Skip to content

Commit

Permalink
wpi
Browse files Browse the repository at this point in the history
  • Loading branch information
CypherPotato committed Jan 29, 2025
1 parent 84de982 commit cea7951
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 33 deletions.
Binary file added .github/cadente-ico.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 10 additions & 28 deletions cadente/Sisk.Cadente/HttpHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using System.Net.Security;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
using System.Threading.Channels;

namespace Sisk.Cadente;

Expand All @@ -20,19 +19,19 @@ namespace Sisk.Cadente;
/// </summary>
public sealed class HttpHost : IDisposable {

const int MAX_WORKERS = 65536;

private readonly TcpListener _listener;
private readonly Channel<TcpClient> clientQueue;
private readonly ChannelWriter<TcpClient> writerQueue;
private readonly ChannelReader<TcpClient> readerQueue;
private readonly Thread channelConsumerThread;

// internal readonly SemaphoreSlim HostLimiter = new SemaphoreSlim ( 64 );
private readonly LingerOption tcpLingerOption = new LingerOption ( true, 0 );

private bool disposedValue;

/// <summary>
/// Gets or sets the client queue size of all <see cref="HttpHost"/> instances. This value indicates how many
/// connections the server can maintain simultaneously before queueing other connections attempts.
/// </summary>
public static int QueueSize { get; set; } = 1024;

/// <summary>
/// Gets or sets the action handler for HTTP requests.
/// </summary>
Expand Down Expand Up @@ -60,12 +59,6 @@ public sealed class HttpHost : IDisposable {
/// <param name="endpoint">The <see cref="IPEndPoint"/> to listen on.</param>
public HttpHost ( IPEndPoint endpoint ) {
this._listener = new TcpListener ( endpoint );
this.channelConsumerThread = new Thread ( this.ConsumerJobThread );
this.clientQueue = Channel.CreateBounded<TcpClient> (
new BoundedChannelOptions ( MAX_WORKERS ) { SingleReader = true, SingleWriter = true, AllowSynchronousContinuations = true } );

this.readerQueue = this.clientQueue.Reader;
this.writerQueue = this.clientQueue.Writer;
}

/// <summary>
Expand All @@ -86,27 +79,25 @@ public void Start () {
this._listener.Server.SetSocketOption ( SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveRetryCount, 3 );
this._listener.Server.SetSocketOption ( SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true );

this._listener.Start ();
this._listener.Start ( QueueSize );
this._listener.BeginAcceptTcpClient ( this.ReceiveClient, null );

this.channelConsumerThread.Start ();
}

private async void ReceiveClient ( IAsyncResult result ) {

this._listener.BeginAcceptTcpClient ( this.ReceiveClient, null );
var client = this._listener.EndAcceptTcpClient ( result );

await this.writerQueue.WriteAsync ( client );
await this.HandleTcpClient ( client );
}

private async Task HandleTcpClient ( TcpClient client ) {
try {
{ // setup the tcpclient
client.NoDelay = true;

//client.ReceiveTimeout = this.TimeoutManager._ClientReadTimeoutSeconds;
//client.SendTimeout = this.TimeoutManager._ClientWriteTimeoutSeconds;
client.ReceiveTimeout = this.TimeoutManager._ClientReadTimeoutSeconds;
client.SendTimeout = this.TimeoutManager._ClientWriteTimeoutSeconds;

client.ReceiveBufferSize = HttpConnection.REQUEST_BUFFER_SIZE;
client.SendBufferSize = HttpConnection.RESPONSE_BUFFER_SIZE;
Expand Down Expand Up @@ -148,19 +139,10 @@ await sslStream.AuthenticateAsServerAsync (
}
}

async void ConsumerJobThread () {
while (!this.disposedValue && await this.readerQueue.WaitToReadAsync ()) {
while (!this.disposedValue && this.readerQueue.TryRead ( out var client )) {
_ = this.HandleTcpClient ( client );
}
}
}

private void Dispose ( bool disposing ) {
if (!this.disposedValue) {
if (disposing) {
this._listener.Dispose ();
this.channelConsumerThread.Join ();
}

this.disposedValue = true;
Expand Down
10 changes: 5 additions & 5 deletions cadente/Sisk.Cadente/Sisk.Cadente.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
<Company>Project Principium</Company>
<Product>Sisk.Cadente</Product>
<NeutralLanguage>en-US</NeutralLanguage>
<Description>Cadente is a managed implementation of HTTP/1.1 with SSL support for .NET.</Description>
<Summary>Cadente is a managed implementation of HTTP/1.1 with SSL support for .NET.</Summary>
<Description>Cadente is a high-performance managed implementation of HTTP/1.1 with SSL support for .NET.</Description>
<Summary>Cadente is a high-performance managed implementation of HTTP/1.1 with SSL support for .NET.</Summary>
<RepositoryType>git</RepositoryType>
<PackageTags>http-server,http,web framework,event sources,web sockets</PackageTags>
<PackageProjectUrl>https://sisk-framework.org/</PackageProjectUrl>
Expand All @@ -45,9 +45,9 @@

<!-- version info -->
<PropertyGroup>
<AssemblyVersion>0.1.42</AssemblyVersion>
<FileVersion>0.1.42</FileVersion>
<Version>0.1.42-alpha1</Version>
<AssemblyVersion>0.1.43</AssemblyVersion>
<FileVersion>0.1.43</FileVersion>
<Version>0.1.43-alpha2</Version>
</PropertyGroup>

<!-- licensing, readme, signing -->
Expand Down

0 comments on commit cea7951

Please sign in to comment.