Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove PooledAwait #623

Merged
merged 1 commit into from
Jan 21, 2025
Merged
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
2 changes: 0 additions & 2 deletions Engine/Internal/GenHTTP.Engine.Internal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@

<ProjectReference Include="..\..\Modules\IO\GenHTTP.Modules.IO.csproj" />

<PackageReference Include="PooledAwait" Version="1.0.49" />

<PackageReference Include="System.IO.Pipelines" Version="9.0.1" />

<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
Expand Down
7 changes: 4 additions & 3 deletions Engine/Internal/Infrastructure/Endpoints/EndPoint.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System.Net;
using System.Net.Sockets;
using System.Security.Cryptography.X509Certificates;

using GenHTTP.Api.Infrastructure;

using GenHTTP.Engine.Internal.Protocol;
using GenHTTP.Engine.Shared.Infrastructure;
using PooledAwait;

namespace GenHTTP.Engine.Internal.Infrastructure.Endpoints;

Expand Down Expand Up @@ -95,9 +96,9 @@ private void Handle(Socket client)
Task.Run(() => Accept(client));
}

protected abstract PooledValueTask Accept(Socket client);
protected abstract ValueTask Accept(Socket client);

protected PooledValueTask Handle(Socket client, Stream inputStream, X509Certificate? clientCertificate = null)
protected ValueTask Handle(Socket client, Stream inputStream, X509Certificate? clientCertificate = null)
{
client.NoDelay = true;

Expand Down
4 changes: 1 addition & 3 deletions Engine/Internal/Infrastructure/Endpoints/InsecureEndPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
using GenHTTP.Engine.Internal.Utilities;
using GenHTTP.Engine.Shared.Infrastructure;

using PooledAwait;

namespace GenHTTP.Engine.Internal.Infrastructure.Endpoints;

internal sealed class InsecureEndPoint : EndPoint
Expand All @@ -31,7 +29,7 @@ internal InsecureEndPoint(IServer server, IPAddress? address, ushort port, Netwo

#region Functionality

protected override PooledValueTask Accept(Socket client) => Handle(client, new PoolBufferedStream(new NetworkStream(client), Configuration.TransferBufferSize));
protected override ValueTask Accept(Socket client) => Handle(client, new PoolBufferedStream(new NetworkStream(client), Configuration.TransferBufferSize));

#endregion

Expand Down
4 changes: 1 addition & 3 deletions Engine/Internal/Infrastructure/Endpoints/SecureEndPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
using GenHTTP.Engine.Internal.Utilities;
using GenHTTP.Engine.Shared.Infrastructure;

using PooledAwait;

namespace GenHTTP.Engine.Internal.Infrastructure.Endpoints;

internal sealed class SecureEndPoint : EndPoint
Expand Down Expand Up @@ -53,7 +51,7 @@ internal SecureEndPoint(IServer server, IPAddress? address, ushort port, Securit

#region Functionality

protected override async PooledValueTask Accept(Socket client)
protected override async ValueTask Accept(Socket client)
{
var stream = await TryAuthenticate(client);

Expand Down
13 changes: 7 additions & 6 deletions Engine/Internal/Protocol/ClientHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
using System.IO.Pipelines;
using System.Net.Sockets;
using System.Security.Cryptography.X509Certificates;

using GenHTTP.Api.Infrastructure;
using GenHTTP.Api.Protocol;

using GenHTTP.Engine.Internal.Protocol.Parser;
using GenHTTP.Engine.Shared.Infrastructure;
using GenHTTP.Engine.Shared.Types;
using PooledAwait;

using StringContent = GenHTTP.Modules.IO.Strings.StringContent;

Expand Down Expand Up @@ -67,7 +67,7 @@

#region Functionality

internal async PooledValueTask Run()
internal async ValueTask Run()
{
var status = ConnectionStatus.Close;

Expand All @@ -92,7 +92,7 @@
Server.Companion?.OnServerError(ServerErrorScope.ClientConnection, Connection.GetAddress(), e);
}

try

Check warning on line 95 in Engine/Internal/Protocol/ClientHandler.cs

View workflow job for this annotation

GitHub Actions / build

Combine this 'try' with the one starting on line 86. (https://rules.sonarsource.com/csharp/RSPEC-2327)

Check warning on line 95 in Engine/Internal/Protocol/ClientHandler.cs

View workflow job for this annotation

GitHub Actions / build

Combine this 'try' with the one starting on line 86. (https://rules.sonarsource.com/csharp/RSPEC-2327)

Check warning on line 95 in Engine/Internal/Protocol/ClientHandler.cs

View workflow job for this annotation

GitHub Actions / build

Combine this 'try' with the one starting on line 86. (https://rules.sonarsource.com/csharp/RSPEC-2327)

Check warning on line 95 in Engine/Internal/Protocol/ClientHandler.cs

View workflow job for this annotation

GitHub Actions / build

Combine this 'try' with the one starting on line 86. (https://rules.sonarsource.com/csharp/RSPEC-2327)
{
Connection.Shutdown(SocketShutdown.Both);
await Connection.DisconnectAsync(false);
Expand All @@ -108,7 +108,7 @@
}
}

private async PooledValueTask<ConnectionStatus> HandlePipe(PipeReader reader)
private async ValueTask<ConnectionStatus> HandlePipe(PipeReader reader)
{
try
{
Expand Down Expand Up @@ -151,7 +151,7 @@
return ConnectionStatus.Close;
}

private async PooledValueTask<ConnectionStatus> HandleRequest(RequestBuilder builder, bool dataRemaining)
private async ValueTask<ConnectionStatus> HandleRequest(RequestBuilder builder, bool dataRemaining)
{
using var request = builder.Connection(Server, Connection, Stream, EndPoint, Connection.GetAddress(), ClientCertificate).Build();

Expand All @@ -171,7 +171,7 @@
return (active && keepAlive) ? ConnectionStatus.KeepAlive : ConnectionStatus.Close;
}

private async PooledValueTask SendError(Exception e, ResponseStatus status)
private async ValueTask SendError(Exception e, ResponseStatus status)
{
try
{
Expand All @@ -184,7 +184,8 @@
await ResponseHandler.Handle(null, response, false, false);
}
catch
{ /* no recovery here */
{
/* no recovery here */
}
}

Expand Down
15 changes: 7 additions & 8 deletions Engine/Internal/Protocol/Parser/RequestParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using GenHTTP.Engine.Internal.Protocol.Parser.Conversion;
using GenHTTP.Engine.Shared.Infrastructure;

using PooledAwait;

namespace GenHTTP.Engine.Internal.Protocol.Parser;

/// <summary>
Expand Down Expand Up @@ -43,7 +41,7 @@ internal RequestParser(NetworkConfiguration configuration)

#region Functionality

internal async PooledValueTask<RequestBuilder?> TryParseAsync(RequestBuffer buffer)
internal async ValueTask<RequestBuilder?> TryParseAsync(RequestBuffer buffer)
{
if (!await Type(buffer))
{
Expand All @@ -69,7 +67,7 @@ internal RequestParser(NetworkConfiguration configuration)
return result;
}

private async PooledValueTask<bool> Type(RequestBuffer buffer)
private async ValueTask<bool> Type(RequestBuffer buffer)
{
Scanner.Mode = ScannerMode.Words;

Expand All @@ -78,10 +76,11 @@ private async PooledValueTask<bool> Type(RequestBuffer buffer)
Request.Type(MethodConverter.ToRequestMethod(Scanner.Value));
return true;
}

return false;
}

private async PooledValueTask Path(RequestBuffer buffer)
private async ValueTask Path(RequestBuffer buffer)
{
Scanner.Mode = ScannerMode.Path;

Expand Down Expand Up @@ -115,7 +114,7 @@ private async PooledValueTask Path(RequestBuffer buffer)
}
}

private async PooledValueTask Protocol(RequestBuffer buffer)
private async ValueTask Protocol(RequestBuffer buffer)
{
Scanner.Mode = ScannerMode.Words;

Expand All @@ -125,7 +124,7 @@ private async PooledValueTask Protocol(RequestBuffer buffer)
}
}

private async PooledValueTask Headers(RequestBuffer buffer)
private async ValueTask Headers(RequestBuffer buffer)
{
Scanner.Mode = ScannerMode.HeaderKey;

Expand All @@ -144,7 +143,7 @@ private async PooledValueTask Headers(RequestBuffer buffer)
}
}

private async PooledValueTask Body(RequestBuffer buffer)
private async ValueTask Body(RequestBuffer buffer)
{
if (Request.Headers.TryGetValue("Content-Length", out var bodyLength))
{
Expand Down
9 changes: 4 additions & 5 deletions Engine/Internal/Protocol/Parser/RequestScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

using GenHTTP.Api.Protocol;

using PooledAwait;

namespace GenHTTP.Engine.Internal.Protocol.Parser;

internal sealed class RequestScanner
Expand All @@ -21,7 +19,7 @@ internal RequestScanner()

internal ScannerMode Mode { get; set; }

internal async PooledValueTask<bool> Next(RequestBuffer buffer, RequestToken expectedToken, bool allowNone = false, bool includeWhitespace = false)
internal async ValueTask<bool> Next(RequestBuffer buffer, RequestToken expectedToken, bool allowNone = false, bool includeWhitespace = false)
{
var read = await Next(buffer, false, includeWhitespace);

Expand All @@ -38,7 +36,7 @@ internal async PooledValueTask<bool> Next(RequestBuffer buffer, RequestToken exp
return true;
}

internal async PooledValueTask<RequestToken> Next(RequestBuffer buffer, bool forceRead = false, bool includeWhitespace = false)
internal async ValueTask<RequestToken> Next(RequestBuffer buffer, bool forceRead = false, bool includeWhitespace = false)
{
// ensure we have data to be scanned
if (await Fill(buffer, forceRead))
Expand Down Expand Up @@ -185,7 +183,7 @@ private bool ReadTo(RequestBuffer buffer, char delimiter, char? boundary = null,
return false;
}

private static async PooledValueTask<bool> Fill(RequestBuffer buffer, bool force = false)
private static async ValueTask<bool> Fill(RequestBuffer buffer, bool force = false)
{
if (buffer.ReadRequired || force)
{
Expand All @@ -194,4 +192,5 @@ private static async PooledValueTask<bool> Fill(RequestBuffer buffer, bool force

return !buffer.Data.IsEmpty;
}

}
4 changes: 1 addition & 3 deletions Engine/Internal/Protocol/RequestBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

using GenHTTP.Engine.Shared.Infrastructure;

using PooledAwait;

namespace GenHTTP.Engine.Internal.Protocol;

/// <summary>
Expand Down Expand Up @@ -50,7 +48,7 @@ internal RequestBuffer(PipeReader reader, NetworkConfiguration configuration)

#region Functionality

internal async PooledValueTask<long?> ReadAsync(bool force = false)
internal async ValueTask<long?> ReadAsync(bool force = false)
{
if (ReadRequired || force)
{
Expand Down
2 changes: 0 additions & 2 deletions Modules/Caching/GenHTTP.Modules.Caching.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@

<ProjectReference Include="..\Basics\GenHTTP.Modules.Basics.csproj" />

<PackageReference Include="PooledAwait" Version="1.0.49" />

<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />

<PackageReference Include="System.Text.Json" Version="9.0.1" />
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,4 @@ in C#. In 2024 the focus has shifted towards API development, dropping support f
## 🙏 Thanks

- Powered by [.NET](https://github.com/dotnet/core)
- Less allocations thanks to [PooledAwait](https://github.com/mgravell/PooledAwait)
- Modules implemented with [NSwag](https://github.com/RicoSuter/NSwag) (Open API), [Fleck](https://github.com/statianzo/Fleck) (WebSockets)
Loading