Skip to content

Commit 350ada5

Browse files
committed
fix route collision detector
1 parent d45cd72 commit 350ada5

29 files changed

+1294
-200
lines changed

cadente/Sisk.Cadente/CadenteHttpListener.cs renamed to cadente/Sisk.Cadente/HttpHost.cs

+20-19
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// The code below is licensed under the MIT license as
55
// of the date of its publication, available at
66
//
7-
// File name: CadenteHttpListener.cs
7+
// File name: HttpHost.cs
88
// Repository: https://github.com/sisk-http/core
99

1010
using System.Net;
@@ -17,10 +17,9 @@ namespace Sisk.Cadente;
1717
/// <summary>
1818
/// Represents an HTTP host that listens for incoming TCP connections and handles HTTP requests.
1919
/// </summary>
20-
public sealed class CadenteHttpListener : IDisposable {
20+
public sealed class HttpHost : IDisposable {
2121

22-
// defines the connection queue size (worker connections)
23-
const int QUEUE_SIZE = 512;
22+
const int QUEUE_SIZE = 256;
2423

2524
private readonly TcpListener _listener;
2625
private readonly Channel<TcpClient> clientQueue;
@@ -31,32 +30,32 @@ public sealed class CadenteHttpListener : IDisposable {
3130
private bool disposedValue;
3231

3332
/// <summary>
34-
/// Gets the action handler for processing HTTP actions.
33+
/// Gets or sets the action handler for HTTP requests.
3534
/// </summary>
3635
public HttpAction ActionHandler { get; }
3736

3837
/// <summary>
39-
/// Gets a value indicating whether the host has been disposed.
38+
/// Gets a value indicating whether this <see cref="HttpHost"/> has been disposed.
4039
/// </summary>
4140
public bool IsDisposed { get => this.disposedValue; }
4241

4342
/// <summary>
44-
/// Gets or sets the port on which the HTTP host listens for incoming connections.
45-
/// Default is 8080.
43+
/// Gets or sets the port number to listen on.
4644
/// </summary>
4745
public int Port { get; set; } = 8080;
4846

4947
/// <summary>
50-
/// Gets or sets the options for HTTPS configuration.
48+
/// Gets or sets the HTTPS options for secure connections. Setting an <see cref="Sisk.Cadente.HttpsOptions"/> object in this
49+
/// property, the <see cref="Sisk.Cadente.HttpHost"/> will use HTTPS instead of HTTP.
5150
/// </summary>
5251
public HttpsOptions? HttpsOptions { get; set; }
5352

5453
/// <summary>
55-
/// Initializes a new instance of the <see cref="CadenteHttpListener"/> class with the specified port and action handler.
54+
/// Initializes a new instance of the <see cref="HttpHost"/> class.
5655
/// </summary>
57-
/// <param name="port">The port on which the host will listen for incoming connections.</param>
58-
/// <param name="actionHandler">The action handler for processing HTTP actions.</param>
59-
public CadenteHttpListener ( int port, HttpAction actionHandler ) {
56+
/// <param name="port">The port number to listen on.</param>
57+
/// <param name="actionHandler">The action handler for HTTP requests.</param>
58+
public HttpHost ( int port, HttpAction actionHandler ) {
6059
this._listener = new TcpListener ( new IPEndPoint ( IPAddress.Any, port ) );
6160
this.channelConsumerThread = new Thread ( this.ConsumerJobThread );
6261
this.clientQueue = Channel.CreateBounded<TcpClient> (
@@ -67,12 +66,12 @@ public CadenteHttpListener ( int port, HttpAction actionHandler ) {
6766
}
6867

6968
/// <summary>
70-
/// Starts the Cadente HTTP host, beginning to listen for incoming connections.
69+
/// Starts the HTTP host and begins listening for incoming connections.
7170
/// </summary>
7271
public void Start () {
7372
ObjectDisposedException.ThrowIf ( this.disposedValue, this );
7473

75-
this._listener.Server.SetSocketOption ( SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveInterval, 3 );
74+
this._listener.Server.SetSocketOption ( SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveInterval, 1 );
7675
this._listener.Server.SetSocketOption ( SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveTime, 120 );
7776
this._listener.Server.SetSocketOption ( SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveRetryCount, 3 );
7877
this._listener.Server.SetSocketOption ( SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true );
@@ -96,8 +95,8 @@ private async Task HandleTcpClient ( TcpClient client ) {
9695
{ // setup the tcpclient
9796
client.NoDelay = true;
9897

99-
client.ReceiveTimeout = 5_000;
100-
client.SendTimeout = 5_000;
98+
client.ReceiveTimeout = (int) TimeSpan.FromSeconds ( 5 ).TotalMilliseconds;
99+
client.SendTimeout = (int) TimeSpan.FromSeconds ( 5 ).TotalMilliseconds;
101100

102101
client.ReceiveBufferSize = HttpConnection.REQUEST_BUFFER_SIZE;
103102
client.SendBufferSize = HttpConnection.RESPONSE_BUFFER_SIZE;
@@ -126,14 +125,16 @@ await sslStream.AuthenticateAsServerAsync (
126125
checkCertificateRevocation: this.HttpsOptions.CheckCertificateRevocation,
127126
enabledSslProtocols: this.HttpsOptions.AllowedProtocols );
128127
}
129-
catch (Exception) {
128+
catch (Exception ex) {
130129
//Logger.LogInformation ( $"[{connection.Id}] Failed SSL authenticate: {ex.Message}" );
131-
// TODO drop connection with 401
132130
}
133131
}
134132

133+
//Logger.LogInformation ( $"[{connection.Id}] Begin handle connection" );
135134
var state = await connection.HandleConnectionEvents ();
136135

136+
//Logger.LogInformation ( $"[{connection.Id}] Ended handling connection with state {state}" );
137+
137138
}
138139
}
139140
finally {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
8+
</PropertyGroup>
9+
10+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0|AnyCPU'">
11+
<DefineConstants>$(DefineConstants);VERBOSE</DefineConstants>
12+
</PropertyGroup>
13+
14+
</Project>

0 commit comments

Comments
 (0)