Description |
|
The parameter s is a socket descriptor. The addr
parameter is a pointer to a socket address structure. This structure
contains the address of a remote socket to which a connection is established. The
addrlen parameter specifies the size of this address structure. Since
the size of the socket address structure varies between socket address
families (16 bytes for AF_INET; 110 bytes for AF_UNIX),
the correct socket address structure should be used with each address
family (struct sockaddr_in for AF_INET,
struct sockaddr_un for AF_UNIX).
If the socket is of type SOCK_STREAM,
then connect attempts to contact the remote host in order
to make a connection between the remote socket (peer) and the local
socket specified by s. The call normally blocks until the
connection completes. If non-blocking mode has been enabled using
the O_NONBLOCK or O_NDELAY fcntl
flags and the connection cannot be completed immediately, then connect
returns an error as described below. In these cases, the select
call can be used on this socket to determine when the connection has
completed by selecting it for writing.
The O_NONBLOCK and O_NDELAY flags are defined
in <fcntl.h> and are explained in the fcntl
section. If s is a SOCK_STREAM socket that is
bound to the same local address as another SOCK_STREAM
socket and addr is the same as the peer address of the other
socket, connect returns EADDRINUSE.
If the AF_INET socket does not already have a local address
bound to it (refer to the bind call), the connect
call also binds the socket to a local address chosen by the system.
Stream sockets may successfully connect only once.
Return Value |
|
If the call is successful, a 0 is returned. If it fails, a -1 is returned,
and an error code is stored in errno.
See Also |
|
accept, select, socket, getsockname,
fcntl