public async Task ShutdownAsync() { await SockLock.WaitAsync().ConfigureAwait(false); if (Listening) { Socket.Shutdown(SocketShutdown.Receive); Socket.Close(); Listening = false; } SockLock.Release(); }
public async Task ShutdownAsync() { await SockLock.WaitAsync().ConfigureAwait(false); if (Connected) { Socket.Shutdown(SocketShutdown.Send); Socket.Close(); Connected = false; } SockLock.Release(); }
public async Task BindSocketToAddressAsync(int pendingConnections) { if (Socket == null) { throw new InvalidOperationException(SocketNullErrorMessage); } await SockLock.WaitAsync().ConfigureAwait(false); Socket.Bind(DnsEntry.Endpoint); Socket.Listen(pendingConnections); Socket.NoDelay = true; Listening = true; SockLock.Release(); }
public async Task ConnectToAddressesAsync() { if (Socket == null) { throw new InvalidOperationException(SocketNullErrorMessage); } await SockLock.WaitAsync().ConfigureAwait(false); if (!Connected) { await Socket .ConnectAsync(DnsEntry.Addresses, DnsEntry.Port) .ConfigureAwait(false); Socket.NoDelay = true; Connected = true; } SockLock.Release(); }