diff options
Diffstat (limited to 'libs/libcurl/src/select.c')
-rw-r--r-- | libs/libcurl/src/select.c | 65 |
1 files changed, 36 insertions, 29 deletions
diff --git a/libs/libcurl/src/select.c b/libs/libcurl/src/select.c index d01820d966..01bde7c0ee 100644 --- a/libs/libcurl/src/select.c +++ b/libs/libcurl/src/select.c @@ -45,8 +45,8 @@ #include "urldata.h"
#include "connect.h"
#include "select.h"
-#include "timediff.h"
-#include "warnless.h"
+#include "curlx/timediff.h"
+#include "curlx/warnless.h"
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
#include "curl_memory.h"
@@ -74,11 +74,11 @@ int Curl_wait_ms(timediff_t timeout_ms) if(!timeout_ms)
return 0;
if(timeout_ms < 0) {
- SET_SOCKERRNO(EINVAL);
+ SET_SOCKERRNO(SOCKEINVAL);
return -1;
}
#if defined(MSDOS)
- delay(timeout_ms);
+ delay((unsigned int)timeout_ms);
#elif defined(_WIN32)
/* prevent overflow, timeout_ms is typecast to ULONG/DWORD. */
#if TIMEDIFF_T_MAX >= ULONG_MAX
@@ -86,7 +86,7 @@ int Curl_wait_ms(timediff_t timeout_ms) timeout_ms = ULONG_MAX-1;
/* do not use ULONG_MAX, because that is equal to INFINITE */
#endif
- Sleep((ULONG)timeout_ms);
+ Sleep((DWORD)timeout_ms);
#else
/* avoid using poll() for this since it behaves incorrectly with no sockets
on Apple operating systems */
@@ -96,7 +96,7 @@ int Curl_wait_ms(timediff_t timeout_ms) }
#endif /* _WIN32 */
if(r) {
- if((r == -1) && (SOCKERRNO == EINTR))
+ if((r == -1) && (SOCKERRNO == SOCKEINTR))
/* make EINTR from select or poll not a "lethal" error */
r = 0;
else
@@ -197,7 +197,7 @@ int Curl_socket_check(curl_socket_t readfd0, /* two sockets to read from */ return Curl_wait_ms(timeout_ms);
}
- /* Avoid initial timestamp, avoid Curl_now() call, when elapsed
+ /* Avoid initial timestamp, avoid curlx_now() call, when elapsed
time in this function does not need to be measured. This happens
when function is called with a zero timeout or a negative timeout
value indicating a blocking call should be performed. */
@@ -292,7 +292,7 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, timediff_t timeout_ms) return Curl_wait_ms(timeout_ms);
}
- /* Avoid initial timestamp, avoid Curl_now() call, when elapsed
+ /* Avoid initial timestamp, avoid curlx_now() call, when elapsed
time in this function does not need to be measured. This happens
when function is called with a zero timeout or a negative timeout
value indicating a blocking call should be performed. */
@@ -312,7 +312,7 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, timediff_t timeout_ms) pending_ms = 0;
r = poll(ufds, nfds, pending_ms);
if(r <= 0) {
- if((r == -1) && (SOCKERRNO == EINTR))
+ if((r == -1) && (SOCKERRNO == SOCKEINTR))
/* make EINTR from select or poll not a "lethal" error */
r = 0;
return r;
@@ -360,7 +360,7 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, timediff_t timeout_ms) */
r = our_select(maxfd, &fds_read, &fds_write, &fds_err, timeout_ms);
if(r <= 0) {
- if((r == -1) && (SOCKERRNO == EINTR))
+ if((r == -1) && (SOCKERRNO == SOCKEINTR))
/* make EINTR from select or poll not a "lethal" error */
r = 0;
return r;
@@ -410,6 +410,11 @@ void Curl_pollfds_init(struct curl_pollfds *cpfds, }
}
+void Curl_pollfds_reset(struct curl_pollfds *cpfds)
+{
+ cpfds->n = 0;
+}
+
void Curl_pollfds_cleanup(struct curl_pollfds *cpfds)
{
DEBUGASSERT(cpfds);
@@ -488,43 +493,47 @@ CURLcode Curl_pollfds_add_ps(struct curl_pollfds *cpfds, return CURLE_OK;
}
-void Curl_waitfds_init(struct curl_waitfds *cwfds,
+void Curl_waitfds_init(struct Curl_waitfds *cwfds,
struct curl_waitfd *static_wfds,
unsigned int static_count)
{
DEBUGASSERT(cwfds);
- DEBUGASSERT(static_wfds);
+ DEBUGASSERT(static_wfds || !static_count);
memset(cwfds, 0, sizeof(*cwfds));
cwfds->wfds = static_wfds;
cwfds->count = static_count;
}
-static CURLcode cwfds_add_sock(struct curl_waitfds *cwfds,
- curl_socket_t sock, short events)
+static unsigned int cwfds_add_sock(struct Curl_waitfds *cwfds,
+ curl_socket_t sock, short events)
{
int i;
-
+ if(!cwfds->wfds) {
+ DEBUGASSERT(!cwfds->count && !cwfds->n);
+ return 1;
+ }
if(cwfds->n <= INT_MAX) {
for(i = (int)cwfds->n - 1; i >= 0; --i) {
if(sock == cwfds->wfds[i].fd) {
cwfds->wfds[i].events |= events;
- return CURLE_OK;
+ return 0;
}
}
}
/* not folded, add new entry */
- if(cwfds->n >= cwfds->count)
- return CURLE_OUT_OF_MEMORY;
- cwfds->wfds[cwfds->n].fd = sock;
- cwfds->wfds[cwfds->n].events = events;
- ++cwfds->n;
- return CURLE_OK;
+ if(cwfds->n < cwfds->count) {
+ cwfds->wfds[cwfds->n].fd = sock;
+ cwfds->wfds[cwfds->n].events = events;
+ ++cwfds->n;
+ }
+ return 1;
}
-CURLcode Curl_waitfds_add_ps(struct curl_waitfds *cwfds,
- struct easy_pollset *ps)
+unsigned int Curl_waitfds_add_ps(struct Curl_waitfds *cwfds,
+ struct easy_pollset *ps)
{
size_t i;
+ unsigned int need = 0;
DEBUGASSERT(cwfds);
DEBUGASSERT(ps);
@@ -534,10 +543,8 @@ CURLcode Curl_waitfds_add_ps(struct curl_waitfds *cwfds, events |= CURL_WAIT_POLLIN;
if(ps->actions[i] & CURL_POLL_OUT)
events |= CURL_WAIT_POLLOUT;
- if(events) {
- if(cwfds_add_sock(cwfds, ps->sockets[i], events))
- return CURLE_OUT_OF_MEMORY;
- }
+ if(events)
+ need += cwfds_add_sock(cwfds, ps->sockets[i], events);
}
- return CURLE_OK;
+ return need;
}
|