diff options
author | Ludovic Courtès <ludo@gnu.org> | 2011-10-22 16:24:32 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2011-10-22 16:24:32 +0200 |
commit | 35428fb6b2d269dbfa2eec7d0739aec149bd4cc2 (patch) | |
tree | 03146c5871ad9b2167f3dffc89fdbb3082d7fc4e /lib/recvfrom.c | |
parent | fe4ea6859e7d19a0fe2694a3fb49f4abb722afc1 (diff) | |
download | guile-35428fb6b2d269dbfa2eec7d0739aec149bd4cc2.tar.gz |
Update Gnulib to v0.0-6523-gb3609c1.
Diffstat (limited to 'lib/recvfrom.c')
-rw-r--r-- | lib/recvfrom.c | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/lib/recvfrom.c b/lib/recvfrom.c index 068f5a576..60c2ec1bf 100644 --- a/lib/recvfrom.c +++ b/lib/recvfrom.c @@ -32,17 +32,27 @@ ssize_t rpl_recvfrom (int fd, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen) { - int frombufsize = (from != NULL ? *fromlen : 0); SOCKET sock = FD_TO_SOCKET (fd); - int r = recvfrom (sock, buf, len, flags, from, fromlen); - if (r < 0) - set_winsock_errno (); - - /* Winsock recvfrom() only returns a valid 'from' when the socket is - connectionless. POSIX gives a valid 'from' for all types of sockets. */ - else if (from != NULL && *fromlen == frombufsize) - rpl_getpeername (fd, from, fromlen); - - return r; + if (sock == INVALID_SOCKET) + { + errno = EBADF; + return -1; + } + else + { + int frombufsize = (from != NULL ? *fromlen : 0); + int r = recvfrom (sock, buf, len, flags, from, fromlen); + + if (r < 0) + set_winsock_errno (); + + /* Winsock recvfrom() only returns a valid 'from' when the socket is + connectionless. POSIX gives a valid 'from' for all types of + sockets. */ + else if (from != NULL && *fromlen == frombufsize) + rpl_getpeername (fd, from, fromlen); + + return r; + } } |