-.\" $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
.\"
.\" @(#)connect.2 8.1 (Berkeley) 6/4/93
.\"
-.Dd $Mdocdate: August 18 2016 $
+.Dd $Mdocdate: August 20 2016 $
.Dt CONNECT 2
.Os
.Sh NAME
#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;
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;
}
\&...
\&...
-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