Parameters
-
s [in]
-
A descriptor identifying an unconnected socket.
name [in]
-
A pointer to the sockaddr structure to which the connection should be established.
namelen [in]
-
The length, in bytes, of the sockaddr structure pointed to by the name parameter.
Return Value
If no error occurs, connect returns zero. Otherwise, it returns SOCKET_ERROR, and a specific error code can be retrieved by calling WSAGetLastError.
注:对于阻塞型的socket,返回值代表连接成功或失败。
对于非阻塞型socket, the connection attempt cannot be completed immediately. In this case, connect will return SOCKET_ERROR, and WSAGetLastError will return WSAEWOULDBLOCK. In this case, there are three possible scenarios:
- Use the select function to determine the completion of the connection request by checking to see if the socket is writeable.
- If the application is using WSAAsyncSelect to indicate interest in connection events, then the application will receive an FD_CONNECT notification indicating that the connect operation is complete (successfully or not).
- If the application is using WSAEventSelect to indicate interest in connection events, then the associated event object will be signaled indicating that the connect operation is complete (successfully or not).