From b1000cb703b852ea6c7493d9d8d24780e4a3b157 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Mon, 28 Oct 1996 03:49:39 +0000 Subject: Cleanup for PL3. svn path=/trunk/; revision=402 --- socket.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'socket.c') diff --git a/socket.c b/socket.c index ba281a31..52f88e95 100644 --- a/socket.c +++ b/socket.c @@ -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); } -- cgit v1.2.3