public async Task ShutdownAsync()
        {
            await SockLock.WaitAsync().ConfigureAwait(false);

            if (Listening)
            {
                Socket.Shutdown(SocketShutdown.Receive);
                Socket.Close();
                Listening = false;
            }
            SockLock.Release();
        }
Exemple #2
0
        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();
        }
Exemple #4
0
        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();
        }