From 345c2506c47f2e7b46070a3c46ba0e3b7a80aa1f Mon Sep 17 00:00:00 2001 From: millert Date: Sat, 20 Aug 2016 20:22:28 +0000 Subject: [PATCH] Sync connect_wait() example with its real usage in ftp(1). --- lib/libc/sys/connect.2 | 40 ++++++++++++++++++---------------------- 1 file 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 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 -- 2.20.1