});
// constructor for inbound connections
- public MsQuicConnection(IPEndPoint localEndPoint, IPEndPoint remoteEndPoint, IntPtr nativeObjPtr)
+ public MsQuicConnection(IPEndPoint localEndPoint, IPEndPoint remoteEndPoint, IntPtr nativeObjPtr, TimeSpan idleTimeout)
{
_localEndPoint = localEndPoint;
_remoteEndPoint = remoteEndPoint;
_connected = true;
SetCallbackHandler();
+
+ SetIdleTimeout(idleTimeout);
}
// constructor for outbound connections
_sslOptions = options.ServerAuthenticationOptions!;
_listenEndPoint = options.ListenEndPoint!;
- SetIdleTimeout(options.IdleTimeout);
-
_ptr = _session.ListenerOpen(options);
}
SetListenPort();
}
- private void SetIdleTimeout(TimeSpan timeout)
- {
- MsQuicParameterHelpers.SetULongParam(MsQuicApi.Api, _ptr, (uint)QUIC_PARAM_LEVEL.LISTENER, (uint)QUIC_PARAM_CONN.IDLE_TIMEOUT, (ulong)timeout.TotalMilliseconds);
- }
-
internal override void Close()
{
ThrowIfDisposed();
IPEndPoint localEndPoint = MsQuicAddressHelpers.INetToIPEndPoint(ref *(SOCKADDR_INET*)connectionInfo.LocalAddress);
IPEndPoint remoteEndPoint = MsQuicAddressHelpers.INetToIPEndPoint(ref *(SOCKADDR_INET*)connectionInfo.RemoteAddress);
- MsQuicConnection msQuicConnection = new MsQuicConnection(localEndPoint, remoteEndPoint, evt.Data.NewConnection.Connection);
+ MsQuicConnection msQuicConnection = new MsQuicConnection(localEndPoint, remoteEndPoint, evt.Data.NewConnection.Connection, _options.IdleTimeout);
msQuicConnection.SetNegotiatedAlpn(connectionInfo.NegotiatedAlpn, connectionInfo.NegotiatedAlpnLength);
_acceptConnectionQueue.Writer.TryWrite(msQuicConnection);
Assert.Equal(100, serverConnection.GetRemoteAvailableUnidirectionalStreamCount());
}
+ [Fact]
+ [OuterLoop("May take serveral seconds")]
+ public async Task SetListenerTimeoutWorksWithSmallTimeout()
+ {
+ var quicOptions = new QuicListenerOptions();
+ quicOptions.IdleTimeout = TimeSpan.FromSeconds(10);
+ quicOptions.ServerAuthenticationOptions = GetSslServerAuthenticationOptions();
+ quicOptions.ListenEndPoint = new IPEndPoint(IPAddress.Loopback, 0);
+
+ using QuicListener listener = new QuicListener(QuicImplementationProviders.MsQuic, quicOptions);
+ listener.Start();
+
+ QuicClientConnectionOptions options = new QuicClientConnectionOptions()
+ {
+ RemoteEndPoint = listener.ListenEndPoint,
+ ClientAuthenticationOptions = GetSslClientAuthenticationOptions(),
+ };
+
+ using QuicConnection clientConnection = new QuicConnection(QuicImplementationProviders.MsQuic, options);
+ ValueTask clientTask = clientConnection.ConnectAsync();
+ using QuicConnection serverConnection = await listener.AcceptConnectionAsync();
+ await clientTask;
+
+ await Assert.ThrowsAsync<QuicOperationAbortedException>(async () => await serverConnection.AcceptStreamAsync().TimeoutAfter(100000));
+ }
+
[Theory]
[MemberData(nameof(WriteData))]
public async Task WriteTests(int[][] writes, WriteType writeType)