diff options
author | Eric S. Raymond <esr@thyrsus.com> | 1996-10-28 03:49:39 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 1996-10-28 03:49:39 +0000 |
commit | b1000cb703b852ea6c7493d9d8d24780e4a3b157 (patch) | |
tree | cd6a56441d638475c0b331cda5b3c0c7c1fbfd5f /socket.c | |
parent | cab2269e10d82e3e5e371889b42d19d0cafc9eaa (diff) | |
download | fetchmail-b1000cb703b852ea6c7493d9d8d24780e4a3b157.tar.gz fetchmail-b1000cb703b852ea6c7493d9d8d24780e4a3b157.tar.bz2 fetchmail-b1000cb703b852ea6c7493d9d8d24780e4a3b157.zip |
Cleanup for PL3.
svn path=/trunk/; revision=402
Diffstat (limited to 'socket.c')
-rw-r--r-- | socket.c | 38 |
1 files changed, 20 insertions, 18 deletions
@@ -192,28 +192,30 @@ int len; for data. */ int SockDataWaiting(int socket) { - int flags; - char sbuf[INTERNAL_BUFSIZE]; - int n; - int res; - flags = fcntl(socket,F_GETFL,0); + int flags; + char sbuf[INTERNAL_BUFSIZE]; + int n; + flags = fcntl(socket,F_GETFL,0); - /* set it to non-block */ - if (fcntl(socket,F_SETFL,flags | O_NONBLOCK) == -1) - return -1; + /* set it to non-block */ + if (fcntl(socket,F_SETFL,flags | O_NONBLOCK) == -1) + return -1; + + n = recv(socket,sbuf,INTERNAL_BUFSIZE,MSG_PEEK); + + /* reset it to block (or, whatever it was). */ + fcntl(socket,F_SETFL,flags); - if ((n = recv(socket,sbuf,INTERNAL_BUFSIZE,MSG_PEEK)) == -1) + if (n == -1) { - /* No data to read. */ - if (errno == EWOULDBLOCK) - res = 0; + /* No data to read. */ + if (errno == EWOULDBLOCK) + return(0); + else + return(-1); } - else - res = n; - - /* reset it to block (or, whatever it was). */ - fcntl(socket,F_SETFL,flags); - return res; + else + return(n); } |