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

Add quic support and fix some bugs #724

Closed
wants to merge 8 commits into from
Closed
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
30 changes: 30 additions & 0 deletions SuperSocket.sln
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SuperSocket.Connection", "s
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SuperSocket.Kestrel", "src\SuperSocket.Kestrel\SuperSocket.Kestrel.csproj", "{8C8507D6-903F-4786-8F18-ACA54257454B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SuperSocket.Quic", "src\SuperSocket.Quic\SuperSocket.Quic.csproj", "{F5FDE719-657B-43A8-9F08-E65C7987D357}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SuperSocket.Quic.Connection", "src\SuperSocket.Quic.Connection\SuperSocket.Quic.Connection.csproj", "{6EFA7A93-3B62-46C1-8816-E1802EBF037A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -241,6 +245,30 @@ Global
{8C8507D6-903F-4786-8F18-ACA54257454B}.Release|x64.Build.0 = Release|Any CPU
{8C8507D6-903F-4786-8F18-ACA54257454B}.Release|x86.ActiveCfg = Release|Any CPU
{8C8507D6-903F-4786-8F18-ACA54257454B}.Release|x86.Build.0 = Release|Any CPU
{F5FDE719-657B-43A8-9F08-E65C7987D357}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F5FDE719-657B-43A8-9F08-E65C7987D357}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F5FDE719-657B-43A8-9F08-E65C7987D357}.Debug|x64.ActiveCfg = Debug|Any CPU
{F5FDE719-657B-43A8-9F08-E65C7987D357}.Debug|x64.Build.0 = Debug|Any CPU
{F5FDE719-657B-43A8-9F08-E65C7987D357}.Debug|x86.ActiveCfg = Debug|Any CPU
{F5FDE719-657B-43A8-9F08-E65C7987D357}.Debug|x86.Build.0 = Debug|Any CPU
{F5FDE719-657B-43A8-9F08-E65C7987D357}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F5FDE719-657B-43A8-9F08-E65C7987D357}.Release|Any CPU.Build.0 = Release|Any CPU
{F5FDE719-657B-43A8-9F08-E65C7987D357}.Release|x64.ActiveCfg = Release|Any CPU
{F5FDE719-657B-43A8-9F08-E65C7987D357}.Release|x64.Build.0 = Release|Any CPU
{F5FDE719-657B-43A8-9F08-E65C7987D357}.Release|x86.ActiveCfg = Release|Any CPU
{F5FDE719-657B-43A8-9F08-E65C7987D357}.Release|x86.Build.0 = Release|Any CPU
{6EFA7A93-3B62-46C1-8816-E1802EBF037A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6EFA7A93-3B62-46C1-8816-E1802EBF037A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6EFA7A93-3B62-46C1-8816-E1802EBF037A}.Debug|x64.ActiveCfg = Debug|Any CPU
{6EFA7A93-3B62-46C1-8816-E1802EBF037A}.Debug|x64.Build.0 = Debug|Any CPU
{6EFA7A93-3B62-46C1-8816-E1802EBF037A}.Debug|x86.ActiveCfg = Debug|Any CPU
{6EFA7A93-3B62-46C1-8816-E1802EBF037A}.Debug|x86.Build.0 = Debug|Any CPU
{6EFA7A93-3B62-46C1-8816-E1802EBF037A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6EFA7A93-3B62-46C1-8816-E1802EBF037A}.Release|Any CPU.Build.0 = Release|Any CPU
{6EFA7A93-3B62-46C1-8816-E1802EBF037A}.Release|x64.ActiveCfg = Release|Any CPU
{6EFA7A93-3B62-46C1-8816-E1802EBF037A}.Release|x64.Build.0 = Release|Any CPU
{6EFA7A93-3B62-46C1-8816-E1802EBF037A}.Release|x86.ActiveCfg = Release|Any CPU
{6EFA7A93-3B62-46C1-8816-E1802EBF037A}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -262,6 +290,8 @@ Global
{8454E8D5-777D-46CB-B050-76C5119B624B} = {DDA4741E-097F-40C3-A252-2E1E3476C1A7}
{FC2B529F-4AF4-4C39-BC4F-A3836CC7B37C} = {DDA4741E-097F-40C3-A252-2E1E3476C1A7}
{8C8507D6-903F-4786-8F18-ACA54257454B} = {DDA4741E-097F-40C3-A252-2E1E3476C1A7}
{F5FDE719-657B-43A8-9F08-E65C7987D357} = {DDA4741E-097F-40C3-A252-2E1E3476C1A7}
{6EFA7A93-3B62-46C1-8816-E1802EBF037A} = {DDA4741E-097F-40C3-A252-2E1E3476C1A7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {ADB30AA2-A848-4CB3-8A20-488C80F1BA9E}
Expand Down
3 changes: 2 additions & 1 deletion src/SuperSocket.Connection/PipeConnectionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ private async ValueTask HandleClosing()
{
try
{
await _pipeTask.ConfigureAwait(false);
if (_pipeTask != null)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add comment for the scenario _pipeTask = null

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can put this change into a separated PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

await _pipeTask.ConfigureAwait(false);
}
catch (OperationCanceledException)
{
Expand Down
52 changes: 52 additions & 0 deletions src/SuperSocket.Quic.Connection/QuicPipeConnection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.IO;
using System.Net;
using System.Net.Quic;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
using SuperSocket.Connection;

#pragma warning disable CA2252

namespace SuperSocket.Quic.Connection;

public class QuicPipeConnection : StreamPipeConnection
{
private readonly Stream _stream;

public QuicPipeConnection(Stream stream, EndPoint remoteEndPoint, ConnectionOptions options)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it really accept all kinds of Stream or only support QuicStream?

: this(stream, remoteEndPoint, null, options)
{
_stream = stream;
}

public QuicPipeConnection(Stream stream, EndPoint remoteEndPoint, EndPoint localEndPoint, ConnectionOptions options)
: base(stream, remoteEndPoint, localEndPoint, options)
{
_stream = stream;
}

protected override async Task StartInputPipeTask<TPackageInfo>(IObjectPipe<TPackageInfo> packagePipe, CancellationToken cancellationToken)
{
if (_stream is QuicPipeStream quicPipeStream)
await quicPipeStream.OpenStreamAsync(cancellationToken);

await base.StartInputPipeTask(packagePipe, cancellationToken);
}

protected override bool IsIgnorableException(Exception e)
{
if (base.IsIgnorableException(e))
return true;

switch (e)
{
case QuicException:
case SocketException se when se.IsIgnorableSocketException():
return true;
default:
return false;
}
}
}
66 changes: 66 additions & 0 deletions src/SuperSocket.Quic.Connection/QuicPipeStream.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using System.IO;
using System.Net.Quic;
using System.Threading;
using System.Threading.Tasks;

namespace SuperSocket.Quic.Connection;

#pragma warning disable CA2252
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignore ca1415 as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image


public sealed class QuicPipeStream : Stream
{
private Stream _stream;

private readonly QuicConnection _connection;

public QuicPipeStream(QuicConnection connection)
{
_connection = connection;
}

public override bool CanRead => _stream.CanRead;
public override bool CanSeek => _stream.CanSeek;
public override bool CanWrite => _stream.CanWrite;
public override long Length => _stream.Length;

public override long Position
{
get => _stream.Position;
set => _stream.Position = value;
}

public async ValueTask OpenStreamAsync(CancellationToken cancellationToken)
{
_stream = await _connection.AcceptInboundStreamAsync(cancellationToken);

Check warning on line 35 in src/SuperSocket.Quic.Connection/QuicPipeStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

This call site is reachable on all platforms. 'QuicConnection.AcceptInboundStreamAsync(CancellationToken)' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 35 in src/SuperSocket.Quic.Connection/QuicPipeStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

This call site is reachable on all platforms. 'QuicConnection.AcceptInboundStreamAsync(CancellationToken)' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 35 in src/SuperSocket.Quic.Connection/QuicPipeStream.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

This call site is reachable on all platforms. 'QuicConnection.AcceptInboundStreamAsync(CancellationToken)' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 35 in src/SuperSocket.Quic.Connection/QuicPipeStream.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

This call site is reachable on all platforms. 'QuicConnection.AcceptInboundStreamAsync(CancellationToken)' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 35 in src/SuperSocket.Quic.Connection/QuicPipeStream.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

This call site is reachable on all platforms. 'QuicConnection.AcceptInboundStreamAsync(CancellationToken)' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 35 in src/SuperSocket.Quic.Connection/QuicPipeStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

This call site is reachable on all platforms. 'QuicConnection.AcceptInboundStreamAsync(CancellationToken)' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 35 in src/SuperSocket.Quic.Connection/QuicPipeStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

This call site is reachable on all platforms. 'QuicConnection.AcceptInboundStreamAsync(CancellationToken)' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 35 in src/SuperSocket.Quic.Connection/QuicPipeStream.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

This call site is reachable on all platforms. 'QuicConnection.AcceptInboundStreamAsync(CancellationToken)' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's inbound stream, do we need handle the outbound stream?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Inbound Stream seems to be all that's needed on the server

}

public override void Flush() => _stream.Flush();

public override int Read(byte[] buffer, int offset, int count) => _stream.Read(buffer, offset, count);

public override long Seek(long offset, SeekOrigin origin) => _stream.Seek(offset, origin);

public override void SetLength(long value) => _stream.Flush();

public override void Close() => _stream.Close();

public override Task FlushAsync(CancellationToken cancellationToken) => _stream.FlushAsync(cancellationToken);

public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) =>
_stream.ReadAsync(buffer, offset, count, cancellationToken);

public override ValueTask<int> ReadAsync(Memory<byte> buffer,
CancellationToken cancellationToken = default) => _stream.ReadAsync(buffer, cancellationToken);

public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) =>
_stream.WriteAsync(buffer, offset, count, cancellationToken);

public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer,
CancellationToken cancellationToken = default) =>
_stream.WriteAsync(buffer, cancellationToken);

public override void Write(ReadOnlySpan<byte> buffer) => _stream.Flush();

public override void Write(byte[] buffer, int offset, int count) => _stream.Flush();
}
12 changes: 12 additions & 0 deletions src/SuperSocket.Quic.Connection/SuperSocket.Quic.Connection.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>SuperSocket quic connection library.</Description>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\SuperSocket.Connection\SuperSocket.Connection.csproj" />
</ItemGroup>

