On Mon, 08 Aug 2016 14:35:39 -0600, "Todd C. Miller" wrote: > We should also update the manual accordingly. Alternately, we could move > the useful bits out of EINPROGRESS and into the main body of the manual > and simply refer to them in ERRORS.
This diff moves some of the useful bits out of the ERRORS section an into a new second paragraph. Adapted from NetBSD. - todd Index: lib/libc/sys/connect.2 =================================================================== RCS file: /cvs/src/lib/libc/sys/connect.2,v retrieving revision 1.28 diff -u -p -u -r1.28 connect.2 --- lib/libc/sys/connect.2 9 Aug 2016 12:06:58 -0000 1.28 +++ lib/libc/sys/connect.2 9 Aug 2016 16:03:45 -0000 @@ -74,6 +74,31 @@ only once; datagram sockets may use multiple times to change their association. Datagram sockets may dissolve the association by connecting to an invalid address, such as a null address. +.Pp +If the socket is in non-blocking mode and the connection cannot be +completed immediately, or if it is interrupted by a signal, +.Fn connect +will return an error and the connection attempt will proceed +asynchronously. +Subsequent calls to +.Fn connect +will fail with errno set to +.Er EALREADY . +It is possible to use +.Xr select 2 +or +.Xr poll 2 +to determine when the connect operation has completed by checking the +socket for writability. +The success or failure of the connection attempt may be determined by using +.Xr getsockopt 2 +to check the socket error status with the +.Dv SO_ERROR +option at the +.Dv SOL_SOCKET +level. +If the connection was successful, the error value will be zero. +Otherwise, it will be one of the error values listed below. .Sh RETURN VALUES If the connection or binding succeeds, 0 is returned. Otherwise a \-1 is returned, and a more specific error @@ -106,7 +131,7 @@ The attempt to connect was forcefully re .It Bq Er EHOSTUNREACH The destination address specified an unreachable host. .It Bq Er EINTR -Connection establishment was interrupted by the delivery of a signal. +The connection attempt was interrupted by a signal. The attempt will continue asynchronously as if the socket was non-blocking. .It Bq Er ENETUNREACH The network isn't reachable from this host. @@ -118,20 +143,13 @@ The parameter specifies an area outside the process address space. .It Bq Er EINPROGRESS -The socket is non-blocking -and the connection cannot +The socket is non-blocking and the connection cannot be completed immediately. -It is possible to -.Xr select 2 -or -.Xr poll 2 -for completion by selecting the socket for writing, and also use -.Xr getsockopt 2 -with -.Dv SO_ERROR -to check for error conditions. .It Bq Er EALREADY -A previous connection attempt has not yet been completed. +Either the socket is non-blocking or a previous call to +.Fn connect +was interrupted by a signal, and the connection attempt has not yet +been completed. .El .Pp The following errors are specific to connecting names in the
