fcntl(fd, F_GETFL) returns the flags as the return value, not via a passed
authorDan Winship <danw@src.gnome.org>
Tue, 16 Jan 2001 23:27:51 +0000 (23:27 +0000)
committerDan Winship <danw@src.gnome.org>
Tue, 16 Jan 2001 23:27:51 +0000 (23:27 +0000)
* camel-tcp-stream-raw.c (stream_getsockopt, stream_setsockopt):
* camel-stream-fs.c (stream_read, stream_write):
* camel-remote-store.c (socket_connect): fcntl(fd, F_GETFL)
returns the flags as the return value, not via a passed in
pointer. And F_SETFL looks for an int, not a long, and you have to
pass it what it's expecting because it's a va_arg parameter. (Yes,
the man page lies on Linux. But check the UNIX98 spec or the glibc
source.) Also, fix another bug in socket_connect: if we manage to
connect right away, unset O_NONBLOCK so it doesn't mess us up
later.

Fixes a bunch of problems with non-blocking I/O being done in the
allegedly-blocking case and then returning EWOULDBLOCK.

camel/ChangeLog
camel/camel-remote-store.c
camel/camel-stream-fs.c
camel/camel-tcp-stream-raw.c

index 66a0825..9c2ec12 100644 (file)
@@ -1,3 +1,19 @@
+2001-01-16  Dan Winship  <danw@ximian.com>
+
+       * camel-tcp-stream-raw.c (stream_getsockopt, stream_setsockopt):
+       * camel-stream-fs.c (stream_read, stream_write): 
+       * camel-remote-store.c (socket_connect): fcntl(fd, F_GETFL)
+       returns the flags as the return value, not via a passed in
+       pointer. And F_SETFL looks for an int, not a long, and you have to
+       pass it what it's expecting because it's a va_arg parameter. (Yes,
+       the man page lies on Linux. But check the UNIX98 spec or the glibc
+       source.) Also, fix another bug in socket_connect: if we manage to
+       connect right away, unset O_NONBLOCK so it doesn't mess us up
+       later.
+
+       Fixes a bunch of problems with non-blocking I/O being done in the
+       allegedly-blocking case and then returning EWOULDBLOCK.
+
 2001-01-16  Chris Toshok  <toshok@ximian.com>
 
        * providers/Makefile.am (NNTP_DIR): set to nntp if ENABLE_NNTP
index 993d9b5..ef6fe56 100644 (file)
@@ -240,15 +240,16 @@ static int socket_connect(struct hostent *h, int port)
                return fd;
        } else {
                fd_set rdset, wrset;
-               long flags;
-               int fdmax;
+               int flags, fdmax;
 
-               fcntl(fd, F_GETFL, &flags);
+               flags = fcntl(fd, F_GETFL);
                fcntl(fd, F_SETFL, flags | O_NONBLOCK);
 
                ret = connect(fd, (struct sockaddr *)&sin, sizeof (sin));
-               if (ret == 0)
+               if (ret == 0) {
+                       fcntl(fd, F_SETFL, flags);
                        return fd;
+               }
 
                if (errno != EINPROGRESS) {
                        close(fd);
index 92c1143..c1758c1 100644 (file)
@@ -226,10 +226,9 @@ stream_read (CamelStream *stream, char *buffer, size_t n)
                } while (nread == -1 && errno == EINTR);
        } else {
                fd_set rdset;
-               long flags;
-               int fdmax;
+               int flags, fdmax;
 
-               fcntl(stream_fs->fd, F_GETFL, &flags);
+               flags = fcntl(stream_fs->fd, F_GETFL);
                fcntl(stream_fs->fd, F_SETFL, flags | O_NONBLOCK);
                FD_ZERO(&rdset);
                FD_SET(stream_fs->fd, &rdset);
@@ -278,10 +277,9 @@ stream_write (CamelStream *stream, const char *buffer, size_t n)
                } while (v == -1 && errno == EINTR);
        } else {
                fd_set rdset, wrset;
-               long flags;
-               int fdmax;
+               int flags, fdmax;
 
-               fcntl(stream_fs->fd, F_GETFL, &flags);
+               flags = fcntl(stream_fs->fd, F_GETFL);
                fcntl(stream_fs->fd, F_SETFL, flags | O_NONBLOCK);
                FD_ZERO(&rdset);
                FD_ZERO(&wrset);
index 5886a30..6467eed 100644 (file)
@@ -243,9 +243,10 @@ stream_getsockopt (CamelTcpStream *stream, CamelSockOptData *data)
                return -1;
        
        if (data->option == CAMEL_SOCKOPT_NONBLOCKING) {
-               long flags;
+               int flags;
                
-               if (fcntl (((CamelTcpStreamRaw *)stream)->sockfd, F_GETFL, &flags) == -1)
+               flags = fcntl (((CamelTcpStreamRaw *)stream)->sockfd, F_GETFL);
+               if (flags == -1)
                        return -1;
                
                data->value.non_blocking = flags & O_NONBLOCK;
@@ -269,9 +270,10 @@ stream_setsockopt (CamelTcpStream *stream, const CamelSockOptData *data)
                return -1;
        
        if (data->option == CAMEL_SOCKOPT_NONBLOCKING) {
-               guint32 flags, set;
+               int flags, set;
                
-               if (fcntl (((CamelTcpStreamRaw *)stream)->sockfd, F_GETFL, &flags) == -1)
+               fcntl (((CamelTcpStreamRaw *)stream)->sockfd, F_GETFL);
+               if (flags == -1)
                        return -1;
                
                set = data->value.non_blocking ? 1 : 0;