</Project>
29 changes: 29 additions & 0 deletions src/SuperSocket.Quic/QuicConnectionFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Net.Quic;
using System.Threading;
using System.Threading.Tasks;
using SuperSocket.Connection;
using SuperSocket.Quic.Connection;

#pragma warning disable CA2252
namespace SuperSocket.Quic;

internal class QuicConnectionFactory : IConnectionFactory
{
private readonly ConnectionOptions _connectionOptions;

public QuicConnectionFactory(ConnectionOptions connectionOptions)
{
_connectionOptions = connectionOptions;
}

public Task<IConnection> CreateConnection(object connection, CancellationToken cancellationToken)
{
var quicConnection = (QuicConnection)connection;

var quicStream = new QuicPipeStream(quicConnection);

var pipeConnection = new QuicPipeConnection(quicStream, quicConnection.RemoteEndPoint, quicConnection.LocalEndPoint, _connectionOptions);

Check warning on line 25 in src/SuperSocket.Quic/QuicConnectionFactory.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

This call site is reachable on all platforms. 'QuicConnection.LocalEndPoint' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 25 in src/SuperSocket.Quic/QuicConnectionFactory.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

This call site is reachable on all platforms. 'QuicConnection.RemoteEndPoint' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 25 in src/SuperSocket.Quic/QuicConnectionFactory.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

This call site is reachable on all platforms. 'QuicConnection.RemoteEndPoint' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 25 in src/SuperSocket.Quic/QuicConnectionFactory.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

This call site is reachable on all platforms. 'QuicConnection.LocalEndPoint' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 25 in src/SuperSocket.Quic/QuicConnectionFactory.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

This call site is reachable on all platforms. 'QuicConnection.LocalEndPoint' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 25 in src/SuperSocket.Quic/QuicConnectionFactory.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

This call site is reachable on all platforms. 'QuicConnection.RemoteEndPoint' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 25 in src/SuperSocket.Quic/QuicConnectionFactory.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

This call site is reachable on all platforms. 'QuicConnection.LocalEndPoint' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 25 in src/SuperSocket.Quic/QuicConnectionFactory.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

This call site is reachable on all platforms. 'QuicConnection.RemoteEndPoint' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 25 in src/SuperSocket.Quic/QuicConnectionFactory.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

This call site is reachable on all platforms. 'QuicConnection.RemoteEndPoint' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 25 in src/SuperSocket.Quic/QuicConnectionFactory.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

This call site is reachable on all platforms. 'QuicConnection.LocalEndPoint' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

return Task.FromResult<IConnection>(pipeConnection);
}
}
13 changes: 13 additions & 0 deletions src/SuperSocket.Quic/QuicConnectionFactoryBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using SuperSocket.Connection;
using SuperSocket.Server.Abstractions;
using SuperSocket.Server.Abstractions.Connections;

