非阻塞connect errno为EINPROGRESS,如何判断已经连接上了?

via:http://stackoverflow.com/questions/8145624/getpeername-can-not-recognize-connection-established


To determine if the socket is connected, it is more usual to use getsockopt() rather than getpeername():

int so_error;
socklen_t len = sizeof(so_error);

getsockopt(sock, SOL_SOCKET, SO_ERROR, &so_error, &len);

if (so_error == 0) {
    /* socket is connected */
}


你可能感兴趣的:(C++,socket,linux,connect,网络编程)