Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket.Select returns error "An operation was attempted on something that is not a socket"

When calling Socket.Select with lists that are verified to contain only Socket objects, I sometimes receive the error An operation was attempted on something that is not a socket. I can't find a pattern for occurrence.

Socket.Select(readList, writeList, null, timeOut > 0 ? timeOut : 0);
like image 586
David Pfeffer Avatar asked Jul 06 '10 16:07

David Pfeffer


2 Answers

It turns out the sockets were closed. That's a really dumb error for .NET to be generating though just because of a closed socket.

like image 105
David Pfeffer Avatar answered Sep 30 '22 18:09

David Pfeffer


I did a search on MSDN and got a couple of hits. See here & here

However, I haven't develop anything in WinSock but on Unix the way Select is implemented requires resetting the fd_set everytime Select returns. Maybe the same applies to WinSock implementation of Select also. If this is the case, your readList, writeList may have got corrupted after Select returned leading to the error you mentioned. Just a thought.

like image 33
Aditya Sehgal Avatar answered Sep 30 '22 19:09

Aditya Sehgal