public async Task UnacceptedConnectionsAreAborted() { var transportContext = new TestLibuvTransportContext(); var transport = new LibuvConnectionListener(transportContext, new IPEndPoint(IPAddress.Loopback, 0)); await transport.BindAsync(); var endpoint = (IPEndPoint)transport.EndPoint; async Task ConnectAsync() { using (var socket = TestConnection.CreateConnectedLoopbackSocket(endpoint.Port)) { try { var read = await socket.ReceiveAsync(new byte[10], SocketFlags.None); Assert.Equal(0, read); } catch (SocketException) { // The connection can be reset sometimes } } } var connectTask = ConnectAsync(); await transport.UnbindAsync(); await transport.DisposeAsync(); // The connection was accepted because libuv eagerly accepts connections // they sit in a queue in each listener, we want to make sure that resources // are cleaned up if they are never accepted by the caller await connectTask.DefaultTimeout(); }
public async Task TransportCanBindUnbindAndStop() { var transportContext = new TestLibuvTransportContext(); var transport = new LibuvConnectionListener(transportContext, new IPEndPoint(IPAddress.Loopback, 0)); await transport.BindAsync(); await transport.UnbindAsync(); await transport.DisposeAsync(); }
public async Task TransportCanBindAndStop() { var transportContext = new TestLibuvTransportContext(); var transport = new LibuvConnectionListener(transportContext, new IPEndPoint(IPAddress.Loopback, 0)); // The transport can no longer start threads without binding to an endpoint. await transport.BindAsync(); await transport.DisposeAsync(); }
public async Task CallingAcceptAfterDisposeAsyncThrows() { var transportContext = new TestLibuvTransportContext(); var transport = new LibuvConnectionListener(transportContext, new IPEndPoint(IPAddress.Loopback, 0)); await transport.BindAsync(); var endpoint = (IPEndPoint)transport.EndPoint; await transport.UnbindAsync(); await transport.DisposeAsync(); await Assert.ThrowsAsync<ObjectDisposedException>(() => transport.AcceptAsync().AsTask()); }
public async Task Dispose() { LibuvConnectionListener listener = Interlocked.Exchange(ref m_Listener, null); if (listener != null) { try { await listener.UnbindAsync(); await listener.DisposeAsync(); } catch (Exception ex) { Console.WriteLine("Listener: Failed to dispose."); Console.WriteLine(ex); } } GC.SuppressFinalize(this); }