diff options
Diffstat (limited to 'libs/libcurl/src/nonblock.c')
-rw-r--r-- | libs/libcurl/src/nonblock.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/libs/libcurl/src/nonblock.c b/libs/libcurl/src/nonblock.c index d46b5b2659..4b1268aa98 100644 --- a/libs/libcurl/src/nonblock.c +++ b/libs/libcurl/src/nonblock.c @@ -50,9 +50,18 @@ int curlx_nonblock(curl_socket_t sockfd, /* operate on this */ /* most recent unix versions */
int flags;
flags = sfcntl(sockfd, F_GETFL, 0);
+ if(flags < 0)
+ return -1;
+ /* Check if the current file status flags have already satisfied
+ * the request, if so, it is no need to call fcntl() to replicate it.
+ */
+ if(!!(flags & O_NONBLOCK) == !!nonblock)
+ return 0;
if(nonblock)
- return sfcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
- return sfcntl(sockfd, F_SETFL, flags & (~O_NONBLOCK));
+ flags |= O_NONBLOCK;
+ else
+ flags &= ~O_NONBLOCK;
+ return sfcntl(sockfd, F_SETFL, flags);
#elif defined(HAVE_IOCTL_FIONBIO)
@@ -64,7 +73,7 @@ int curlx_nonblock(curl_socket_t sockfd, /* operate on this */ /* Windows */
unsigned long flags = nonblock ? 1UL : 0UL;
- return ioctlsocket(sockfd, FIONBIO, &flags);
+ return ioctlsocket(sockfd, (long)FIONBIO, &flags);
#elif defined(HAVE_IOCTLSOCKET_CAMEL_FIONBIO)
|