FD_ZERO(&wd); FD_SET(osfd, &wd); #ifdef XP_OS2 rv = _MD_SELECT(osfd + 1, NULL, &wd, NULL, tvp); #else FD_ZERO(&ex); FD_SET(osfd, &ex); rv = _MD_SELECT(osfd + 1, NULL, &wd, &ex, tvp); #endif  #vacpp #else #!bsd_select if (timeout == PR_INTERVAL_NO_TIMEOUT) lTimeout = -1; else { lTimeout = PR_IntervalToMilliseconds(timeout);
PR_ASSERT(rv == 1); if (_PR_PENDING_INTERRUPT(me)) { me->flags &= ~_PR_INTERRUPT; PR_SetError( PR_PENDING_INTERRUPT_ERROR, 0); return -1;
_PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,                PRIntervalTime timeout){    PRInt32 osfd = fd->secret->md.osfd;    PRInt32 rv;    int err, len;#ifdef BSD_SELECT#ifdef XP_OS2//_VACPP    fd_set wd;#else    fd_set wd, ex;#endif  #vacpp    struct timeval tv, *tvp;#else    int socks[1];     long lTimeout = -1;#endif    if ((rv = connect(osfd, (struct sockaddr *) addr, addrlen)) == -1)     {        err = sock_errno();        if ((!fd->secret->nonblocking) && ((err == EINPROGRESS) || (err == EWOULDBLOCK)))        {#ifdef BSD_SELECT           if (timeout == PR_INTERVAL_NO_TIMEOUT)               tvp = NULL;            else             {                tv.tv_sec = PR_IntervalToSeconds(timeout);                tv.tv_usec = PR_IntervalToMicroseconds(timeout - PR_SecondsToInterval(tv.tv_sec));                tvp = &tv;            }            FD_ZERO(&wd);            FD_SET(osfd, &wd);#ifdef XP_OS2//_VACPP            rv = _MD_SELECT(osfd + 1, NULL, &wd, NULL, tvp);#else            FD_ZERO(&ex);            FD_SET(osfd, &ex);            rv = _MD_SELECT(osfd + 1, NULL, &wd, &ex, tvp);#endif  #vacpp#else #!bsd_select            if (timeout == PR_INTERVAL_NO_TIMEOUT)                lTimeout = -1;            else             {                lTimeout = PR_IntervalToMilliseconds(timeout);              }	                socks[0] = osfd; #ifdef XP_OS2//_VACPP            rv = _MD_SELECT(socks, 0, 1, 0, lTimeout);#else            rv = _MD_SELECT(socks, 0, 1, 1, lTimeout);#endif  #vacpp#endif            if (rv > 0)             {#ifdef BSD_SELECT#ifdef XP_OS2//_VACPP                if (FD_ISSET(osfd, &wd))                {                    //DosSleep(0);                    len = sizeof(err);                    if (getsockopt(osfd, SOL_SOCKET, SO_ERROR,                           (char *) &err, &len) < 0)                    {                          _PR_MD_MAP_GETSOCKOPT_ERROR(sock_errno());                        return -1;                    }                    if (err != 0)                    {                        _PR_MD_MAP_CONNECT_ERROR(err);                        return -1;                    }                    else                        return 0;   /* it's connected */                }                else                    return -1;#else               if (FD_ISSET(osfd, &ex))               {                   DosSleep(0);                   len = sizeof(err);                   if (getsockopt(osfd, SOL_SOCKET, SO_ERROR,                           (char *) &err, &len) < 0)                   {                         _PR_MD_MAP_GETSOCKOPT_ERROR(sock_errno());                       return -1;                   }                   if (err != 0)                       _PR_MD_MAP_CONNECT_ERROR(err);                   else                       PR_SetError(PR_UNKNOWN_ERROR, 0);                   return -1;               }               if (FD_ISSET(osfd, &wd))               {                   /* it's connected */                   return 0;               }#endif  #vacpp#else #!bsd_select                if (socks[0] == osfd)                {                  len = sizeof(err);                  if (getsockopt(osfd, SOL_SOCKET, SO_ERROR,                         (char *) &err, &len) < 0)                  {                      _PR_MD_MAP_GETSOCKOPT_ERROR(sock_errno());                    return -1;                  }                  if (err != 0)                  {                    _PR_MD_MAP_CONNECT_ERROR(err);                    return -1;                  }                  else                    return 0;   /* it's connected */                }                else                  return -1;#endif            }            else if (rv == 0)             {                PR_SetError(PR_IO_TIMEOUT_ERROR, 0);                return(-1);            } else if (rv < 0)             {                _PR_MD_MAP_SELECT_ERROR(sock_errno());                return(-1);            }        }         _PR_MD_MAP_CONNECT_ERROR(err);    }    return rv;}