aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/usocket.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/usocket.c b/src/usocket.c
index 2143c7d..c1ab725 100644
--- a/src/usocket.c
+++ b/src/usocket.c
@@ -16,7 +16,7 @@
16/*-------------------------------------------------------------------------*\ 16/*-------------------------------------------------------------------------*\
17* Wait for readable/writable/connected socket with timeout 17* Wait for readable/writable/connected socket with timeout
18\*-------------------------------------------------------------------------*/ 18\*-------------------------------------------------------------------------*/
19#ifndef SOCK_SELECT 19#ifdef SOCK_POLL
20#include <sys/poll.h> 20#include <sys/poll.h>
21 21
22#define WAITFD_R POLLIN 22#define WAITFD_R POLLIN
@@ -29,8 +29,10 @@ static int sock_waitfd(int fd, int sw, p_tm tm) {
29 pfd.events = sw; 29 pfd.events = sw;
30 pfd.revents = 0; 30 pfd.revents = 0;
31 if (tm_iszero(tm)) return IO_TIMEOUT; /* optimize timeout == 0 case */ 31 if (tm_iszero(tm)) return IO_TIMEOUT; /* optimize timeout == 0 case */
32 do ret = poll(&pfd, 1, (int)(tm_getretry(tm)*1e3)); 32 do {
33 while (ret == -1 && errno == EINTR); 33 int t = (int)(tm_getretry(tm)*1e3);
34 ret = poll(&pfd, 1, t >= 0? t: -1);
35 } while (ret == -1 && errno == EINTR);
34 if (ret == -1) return errno; 36 if (ret == -1) return errno;
35 if (ret == 0) return IO_TIMEOUT; 37 if (ret == 0) return IO_TIMEOUT;
36 if (sw == WAITFD_C && (pfd.revents & (POLLIN|POLLERR))) return IO_CLOSED; 38 if (sw == WAITFD_C && (pfd.revents & (POLLIN|POLLERR))) return IO_CLOSED;