Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions frameworks/CSharp/touchsocket/Benchmarks.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TouchSocketWebApi31", "src\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TouchSocketHttpPlatform", "src\TouchSocketHttpPlatform\TouchSocketHttpPlatform.csproj", "{BC320C24-941D-2109-FBC8-92780569BBA4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TouchSocketHttpSyncPlatform", "TouchSocketHttpSyncPlatform\TouchSocketHttpSyncPlatform.csproj", "{E4A6B13A-13D3-47D6-9696-533A1FA1B88F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -39,6 +41,10 @@ Global
{BC320C24-941D-2109-FBC8-92780569BBA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC320C24-941D-2109-FBC8-92780569BBA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC320C24-941D-2109-FBC8-92780569BBA4}.Release|Any CPU.Build.0 = Release|Any CPU
{E4A6B13A-13D3-47D6-9696-533A1FA1B88F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E4A6B13A-13D3-47D6-9696-533A1FA1B88F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E4A6B13A-13D3-47D6-9696-533A1FA1B88F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E4A6B13A-13D3-47D6-9696-533A1FA1B88F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// ------------------------------------------------------------------------------
// 此代码版权(除特别声明或在XREF结尾的命名空间的代码)归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
// CSDN博客:https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频:https://space.bilibili.com/94253567
// Gitee源代码仓库:https://gitee.com/RRQM_Home
// Github源代码仓库:https://github.com/RRQM
// API首页:https://touchsocket.net/
// 交流QQ群:234762506
// 感谢您的下载和使用
// ------------------------------------------------------------------------------

using System.Buffers.Text;
using System.Diagnostics;

namespace TouchSocketHttpSyncPlatform;

internal static class DateHeader
{
private const int dateTimeRLength = 29;
private const int prefixLength = 6;
private const int suffixIndex = dateTimeRLength + prefixLength;
private const int suffixLength = 2;

private static readonly Timer s_timer = new((s) =>
{
SetDateValues(DateTimeOffset.UtcNow);
}, null, 1000, 1000);

private static byte[] s_headerBytesMaster = new byte[prefixLength + dateTimeRLength + 2 * suffixLength];
private static byte[] s_headerBytesScratch = new byte[prefixLength + dateTimeRLength + 2 * suffixLength];

static DateHeader()
{
var utf8 = "Date: "u8;

utf8.CopyTo(s_headerBytesMaster);
utf8.CopyTo(s_headerBytesScratch);
s_headerBytesMaster[suffixIndex] = (byte)'\r';
s_headerBytesMaster[suffixIndex + 1] = (byte)'\n';
s_headerBytesMaster[suffixIndex + 2] = (byte)'\r';
s_headerBytesMaster[suffixIndex + 3] = (byte)'\n';
s_headerBytesScratch[suffixIndex] = (byte)'\r';
s_headerBytesScratch[suffixIndex + 1] = (byte)'\n';
s_headerBytesScratch[suffixIndex + 2] = (byte)'\r';
s_headerBytesScratch[suffixIndex + 3] = (byte)'\n';

SetDateValues(DateTimeOffset.UtcNow);
SyncDateTimer();
}

public static ReadOnlySpan<byte> HeaderBytes => s_headerBytesMaster;

public static void SyncDateTimer()
{
s_timer.Change(1000, 1000);
}

private static void SetDateValues(DateTimeOffset value)
{
lock (s_headerBytesScratch)
{
if (!Utf8Formatter.TryFormat(value, s_headerBytesScratch.AsSpan(prefixLength), out var written, 'R'))
{
throw new Exception("date time format failed");
}
Debug.Assert(written == dateTimeRLength);
(s_headerBytesScratch, s_headerBytesMaster) = (s_headerBytesMaster, s_headerBytesScratch);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
Loading
Loading