Unix-system-calls-connect
[top]#
|http://www.google.com/[Google] | a|
Web | This Site |
選択した読書
Copyright©2014 by finddevguides |
[cols=",,,,,,,",] |
| | Home | | References | | Discussion Forums | | About TP
[width="100%",cols="100%",] |
a| == connect()-Unix、Linuxシステムコール
[[File:]] image :http://www.finddevguides.com/images/next.gif [next] image:http://www.finddevguides.com/add- this.gif [AddThisソーシャルブックマークボタン]
広告
NAME
connect-ソケットで接続を開始します
概要
#include <sys/types.h> #include <sys/socket.h> int connect(int sockfd, const struct sockaddr* serv_addr, socklen_t addrlen); |
説明
ソケット_sockfd_のタイプが SOCK_DGRAM の場合、_serv_addr_はデフォルトでデータグラムが送信されるアドレスであり、データグラムを受信する唯一のアドレスです。 ソケットのタイプが SOCK_STREAM または SOCK_SEQPACKET の場合、この呼び出しは、_serv_addr_で指定されたアドレスにバインドされているソケットへの接続を試みます。
一般に、接続ベースのプロトコルソケットは connect ()を1回だけ正常に実行できます。コネクションレス型プロトコルソケットは、 connect ()を複数回使用して関連付けを変更できます。 コネクションレスソケットは、 sockaddr の_sa_family_メンバーを AF_UNSPEC に設定してアドレスに接続することにより、関連付けを解除できます。
返り値
接続またはバインディングが成功すると、ゼロが返されます。 エラーの場合、-1が返され、_errno_が適切に設定されます。
エラー
以下は一般的なソケットエラーのみです。 他のドメイン固有のエラーコードがある可能性があります。
Error Code | Description |
---|---|
*EACCES * | For Unix domain sockets, which are identified by pathname: Write permission is denied on the socket file, or search permission is denied for one of the directories in the path prefix. (See also* path_resolution*(2).) |
EACCES, EPERM | The user tried to connect to a broadcast address without having the socket broadcast flag enabled or the connection request failed because of a local firewall rule. |
EADDRINUSE | Local address is already in use. |
EAFNOSUPPORT | The passed address didn’t have the correct address family in its sa_family field. |
EADDRNOTAVAIL | Non-existent interface was requested or the requested address was not local. |
EALREADY | The socket is non-blocking and a previous connection attempt has not yet been completed. |
EBADF | The file descriptor is not a valid index in the descriptor table. |
ECONNREFUSED | No one listening on the remote address. |
EFAULT | The socket structure address is outside the user’s address space. |
*EINPROGRESS * | The socket is non-blocking and the connection cannot be completed immediately. It is possible to* select*(2) or poll(2) for completion by selecting the socket for writing. After select(2) indicates writability, use getsockopt(2) to read the SO_ERROR *option at level SOL_SOCKET to determine whether connect*() completed successfully (SO_ERROR is zero) or unsuccessfully (SO_ERROR is one of the usual error codes listed here, explaining the reason for the failure). |
EINTR | The system call was interrupted by a signal that was caught. |
EISCONN | The socket is already connected. |
ENETUNREACH | Network is unreachable. |
ENOTSOCK | The file descriptor is not associated with a socket. |
ETIMEDOUT | Timeout while attempting connection. The server may be too busy to accept new connections. Note that for IP sockets the timeout may be very long when syncookies are enabled on the server. |
準拠
SVr4、4.4BSD( connect ()関数は4.2BSDで初めて登場しました)。
NOTE
BUGS
- connect_()を AF_UNSPEC アドレスで呼び出してソケットを切断することはまだ実装されていません。
関連項目
[[File:]] image :http://www.finddevguides.com/images/next.gif [next] [[File:]]
広告
|
[cols="^",] |
|Advertisements