aboutsummaryrefslogtreecommitdiffstats
path: root/socket.c
diff options
context:
space:
mode:
Diffstat (limited to 'socket.c')
-rw-r--r--socket.c38
1 files changed, 20 insertions, 18 deletions
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);
}