namespace SuperSocket.Quic;

internal class QuicConnectionFactoryBuilder : IConnectionFactoryBuilder
{
public IConnectionFactory Build(ListenOptions listenOptions, ConnectionOptions connectionOptions)
{
return new QuicConnectionFactory(connectionOptions);
}
}
157 changes: 157 additions & 0 deletions src/SuperSocket.Quic/QuicConnectionListener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using SuperSocket.Connection;
using SuperSocket.Server.Abstractions;
using SuperSocket.Server.Abstractions.Connections;
using System.Net.Quic;
using System.Net.Security;

#pragma warning disable CA2252
namespace SuperSocket.Quic;

internal sealed class QuicConnectionListener : IConnectionListener
{
private readonly ILogger _logger;
private readonly QuicTransportOptions _quicTransportOptions;

private QuicListener _listenQuic;
private CancellationTokenSource _cancellationTokenSource;
private TaskCompletionSource<bool> _stopTaskCompletionSource;
public IConnectionFactory ConnectionFactory { get; }
public ListenOptions Options { get; }
public bool IsRunning { get; private set; }

public QuicConnectionListener(ListenOptions options,
QuicTransportOptions quicTransportOptions,
IConnectionFactory connectionFactory, ILogger logger)
{
Options = options;
ConnectionFactory = connectionFactory;
_logger = logger;
_quicTransportOptions = quicTransportOptions;
}

public bool Start()
{
var options = Options;

try
{
var listenEndpoint = options.ToEndPoint();

if (options.CertificateOptions == null)
throw new ArgumentNullException(nameof(options.CertificateOptions),"Quic requires an ssl certificate");

if (options.CertificateOptions.Certificate == null)
options.CertificateOptions.EnsureCertificate();

var quicListenerOptions = new QuicListenerOptions

Check warning on line 51 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

This call site is reachable on all platforms. 'QuicListenerOptions' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 51 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

This call site is reachable on all platforms. 'QuicListenerOptions' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
{
ListenBacklog = options.BackLog,

Check warning on line 53 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

This call site is reachable on all platforms. 'QuicListenerOptions.ListenBacklog' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 53 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

This call site is reachable on all platforms. 'QuicListenerOptions.ListenBacklog' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
ListenEndPoint = listenEndpoint,
ApplicationProtocols = new List<SslApplicationProtocol> { SslApplicationProtocol.Http3 },
ConnectionOptionsCallback = (connection, ssl, token) => ValueTask.FromResult(

Check warning on line 56 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

This call site is reachable on all platforms. 'QuicServerConnectionOptions' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 56 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

This call site is reachable on all platforms. 'QuicListenerOptions.ConnectionOptionsCallback' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 56 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

This call site is reachable on all platforms. 'QuicListenerOptions.ConnectionOptionsCallback' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
new QuicServerConnectionOptions
{
DefaultStreamErrorCode = _quicTransportOptions.DefaultStreamErrorCode,
DefaultCloseErrorCode = _quicTransportOptions.DefaultCloseErrorCode,

Check warning on line 60 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

This call site is reachable on all platforms. 'QuicConnectionOptions.DefaultCloseErrorCode' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 60 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

This call site is reachable on all platforms. 'QuicConnectionOptions.DefaultCloseErrorCode' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
IdleTimeout = _quicTransportOptions.IdleTimeout.HasValue

Check warning on line 61 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

This call site is reachable on all platforms. 'QuicConnectionOptions.IdleTimeout' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 61 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

This call site is reachable on all platforms. 'QuicConnectionOptions.IdleTimeout' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
? TimeSpan.FromMicroseconds(_quicTransportOptions.IdleTimeout.Value)
: Timeout.InfiniteTimeSpan,
MaxInboundBidirectionalStreams = _quicTransportOptions.MaxBidirectionalStreamCount,

Check warning on line 64 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

This call site is reachable on all platforms. 'QuicConnectionOptions.MaxInboundBidirectionalStreams' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 64 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

This call site is reachable on all platforms. 'QuicConnectionOptions.MaxInboundBidirectionalStreams' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
MaxInboundUnidirectionalStreams = _quicTransportOptions.MaxUnidirectionalStreamCount,

Check warning on line 65 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

This call site is reachable on all platforms. 'QuicConnectionOptions.MaxInboundUnidirectionalStreams' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 65 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

This call site is reachable on all platforms. 'QuicConnectionOptions.MaxInboundUnidirectionalStreams' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
ServerAuthenticationOptions = new SslServerAuthenticationOptions()

Check warning on line 66 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

This call site is reachable on all platforms. 'QuicServerConnectionOptions.ServerAuthenticationOptions' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 66 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

This call site is reachable on all platforms. 'QuicServerConnectionOptions.ServerAuthenticationOptions' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
{
ApplicationProtocols =
new List<SslApplicationProtocol> { SslApplicationProtocol.Http3 },
ServerCertificate = options.CertificateOptions.Certificate,
RemoteCertificateValidationCallback =
options.CertificateOptions.RemoteCertificateValidationCallback,
}
})
};

var listenSocket = _listenQuic = QuicListener.ListenAsync(quicListenerOptions).GetAwaiter().GetResult();

Check warning on line 77 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

This call site is reachable on all platforms. 'QuicListener' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 77 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

This call site is reachable on all platforms. 'QuicListener' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 77 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

This call site is reachable on all platforms. 'QuicListener' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 77 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

This call site is reachable on all platforms. 'QuicListener' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 77 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

This call site is reachable on all platforms. 'QuicListener.ListenAsync(QuicListenerOptions, CancellationToken)' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

IsRunning = true;

_cancellationTokenSource = new CancellationTokenSource();

KeepAcceptAsync(listenSocket, _cancellationTokenSource.Token).DoNotAwait();
return true;
}
catch (Exception e)
{
_logger.LogError(e, $"The listener[{this.ToString()}] failed to start.");
return false;
}
}


private async Task KeepAcceptAsync(QuicListener listenSocket, CancellationToken cancellationToken)
{
while (!cancellationToken.IsCancellationRequested)
{
try
{
var quicConnection =
await listenSocket.AcceptConnectionAsync(cancellationToken).ConfigureAwait(false);

Check warning on line 101 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

This call site is reachable on all platforms. 'QuicListener.AcceptConnectionAsync(CancellationToken)' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 101 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

This call site is reachable on all platforms. 'QuicConnection' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 101 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

This call site is reachable on all platforms. 'QuicListener.AcceptConnectionAsync(CancellationToken)' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 101 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

This call site is reachable on all platforms. 'QuicConnection' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 101 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

This call site is reachable on all platforms. 'QuicListener.AcceptConnectionAsync(CancellationToken)' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 101 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

This call site is reachable on all platforms. 'QuicConnection' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 101 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

This call site is reachable on all platforms. 'QuicListener.AcceptConnectionAsync(CancellationToken)' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 101 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

This call site is reachable on all platforms. 'QuicConnection' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
OnNewClientAccept(quicConnection, cancellationToken);
}
catch (Exception e)
{
_logger.LogError(e, $"Listener[{this.ToString()}] failed to do AcceptAsync");
}
}

_stopTaskCompletionSource.TrySetResult(true);
}

public event NewConnectionAcceptHandler NewConnectionAccept;

private async void OnNewClientAccept(QuicConnection quicConnection, CancellationToken cancellationToken)
{
var handler = NewConnectionAccept;

if (handler == null)
return;

IConnection connection = null;

try
{
using var cts = CancellationTokenSourcePool.Shared.Rent(Options.ConnectionAcceptTimeOut);
connection = await ConnectionFactory.CreateConnection(quicConnection, cts.Token);
}
catch (Exception e)
{
_logger.LogError(e, $"Failed to create quicConnection for {quicConnection.RemoteEndPoint}.");

Check warning on line 131 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

This call site is reachable on all platforms. 'QuicConnection.RemoteEndPoint' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 131 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

This call site is reachable on all platforms. 'QuicConnection.RemoteEndPoint' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 131 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

This call site is reachable on all platforms. 'QuicConnection.RemoteEndPoint' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
return;
}

await handler.Invoke(this.Options, connection);
}

public async Task StopAsync()
{
var listenSocket = _listenQuic;

if (listenSocket == null)
return;

_stopTaskCompletionSource = new TaskCompletionSource<bool>();

_cancellationTokenSource.Cancel();
await _listenQuic.DisposeAsync();

Check warning on line 148 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

This call site is reachable on all platforms. 'QuicListener.DisposeAsync()' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 148 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

This call site is reachable on all platforms. 'QuicListener.DisposeAsync()' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 148 in src/SuperSocket.Quic/QuicConnectionListener.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

This call site is reachable on all platforms. 'QuicListener.DisposeAsync()' is only supported on: 'linux', 'macOS/OSX', 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

await _stopTaskCompletionSource.Task;
}

public override string ToString()
{
return Options?.ToString();
}
}
Loading
Loading