int Ns_SockCloseLater ( SOCKET sock );
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 ... }