System.Net.Sockets.Socket.Poll C# (CSharp) Method

Poll() public method

public Poll ( int microSeconds, SelectMode mode ) : bool
microSeconds int
mode SelectMode
return bool
        public bool Poll(int microSeconds, SelectMode mode)
        {
            if (CleanedUp)
            {
                throw new ObjectDisposedException(this.GetType().FullName);
            }

            bool status;
            SocketError errorCode = SocketPal.Poll(_handle, microSeconds, mode, out status);
            if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"Interop.Winsock.select returns socketCount:{(int)errorCode}");

            // Throw an appropriate SocketException if the native call fails.
            if (errorCode != SocketError.Success)
            {
                // Update the internal state of this socket according to the error before throwing.
                SocketException socketException = new SocketException((int)errorCode);
                UpdateStatusAfterSocketError(socketException);
                if (NetEventSource.IsEnabled) NetEventSource.Error(this, socketException);
                throw socketException;
            }

            return status;
        }

Usage Example

Example #1
15
        protected static bool IsConnected(Socket socket)
        {
            if (socket == null)
                return false;

            try
            {
                if (!socket.Poll(1, SelectMode.SelectRead) || socket.Available != 0)
                    return true;
                socket.Close();
                return false;
            }
            catch
            {
                socket.Close();
                return false;
            }
        }
All Usage Examples Of System.Net.Sockets.Socket::Poll