Ticket #13 (closed defect: fixed)

Opened 3 years ago

Last modified 9 months ago

Wrong value for first argument of select() in mango.io.Socket.reader()

Reported by: jcomellas Assigned to:
Priority: minor Milestone:
Component: mango.io Version: SVN HEAD
Keywords: select Linux Cc:

Description

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;

Attachments

Socket.d-linux_select_bug (1.6 kB) - added by jcomellas on 01/30/06 12:03:34.
Fix for problem with select() usage in Linux

Change History

01/30/06 12:02:56 changed by jcomellas

Sorry, I've just seen that I can attach a file after sending the bug report. I am also attaching the file.

01/30/06 12:03:34 changed by jcomellas

  • attachment Socket.d-linux_select_bug added.

Fix for problem with select() usage in Linux

12/07/07 02:41:46 changed by kris

  • status changed from new to closed.
  • resolution set to fixed.

Moved to Tango