[Linux manuál]
Návod, kniha: POSIX Programmer's Manual
int connect(int socket, const struct sockaddr
* address,
socklen_t
address_len );
connect: připojte zásuvku
Originální popis anglicky: connect - connect a socketNávod, kniha: POSIX Programmer's Manual
STRUČNĚ
#include <sys/socket.h>POPIS / INSTRUKCE
The connect() function shall attempt to make a connection on a socket. The function takes the following arguments:- socket
- Specifies the file descriptor associated with the socket.
- address
- Points to a sockaddr structure containing the peer address. The length and format of the address depend on the address family of the socket.
- address_len
- Specifies the length of the sockaddr structure
pointed to by the address argument.
NÁVRATOVÁ HODNOTA
Upon successful completion, connect() shall return 0; otherwise, -1 shall be returned and errno set to indicate the error.CHYBY / ERRORY
The connect() function shall fail if:- EADDRNOTAVAIL
- The specified address is not available from the local machine.
- EAFNOSUPPORT
- The specified address is not a valid address for the address family of the specified socket.
- EALREADY
- A connection request is already in progress for the specified socket.
- EBADF
- The socket argument is not a valid file descriptor.
- ECONNREFUSED
- The target address was not listening for connections or refused the connection request.
- EINPROGRESS
- O_NONBLOCK is set for the file descriptor for the socket and the connection cannot be immediately established; the connection shall be established asynchronously.
- EINTR
- The attempt to establish a connection was interrupted by delivery of a signal that was caught; the connection shall be established asynchronously.
- EISCONN
- The specified socket is connection-mode and is already connected.
- ENETUNREACH
- No route to the network is present.
- ENOTSOCK
- The socket argument does not refer to a socket.
- EPROTOTYPE
- The specified address has a different type than the socket bound to the specified peer address.
- ETIMEDOUT
- The attempt to connect timed out before a connection was
made.
- EIO
- An I/O error occurred while reading from or writing to the file system.
- ELOOP
- A loop exists in symbolic links encountered during resolution of the pathname in address.
- ENAMETOOLONG
- A component of a pathname exceeded {NAME_MAX} characters, or an entire pathname exceeded {PATH_MAX} characters.
- ENOENT
- A component of the pathname does not name an existing file or the pathname is an empty string.
- ENOTDIR
- A component of the path prefix of the pathname in
address is not a directory.
- EACCES
- Search permission is denied for a component of the path prefix; or write access to the named socket is denied.
- EADDRINUSE
- Attempt to establish a connection that uses addresses that are already in use.
- ECONNRESET
- Remote host reset the connection request.
- EHOSTUNREACH
- The destination host cannot be reached (probably because the host is down or a remote router cannot reach it).
- EINVAL
- The address_len argument is not a valid length for the address family; or invalid address family in the sockaddr structure.
- ELOOP
- More than {SYMLOOP_MAX} symbolic links were encountered during resolution of the pathname in address.
- ENAMETOOLONG
- Pathname resolution of a symbolic link produced an intermediate result whose length exceeds {PATH_MAX}.
- ENETDOWN
- The local network interface used to reach the destination is down.
- ENOBUFS
- No buffer space is available.
- EOPNOTSUPP
- The socket is listening and cannot be connected.
PŘÍKLADY POUŽITÍ
None.APPLICATION USAGE
If connect() fails, the state of the socket is unspecified. Conforming applications should close the file descriptor and create a new socket before attempting to reconnect.RATIONALE
None.FUTURE DIRECTIONS
None.SOUVISEJÍCÍ
accept() , bind() , close() , getsockname() , poll() , select() , send() , shutdown() , socket() , the Base Definitions volume of IEEE Std 1003.1-2001, <sys/socket.h>COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .| 2003 | IEEE/The Open Group |