[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnurl] 54/411: select: simplify return code handling for poll and selec
From: |
gnunet |
Subject: |
[gnurl] 54/411: select: simplify return code handling for poll and select |
Date: |
Wed, 13 Jan 2021 01:17:49 +0100 |
This is an automated email from the git hooks/post-receive script.
nikita pushed a commit to branch master
in repository gnurl.
commit 05729b66c56fe67ce96a1a0a037cd4946aa46e36
Author: Marc Hoersken <info@marc-hoersken.de>
AuthorDate: Fri Aug 28 18:21:47 2020 +0200
select: simplify return code handling for poll and select
poll and select already return -1 on error according to POSIX,
so there is no need to perform a <0 to -1 conversion in code.
Also we can just use one check with <= 0 on the return code.
Assisted-by: Daniel Stenberg
Reviewed-by: Jay Satiro
Replaces #5852
Closes #5880
---
lib/select.c | 37 +++++++++++++------------------------
1 file changed, 13 insertions(+), 24 deletions(-)
diff --git a/lib/select.c b/lib/select.c
index 90f731c9a..5bb6d12cc 100644
--- a/lib/select.c
+++ b/lib/select.c
@@ -149,15 +149,14 @@ int Curl_select(curl_socket_t maxfd, /* highest socket
number */
{
struct timeval pending_tv;
struct timeval *ptimeout;
- int r;
#ifdef USE_WINSOCK
/* WinSock select() can't handle zero events. See the comment below. */
if((!fds_read || fds_read->fd_count == 0) &&
(!fds_write || fds_write->fd_count == 0) &&
(!fds_err || fds_err->fd_count == 0)) {
- r = Curl_wait_ms(timeout_ms);
- return r;
+ /* no sockets, just wait */
+ return Curl_wait_ms(timeout_ms);
}
#endif
@@ -212,15 +211,13 @@ int Curl_select(curl_socket_t maxfd, /* highest socket
number */
calling this an error. Luckily, with WinSock, we can _also_ ask how
many bits are set on an fd_set. So, let's just check it beforehand.
*/
- r = select((int)maxfd + 1,
- fds_read && fds_read->fd_count ? fds_read : NULL,
- fds_write && fds_write->fd_count ? fds_write : NULL,
- fds_err && fds_err->fd_count ? fds_err : NULL, ptimeout);
+ return select((int)maxfd + 1,
+ fds_read && fds_read->fd_count ? fds_read : NULL,
+ fds_write && fds_write->fd_count ? fds_write : NULL,
+ fds_err && fds_err->fd_count ? fds_err : NULL, ptimeout);
#else
- r = select((int)maxfd + 1, fds_read, fds_write, fds_err, ptimeout);
+ return select((int)maxfd + 1, fds_read, fds_write, fds_err, ptimeout);
#endif
-
- return r;
}
/*
@@ -255,8 +252,7 @@ int Curl_socket_check(curl_socket_t readfd0, /* two sockets
to read from */
if((readfd0 == CURL_SOCKET_BAD) && (readfd1 == CURL_SOCKET_BAD) &&
(writefd == CURL_SOCKET_BAD)) {
/* no sockets, just wait */
- r = Curl_wait_ms(timeout_ms);
- return r;
+ return Curl_wait_ms(timeout_ms);
}
/* Avoid initial timestamp, avoid Curl_now() call, when elapsed
@@ -351,8 +347,7 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds,
timediff_t timeout_ms)
}
if(fds_none) {
/* no sockets, just wait */
- r = Curl_wait_ms(timeout_ms);
- return r;
+ return Curl_wait_ms(timeout_ms);
}
/* Avoid initial timestamp, avoid Curl_now() call, when elapsed
@@ -374,11 +369,8 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds,
timediff_t timeout_ms)
else
pending_ms = 0;
r = poll(ufds, nfds, pending_ms);
-
- if(r < 0)
- return -1;
- if(r == 0)
- return 0;
+ if(r <= 0)
+ return r;
for(i = 0; i < nfds; i++) {
if(ufds[i].fd == CURL_SOCKET_BAD)
@@ -421,11 +413,8 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds,
timediff_t timeout_ms)
value).
*/
r = Curl_select(maxfd, &fds_read, &fds_write, &fds_err, timeout_ms);
-
- if(r < 0)
- return -1;
- if(r == 0)
- return 0;
+ if(r <= 0)
+ return r;
r = 0;
for(i = 0; i < nfds; i++) {
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [gnurl] 66/411: RELEASE-NOTES: synced, (continued)
- [gnurl] 66/411: RELEASE-NOTES: synced, gnunet, 2021/01/12
- [gnurl] 39/411: configure: added --disable-get-easy-options, gnunet, 2021/01/12
- [gnurl] 53/411: RELEASE-NOTES: synced, gnunet, 2021/01/12
- [gnurl] 65/411: mqtt: enable by default, gnunet, 2021/01/12
- [gnurl] 58/411: tests/getpart: use MIME::Base64 instead of home-cooked, gnunet, 2021/01/12
- [gnurl] 63/411: url: remove funny embedded comments in Curl_disonnect calls, gnunet, 2021/01/12
- [gnurl] 46/411: docs: SSLCERTS: fix English syntax, gnunet, 2021/01/12
- [gnurl] 70/411: lib/Makefile.am: bump VERSIONINFO due to new functions, gnunet, 2021/01/12
- [gnurl] 71/411: test971: show test mismatches "inline", gnunet, 2021/01/12
- [gnurl] 44/411: curl.1: fix typo invokved -> invoked, gnunet, 2021/01/12
- [gnurl] 54/411: select: simplify return code handling for poll and select,
gnunet <=
- [gnurl] 69/411: optiontable: use DEBUGBUILD, gnunet, 2021/01/12
- [gnurl] 37/411: HTTP/3: update to OpenSSL_1_1_1g-quic-draft-29, gnunet, 2021/01/12
- [gnurl] 11/411: sftp: add new quote commands 'atime' and 'mtime', gnunet, 2021/01/12
- [gnurl] 40/411: scripts: improve the "get latest curl release tag" logic, gnunet, 2021/01/12
- [gnurl] 52/411: tests: add test1912 with typechecks, gnunet, 2021/01/12
- [gnurl] 61/411: buildconf: exec autoreconf to avoid additional process, gnunet, 2021/01/12
- [gnurl] 72/411: copyright.pl: ignore buildconf, gnunet, 2021/01/12
- [gnurl] 62/411: conn: check for connection being dead before reuse, gnunet, 2021/01/12
- [gnurl] 45/411: docs: non-existing macros in man pages, gnunet, 2021/01/12
- [gnurl] 38/411: options: API for meta-data about easy options, gnunet, 2021/01/12