diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2016-08-20 20:22:29 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2016-08-20 20:22:29 +0000 |
commit | b7dab22791d5dc7fcdcf583d915d9c74af7e1767 (patch) | |
tree | 08dbc10212e183ed76a64434ee9f806c12b07ee5 /lib | |
parent | 5814e40b1ca8bd1ca952a01be45be0ac4ae40ab9 (diff) |
Sync connect_wait() example with its real usage in ftp(1).
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/sys/connect.2 | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/lib/libc/sys/connect.2 b/lib/libc/sys/connect.2 index 2f8e0c5a7ae..9c0cfb09d79 100644 --- a/lib/libc/sys/connect.2 +++ b/lib/libc/sys/connect.2 @@ -1,4 +1,4 @@ -.\" $OpenBSD: connect.2,v 1.30 2016/08/18 22:29:02 millert Exp $ +.\" $OpenBSD: connect.2,v 1.31 2016/08/20 20:22:28 millert Exp $ .\" $NetBSD: connect.2,v 1.8 1995/10/12 15:40:48 jtc Exp $ .\" .\" Copyright (c) 1983, 1993 @@ -30,7 +30,7 @@ .\" .\" @(#)connect.2 8.1 (Berkeley) 6/4/93 .\" -.Dd $Mdocdate: August 18 2016 $ +.Dd $Mdocdate: August 20 2016 $ .Dt CONNECT 2 .Os .Sh NAME @@ -117,7 +117,7 @@ is interrupted by a signal. #include <err.h> int -connect_wait(int s, const struct sockaddr *name, socklen_t namelen) +connect_wait(int s) { struct pollfd pfd[1]; int error = 0; @@ -125,19 +125,16 @@ connect_wait(int s, const struct sockaddr *name, socklen_t namelen) pfd[0].fd = s; pfd[0].events = POLLOUT; - for (;;) { - if (poll(pfd, 1, -1) == -1) { - if (errno != EINTR) - return -1; - continue; - } - if (getsockopt(s, SOL_SOCKET, SO_ERROR, &error, &len) < 0) - return -1; - if (error != 0) - errno = error; - break; + + if (poll(pfd, 1, -1) == -1) + return -1; + if (getsockopt(s, SOL_SOCKET, SO_ERROR, &error, &len) < 0) + return -1; + if (error != 0) { + errno = error; + return -1; } - return (error ? -1 : 0); + return 0; } \&... @@ -146,13 +143,12 @@ int retcode; \&... -retcode = connect(s, name, namelen); -if (retcode == -1) { - if (errno == EINTR) - retcode = connect_wait(s, name, namelen); - if (retcode == -1) - err(1, "connect"); -} +for (retcode = connect(s, name, namelen); + retcode != 0 && errno == EINTR; + retcode = connect_wait(s)) + continue; +if (retcode == -1) + err(1, "connect"); .Ed .Sh ERRORS The |