diff options
Diffstat (limited to 'src/usocket.c')
-rw-r--r-- | src/usocket.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/usocket.c b/src/usocket.c index 3428a0c..3e151bf 100644 --- a/src/usocket.c +++ b/src/usocket.c | |||
@@ -22,10 +22,10 @@ | |||
22 | #define WAITFD_R POLLIN | 22 | #define WAITFD_R POLLIN |
23 | #define WAITFD_W POLLOUT | 23 | #define WAITFD_W POLLOUT |
24 | #define WAITFD_C (POLLIN|POLLOUT) | 24 | #define WAITFD_C (POLLIN|POLLOUT) |
25 | int sock_waitfd(int fd, int sw, p_tm tm) { | 25 | int sock_waitfd(p_sock ps, int sw, p_tm tm) { |
26 | int ret; | 26 | int ret; |
27 | struct pollfd pfd; | 27 | struct pollfd pfd; |
28 | pfd.fd = fd; | 28 | pfd.fd = *ps; |
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 */ |
@@ -44,7 +44,7 @@ int sock_waitfd(int fd, int sw, p_tm tm) { | |||
44 | #define WAITFD_W 2 | 44 | #define WAITFD_W 2 |
45 | #define WAITFD_C (WAITFD_R|WAITFD_W) | 45 | #define WAITFD_C (WAITFD_R|WAITFD_W) |
46 | 46 | ||
47 | int sock_waitfd(int fd, int sw, p_tm tm) { | 47 | int sock_waitfd(p_sock ps, int sw, p_tm tm) { |
48 | int ret; | 48 | int ret; |
49 | fd_set rfds, wfds, *rp, *wp; | 49 | fd_set rfds, wfds, *rp, *wp; |
50 | struct timeval tv, *tp; | 50 | struct timeval tv, *tp; |
@@ -53,8 +53,8 @@ int sock_waitfd(int fd, int sw, p_tm tm) { | |||
53 | do { | 53 | do { |
54 | /* must set bits within loop, because select may have modifed them */ | 54 | /* must set bits within loop, because select may have modifed them */ |
55 | rp = wp = NULL; | 55 | rp = wp = NULL; |
56 | if (sw & WAITFD_R) { FD_ZERO(&rfds); FD_SET(fd, &rfds); rp = &rfds; } | 56 | if (sw & WAITFD_R) { FD_ZERO(&rfds); FD_SET(*ps, &rfds); rp = &rfds; } |
57 | if (sw & WAITFD_W) { FD_ZERO(&wfds); FD_SET(fd, &wfds); wp = &wfds; } | 57 | if (sw & WAITFD_W) { FD_ZERO(&wfds); FD_SET(*ps, &wfds); wp = &wfds; } |
58 | t = tm_getretry(tm); | 58 | t = tm_getretry(tm); |
59 | tp = NULL; | 59 | tp = NULL; |
60 | if (t >= 0.0) { | 60 | if (t >= 0.0) { |
@@ -62,11 +62,11 @@ int sock_waitfd(int fd, int sw, p_tm tm) { | |||
62 | tv.tv_usec = (int)((t-tv.tv_sec)*1.0e6); | 62 | tv.tv_usec = (int)((t-tv.tv_sec)*1.0e6); |
63 | tp = &tv; | 63 | tp = &tv; |
64 | } | 64 | } |
65 | ret = select(fd+1, rp, wp, NULL, tp); | 65 | ret = select(*ps+1, rp, wp, NULL, tp); |
66 | } while (ret == -1 && errno == EINTR); | 66 | } while (ret == -1 && errno == EINTR); |
67 | if (ret == -1) return errno; | 67 | if (ret == -1) return errno; |
68 | if (ret == 0) return IO_TIMEOUT; | 68 | if (ret == 0) return IO_TIMEOUT; |
69 | if (sw == WAITFD_C && FD_ISSET(fd, &rfds)) return IO_CLOSED; | 69 | if (sw == WAITFD_C && FD_ISSET(*ps, &rfds)) return IO_CLOSED; |
70 | return IO_DONE; | 70 | return IO_DONE; |
71 | } | 71 | } |
72 | #endif | 72 | #endif |
@@ -177,7 +177,7 @@ int sock_connect(p_sock ps, SA *addr, socklen_t len, p_tm tm) { | |||
177 | \*-------------------------------------------------------------------------*/ | 177 | \*-------------------------------------------------------------------------*/ |
178 | int sock_connected(p_sock ps, p_tm tm) { | 178 | int sock_connected(p_sock ps, p_tm tm) { |
179 | int err; | 179 | int err; |
180 | if ((err = sock_waitfd(*ps, WAITFD_C, tm) == IO_CLOSED)) { | 180 | if ((err = sock_waitfd(ps, WAITFD_C, tm) == IO_CLOSED)) { |
181 | if (recv(*ps, (char *) &err, 0, 0) == 0) return IO_DONE; | 181 | if (recv(*ps, (char *) &err, 0, 0) == 0) return IO_DONE; |
182 | else return errno; | 182 | else return errno; |
183 | } else return err; | 183 | } else return err; |
@@ -198,7 +198,7 @@ int sock_accept(p_sock ps, p_sock pa, SA *addr, socklen_t *len, p_tm tm) { | |||
198 | err = errno; | 198 | err = errno; |
199 | if (err == EINTR) continue; | 199 | if (err == EINTR) continue; |
200 | if (err != EAGAIN && err != ECONNABORTED) return err; | 200 | if (err != EAGAIN && err != ECONNABORTED) return err; |
201 | if ((err = sock_waitfd(*ps, WAITFD_R, tm)) != IO_DONE) return err; | 201 | if ((err = sock_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err; |
202 | } | 202 | } |
203 | /* can't reach here */ | 203 | /* can't reach here */ |
204 | return IO_UNKNOWN; | 204 | return IO_UNKNOWN; |
@@ -230,7 +230,7 @@ int sock_send(p_sock ps, const char *data, size_t count, size_t *sent, p_tm tm) | |||
230 | /* if failed fatal reason, report error */ | 230 | /* if failed fatal reason, report error */ |
231 | if (err != EAGAIN) return err; | 231 | if (err != EAGAIN) return err; |
232 | /* wait until we can send something or we timeout */ | 232 | /* wait until we can send something or we timeout */ |
233 | if ((err = sock_waitfd(*ps, WAITFD_W, tm)) != IO_DONE) return err; | 233 | if ((err = sock_waitfd(ps, WAITFD_W, tm)) != IO_DONE) return err; |
234 | } | 234 | } |
235 | /* can't reach here */ | 235 | /* can't reach here */ |
236 | return IO_UNKNOWN; | 236 | return IO_UNKNOWN; |
@@ -255,7 +255,7 @@ int sock_sendto(p_sock ps, const char *data, size_t count, size_t *sent, | |||
255 | if (put == 0 || err == EPIPE) return IO_CLOSED; | 255 | if (put == 0 || err == EPIPE) return IO_CLOSED; |
256 | if (err == EINTR) continue; | 256 | if (err == EINTR) continue; |
257 | if (err != EAGAIN) return err; | 257 | if (err != EAGAIN) return err; |
258 | if ((err = sock_waitfd(*ps, WAITFD_W, tm)) != IO_DONE) return err; | 258 | if ((err = sock_waitfd(ps, WAITFD_W, tm)) != IO_DONE) return err; |
259 | } | 259 | } |
260 | return IO_UNKNOWN; | 260 | return IO_UNKNOWN; |
261 | } | 261 | } |
@@ -277,7 +277,7 @@ int sock_recv(p_sock ps, char *data, size_t count, size_t *got, p_tm tm) { | |||
277 | if (taken == 0) return IO_CLOSED; | 277 | if (taken == 0) return IO_CLOSED; |
278 | if (err == EINTR) continue; | 278 | if (err == EINTR) continue; |
279 | if (err != EAGAIN) return err; | 279 | if (err != EAGAIN) return err; |
280 | if ((err = sock_waitfd(*ps, WAITFD_R, tm)) != IO_DONE) return err; | 280 | if ((err = sock_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err; |
281 | } | 281 | } |
282 | return IO_UNKNOWN; | 282 | return IO_UNKNOWN; |
283 | } | 283 | } |
@@ -300,7 +300,7 @@ int sock_recvfrom(p_sock ps, char *data, size_t count, size_t *got, | |||
300 | if (taken == 0) return IO_CLOSED; | 300 | if (taken == 0) return IO_CLOSED; |
301 | if (err == EINTR) continue; | 301 | if (err == EINTR) continue; |
302 | if (err != EAGAIN) return err; | 302 | if (err != EAGAIN) return err; |
303 | if ((err = sock_waitfd(*ps, WAITFD_R, tm)) != IO_DONE) return err; | 303 | if ((err = sock_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err; |
304 | } | 304 | } |
305 | return IO_UNKNOWN; | 305 | return IO_UNKNOWN; |
306 | } | 306 | } |