public static unsafe SocketError Poll(SafeCloseSocket handle, int microseconds, SelectMode mode, out bool status)
{
Interop.Sys.PollEvents inEvent = Interop.Sys.PollEvents.POLLNONE;
switch (mode)
{
case SelectMode.SelectRead: inEvent = Interop.Sys.PollEvents.POLLIN; break;
case SelectMode.SelectWrite: inEvent = Interop.Sys.PollEvents.POLLOUT; break;
case SelectMode.SelectError: inEvent = Interop.Sys.PollEvents.POLLPRI; break;
}
int milliseconds = microseconds == -1 ? -1 : microseconds / 1000;
Interop.Sys.PollEvents outEvents;
Interop.Error err = Interop.Sys.Poll(handle, inEvent, milliseconds, out outEvents);
if (err != Interop.Error.SUCCESS)
{
status = false;
return GetSocketErrorForErrorCode(err);
}
switch (mode)
{
case SelectMode.SelectRead: status = (outEvents & (Interop.Sys.PollEvents.POLLIN | Interop.Sys.PollEvents.POLLHUP)) != 0; break;
case SelectMode.SelectWrite: status = (outEvents & Interop.Sys.PollEvents.POLLOUT) != 0; break;
case SelectMode.SelectError: status = (outEvents & (Interop.Sys.PollEvents.POLLERR | Interop.Sys.PollEvents.POLLPRI)) != 0; break;
default: status = false; break;
}
return SocketError.Success;
}