SOCKET Ns_SockAsyncConnect ( char *host, int port );
Ns_SockAsyncConnect creates a socket connected to a remote host and port, returning immediately with the connection in progress. A select call can later be used to determine when the connection has been established.
SOCKET sock; fd_set set; struct timeval tv; sock = Ns_SockAsyncConnect("mailhost", 25); ... perform some other work while connection is in progress... ... check for connection ... tv.tv_sec = 2; /* allow 2 more seconds */ tv.tv_usec = 0; FD_ZERO(&set); FD_SET(sock, &set); if (select(sock+1, NULL, &set, NULL, &tv) != 1) { ... timeout - close socket and return error... Ns_CloseLater(sock); } else { ... use socket ... }