summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/misc.c b/misc.c
index 78c00eb8e..5204c1e9f 100644
--- a/misc.c
+++ b/misc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: misc.c,v 1.142 2019/09/03 08:32:11 djm Exp $ */ 1/* $OpenBSD: misc.c,v 1.143 2019/11/22 06:50:30 dtucker Exp $ */
2/* 2/*
3 * Copyright (c) 2000 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000 Markus Friedl. All rights reserved.
4 * Copyright (c) 2005,2006 Damien Miller. All rights reserved. 4 * Copyright (c) 2005,2006 Damien Miller. All rights reserved.
@@ -238,12 +238,12 @@ set_rdomain(int fd, const char *name)
238} 238}
239 239
240/* 240/*
241 * Wait up to *timeoutp milliseconds for fd to be readable. Updates 241 * Wait up to *timeoutp milliseconds for events on fd. Updates
242 * *timeoutp with time remaining. 242 * *timeoutp with time remaining.
243 * Returns 0 if fd ready or -1 on timeout or error (see errno). 243 * Returns 0 if fd ready or -1 on timeout or error (see errno).
244 */ 244 */
245int 245static int
246waitrfd(int fd, int *timeoutp) 246waitfd(int fd, int *timeoutp, short events)
247{ 247{
248 struct pollfd pfd; 248 struct pollfd pfd;
249 struct timeval t_start; 249 struct timeval t_start;
@@ -251,7 +251,7 @@ waitrfd(int fd, int *timeoutp)
251 251
252 monotime_tv(&t_start); 252 monotime_tv(&t_start);
253 pfd.fd = fd; 253 pfd.fd = fd;
254 pfd.events = POLLIN; 254 pfd.events = events;
255 for (; *timeoutp >= 0;) { 255 for (; *timeoutp >= 0;) {
256 r = poll(&pfd, 1, *timeoutp); 256 r = poll(&pfd, 1, *timeoutp);
257 oerrno = errno; 257 oerrno = errno;
@@ -270,6 +270,16 @@ waitrfd(int fd, int *timeoutp)
270} 270}
271 271
272/* 272/*
273 * Wait up to *timeoutp milliseconds for fd to be readable. Updates
274 * *timeoutp with time remaining.
275 * Returns 0 if fd ready or -1 on timeout or error (see errno).
276 */
277int
278waitrfd(int fd, int *timeoutp) {
279 return waitfd(fd, timeoutp, POLLIN);
280}
281
282/*
273 * Attempt a non-blocking connect(2) to the specified address, waiting up to 283 * Attempt a non-blocking connect(2) to the specified address, waiting up to
274 * *timeoutp milliseconds for the connection to complete. If the timeout is 284 * *timeoutp milliseconds for the connection to complete. If the timeout is
275 * <=0, then wait indefinitely. 285 * <=0, then wait indefinitely.
@@ -295,7 +305,7 @@ timeout_connect(int sockfd, const struct sockaddr *serv_addr,
295 } else if (errno != EINPROGRESS) 305 } else if (errno != EINPROGRESS)
296 return -1; 306 return -1;
297 307
298 if (waitrfd(sockfd, timeoutp) == -1) 308 if (waitfd(sockfd, timeoutp, POLLIN | POLLOUT) == -1)
299 return -1; 309 return -1;
300 310
301 /* Completed or failed */ 311 /* Completed or failed */