inline int    hpi::timeout(int fd, long timeout) {
  int res;
  struct timeval t;
  julong prevtime, newtime;
  static const char* aNull = 0;

  struct pollfd pfd;
  pfd.fd = fd;
  pfd.events = POLLIN;

  gettimeofday(&t, &aNull);
  prevtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec / 1000;

  for(;;) {
  
    INTERRUPTIBLE_NORESTART(::poll(&pfd, 1, timeout), res, os::Solaris::clear_interrupted);
    if(res == OS_ERR && errno == EINTR) {
	gettimeofday(&t, &aNull);
	newtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec /1000;
	timeout -= newtime - prevtime;
	if(timeout <= 0)
	  return OS_OK;
	prevtime = newtime;
    } else
      return res;
  }
}
inline int
hpi::connect(int fd, struct sockaddr *him, int len) {
  do {
    int _result;
    INTERRUPTIBLE_NORESTART(::connect(fd, him, len), _result,
                            os::Solaris::clear_interrupted);

    // Depending on when thread interruption is reset, _result could be
    // one of two values when errno == EINTR

    if (((_result == OS_INTRPT) || (_result == OS_ERR)) && (errno == EINTR)) {
      /* restarting a connect() changes its errno semantics */
      INTERRUPTIBLE(::connect(fd, him, len), _result,
                      os::Solaris::clear_interrupted);
      /* undo these changes */
      if (_result == OS_ERR) {
        if (errno == EALREADY) errno = EINPROGRESS; /* fall through */
        else if (errno == EISCONN) { errno = 0; return OS_OK; }
      }
    }
    return _result;
  } while(false);
}