@@ -12,6 +12,10 @@ namespace ManagedRIOHttpServer
12
12
{
13
13
public sealed class Program
14
14
{
15
+ // Number of 100ns ticks per time unit
16
+ private const long TicksPerMillisecond = 10000 ;
17
+ private const long TicksPerSecond = TicksPerMillisecond * 1000 ;
18
+
15
19
static readonly string headersKeepAliveStr = "HTTP/1.1 200 OK\r \n " +
16
20
"Content-Type: text/plain\r \n " +
17
21
"Content-Length:13\r \n " +
@@ -106,6 +110,7 @@ static async Task ServeSocket(RIOTcpConnection socket)
106
110
107
111
var loop = 0 ;
108
112
var overflow = 0 ;
113
+ var lastSeconds = 0L ;
109
114
// need to check for keep alive
110
115
111
116
while ( true )
@@ -272,8 +277,14 @@ static async Task ServeSocket(RIOTcpConnection socket)
272
277
socket . SendCachedBad ( ) ;
273
278
break ;
274
279
}
275
-
276
- SetDateBytes ( dateBytes ) ;
280
+
281
+ var now = DateTime . UtcNow ;
282
+ var ticks = now . Ticks / TicksPerSecond ;
283
+ if ( lastSeconds != ticks ) {
284
+ lastSeconds = ticks ;
285
+ var date = now . ToString ( "r" ) ;
286
+ Encoding . ASCII . GetBytes ( date , 0 , dateBytes . Length , dateBytes , 0 ) ;
287
+ }
277
288
278
289
for ( var i = 1 ; i < count ; i ++ )
279
290
{
@@ -299,21 +310,6 @@ static async Task ServeSocket(RIOTcpConnection socket)
299
310
socket . Close ( ) ;
300
311
}
301
312
}
302
-
303
- // Number of 100ns ticks per time unit
304
- private const long TicksPerMillisecond = 10000 ;
305
- private const long TicksPerSecond = TicksPerMillisecond * 1000 ;
306
- private long _lastSeconds = 0L ;
307
- private void SetDateBytes ( byte [ ] dateBytes )
308
- {
309
- var now = DateTime . UtcNow ;
310
- var ticks = now . Ticks / TicksPerSecond ;
311
- if ( _lastSeconds == ticks ) return ;
312
- _lastSeconds = ticks ;
313
-
314
- var date = now . ToString ( "r" ) ;
315
- Encoding . ASCII . GetBytes ( date , 0 , dateBytes . Length , dateBytes , 0 ) ;
316
- }
317
313
318
314
//public static void LowerCaseSIMD(ArraySegment<byte> data)
319
315
//{
0 commit comments