System.Net.Sockets.Socket.Poll Method

Determines the status of the System.Net.Sockets.Socket.

Syntax

public bool Poll (int time_us, SelectMode mode)

Parameters

time_us
Documentation for this section has not yet been entered.
mode
One of the System.Net.Sockets.SelectMode values.

Returns

The status of the System.Net.Sockets.Socket based on the polling mode value passed in the mode parameter.

SelectMode.SelectRead

true if Socket.Listen(int) has been called and a connection is pending;

-or-

true if data is available for reading;

-or-

true if the connection has been closed, reset, or terminated;

otherwise, returns false.

SelectMode.SelectWrite

true, if processing a Socket.Connect(System.Net.EndPoint), and the connection has succeeded;

-or-

true if data can be sent;

otherwise, returns false.

SelectMode.SelectError

true if processing a Socket.Connect(System.Net.EndPoint) that does not block, and the connection has failed;

-or-

true if SocketOptionName.OutOfBandInline is not set and out-of-band data is available;

otherwise, returns false.

Exceptions

TypeReason
NotSupportedException mode is not one of the values defined in the System.Net.Sockets.SelectMode enumeration.
System.Net.Sockets.SocketException

An error occurred while accessing the socket.

Note: For additional information on causes of the SocketException, see the System.Net.Sockets.SocketException class.

ObjectDisposedExceptionThe current instance has been disposed.

Remarks

The Socket.Poll(int, SelectMode) method will check the state of the System.Net.Sockets.Socket. Specify SelectMode.SelectRead for the selectMode parameter to determine if the System.Net.Sockets.Socket is readable. Specify SelectMode.SelectWrite to determine if the System.Net.Sockets.Socket is writable. Use SelectMode.SelectError to detect an error condition. Socket.Poll(int, SelectMode) will block execution until the specified time period, measured in microseconds, elapses. Set the microSeconds parameter to a negative integer if you would like to wait indefinitely for a response. If you want to check the status of multiple sockets, you might prefer to use the Socket.Select(IList, IList, IList, int) method.

Note:

If you receive a System.Net.Sockets.SocketException, use the SocketException.ErrorCode property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

Note:

This method cannot detect certain kinds of connection problems, such as a broken network cable, or that the remote host was shut down ungracefully. You must attempt to send or receive data to detect these kinds of errors.

Note:

This member outputs trace information when you enable network tracing in your application. For more information, see [<topic://conUsingNetworkTracing>].

Requirements

Namespace: System.Net.Sockets
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0