public void Select() {
ReadSocks.Clear();
ErrorSocks.Clear();
WriteSocks.Clear();
ReadSocks.AddRange(AllSockets);
//Also listen for incoming connections:
ReadSocks.Add(ListenSock);
/*
* POB: I cannot find any documentation on what, other than
* out-of-band data, might be signaled with these. As such
* I am commenting them out. If we don't see a reason to put
* it back soon, please delete ErrorSocks from the code.
* 11/19/2008
ErrorSocks.AddRange(AllSockets);
*/
//Here we do non-blocking connecting:
WriteSocks.AddRange(_con_socks);
//Here we add the sockets that are waiting to write:
WriteSocks.AddRange(_socks_to_send);
//An error signals that the connection failed
ErrorSocks.AddRange(_con_socks);
/*
* Now we are ready to do our select and we only act on local
* variables
*/
try {
//Socket.Select(ReadSocks, null, ErrorSocks, TIMEOUT_MS * 1000);
Socket.Select(ReadSocks, WriteSocks, ErrorSocks, TIMEOUT_MS * 1000);
//Socket.Select(ReadSocks, null, null, TIMEOUT_MS * 1000);
}
catch(System.ObjectDisposedException) {
/*
* This happens if one of the edges is closed while
* a select call is in progress. This is not weird,
* just ignore it
*/
ReadSocks.Clear();
ErrorSocks.Clear();
WriteSocks.Clear();
}
catch(Exception x) {
/*
* There could be an OS error, in principle. If this
* happens, log it, and just sleep for the period of time
* we would have waited (to prevent us from spinning in
* this thread).
*/
ProtocolLog.Write(ProtocolLog.Exceptions, x.ToString());
Thread.Sleep(TIMEOUT_MS);
}
}
}