When doing socket reads with a timeout on Linux, they always fail because the value long.max is passed as the first argument to the select() system call. Linux does not accept this value and returns the error EBADF in errno when failing. A value which is bigger than the largest file descriptor in the SocketSet should be used.
I've made a fix, but it's not 100% foolproof, as it doesn't keep track of the sockets that have been removed from the SocketSet. I couldn't find a way to attach it, so here's an embedded diff against today's SVN trunk:
--- Socket.d 2006-01-30 13:38:25.000000000 -0300
+++ Socket.d.patched 2006-01-30 13:38:15.000000000 -0300
@@ -1564,6 +1564,7 @@
body
{
fd_set* fr, fw, fe;
+ socket_t maxfd;
version(Win32)
{
@@ -1582,7 +1583,7 @@
int result;
// MANGO: if select() was interrupted, we now try again
- while ((result = .select (socket_t.max - 1, fr, fw, fe, tv)) == -1)
+ while ((result = .select (maxfd + 1, fr, fw, fe, tv)) == -1)
version(Win32)
{
if(WSAGetLastError() != WSAEINTR)
@@ -2088,6 +2089,7 @@
// private:
private uint nbytes; //Win32: excludes uint.size "count"
private byte* buf;
+ private socket_t maxfd = 0;
version(Win32)
@@ -2193,6 +2195,15 @@
***********************************************************************/
+ socket_t maxFd()
+ {
+ return maxfd;
+ }
+
+ /***********************************************************************
+
+
+ ***********************************************************************/
void reset()
{
@@ -2226,6 +2237,9 @@
}
body
{
+ if (s > maxfd)
+ maxfd = s;
+
version(Win32)
{
uint c = count;