Skip to content

Commit 93d7f70

Browse files
committed
Static fix
1 parent ee190d0 commit 93d7f70

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

experimental/ManagedRIOHttpServer/Program.cs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ namespace ManagedRIOHttpServer
1212
{
1313
public sealed class Program
1414
{
15+
// Number of 100ns ticks per time unit
16+
private const long TicksPerMillisecond = 10000;
17+
private const long TicksPerSecond = TicksPerMillisecond * 1000;
18+
1519
static readonly string headersKeepAliveStr = "HTTP/1.1 200 OK\r\n" +
1620
"Content-Type: text/plain\r\n" +
1721
"Content-Length:13\r\n" +
@@ -106,6 +110,7 @@ static async Task ServeSocket(RIOTcpConnection socket)
106110

107111
var loop = 0;
108112
var overflow = 0;
113+
var lastSeconds = 0L;
109114
// need to check for keep alive
110115

111116
while (true)
@@ -272,8 +277,14 @@ static async Task ServeSocket(RIOTcpConnection socket)
272277
socket.SendCachedBad();
273278
break;
274279
}
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+
}
277288

278289
for (var i = 1; i < count; i++)
279290
{
@@ -299,21 +310,6 @@ static async Task ServeSocket(RIOTcpConnection socket)
299310
socket.Close();
300311
}
301312
}
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-
}
317313

318314
//public static void LowerCaseSIMD(ArraySegment<byte> data)
319315
//{

0 commit comments

Comments
 (0)