示例#1
0
bool QIrSocketEngine::waitFor(QIrSocketEngine::SelectTypes types,
                              int fd, int timeout, bool *timedOut,
                              bool *canRead, bool *canWrite)
{
    if (timedOut)
        *timedOut = false;

    QTime stopWatch;
    stopWatch.start();

    while ((timeout < 0) || (stopWatch.elapsed() < timeout)) {
        int msecs = timeout_value(timeout, stopWatch.elapsed());
        int ret = select(types, fd, msecs, canRead, canWrite);

        if (ret == 0) {
            if (timedOut)
                *timedOut = true;

            m_error = QIrSocket::TimeoutError;
            return false;
        }

        if (ret > 0)
            return true;

        // Have an error condition, continue on interrupt
        if (errno == EINTR)
            continue;

        break;
    }

    m_error = QIrSocket::UnknownError;
    return false;
}
示例#2
0
static u_int
host_is_up (ACE_TCHAR hostname[])
{
  ACE_SOCK_Connector con;
  ACE_SOCK_Stream sock;

  // The ACE_INET_Addr construction causes gethostbyname_r to be
  // called, so we need to copy the hostname.
  ACE_TCHAR test_host[MAXHOSTNAMELEN];
  ACE_OS::strcpy (test_host, hostname);

  ACE_INET_Addr another_host ((u_short) 7, test_host);
  ACE_Time_Value timeout_value (5);
  int const status = con.connect (sock,
                                  another_host,
                                  &timeout_value);
  sock.close ();
  return status == 0  ?  1  :  0;
}