Remove redundant timeout check, de-select, use-poll instead
authorMiguel de Icaza <miguel@gnome.org>
Thu, 17 Apr 2008 23:49:58 +0000 (23:49 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Thu, 17 Apr 2008 23:49:58 +0000 (23:49 -0000)
svn path=/trunk/mono/; revision=101085

support/serial.c

index 4775805aaf5950ddcb38db917c617e4a26722c80..abe409e05b617269da96c9b7f453dbe179d31ca9 100644 (file)
@@ -91,6 +91,13 @@ read_serial (int fd, guchar *buffer, int offset, int count)
 int
 write_serial (int fd, guchar *buffer, int offset, int count, int timeout)
 {
+       struct pollfd pinfo;
+
+       pinfo.fd = fd;
+       pinfo.events = POLLOUT;
+       pinfo.revents = POLLOUT;
+
+       
        struct timeval tmval;
        fd_set writefs;
        guint32 n;
@@ -105,12 +112,13 @@ write_serial (int fd, guchar *buffer, int offset, int count, int timeout)
        {
                size_t t;
                        
-               if (timeout > 0)
-               {
-                       if (select(fd+1, NULL, &writefs, NULL, &tmval) <= 0 && errno != EINTR)
-                       {
+               if (timeout > 0) {
+                       int c;
+                       
+                       while ((c = poll (&pinfo, 1, timeout)) == -1 && errno == EINTR)
+                               ;
+                       if (c == -1)
                                return -1;
-                       }
                }               
 
                do {
@@ -120,14 +128,6 @@ write_serial (int fd, guchar *buffer, int offset, int count, int timeout)
                if (t < 0)
                        return -1;
                
-               if (timeout > 0)
-               {
-                       if (select(fd+1, NULL, &writefs, NULL, &tmval) <= 0  && errno != EINTR)
-                       {
-                               return -1;
-                       }
-               }
-
                offset += t;
                n -= t; 
        }