コード例 #1
0
void blocking_connection_impl::wait(const condition &condition, const std::string &msg, duration wait_timeout)
{
    reactor& reactor = container_->reactor();

    if (wait_timeout == duration(-1))
        wait_timeout = container_->reactor().timeout();

    if (wait_timeout == duration::FOREVER) {
        while (!condition()) {
            reactor.process();
        }
    } else {
        save_timeout st(reactor);
        reactor.timeout(wait_timeout);
        pn_timestamp_t deadline = pn_reactor_mark(pn_cast(&reactor)) + wait_timeout.milliseconds;
        while (!condition()) {
            reactor.process();
            if (!condition()) {
                pn_timestamp_t now = pn_reactor_mark(pn_cast(&reactor));
                if (now < deadline)
                    reactor.timeout(duration(deadline - now));
                else
                    throw timeout_error("connection timed out " + msg);
            }
        }
    }
}
コード例 #2
0
ファイル: socket_connection.cpp プロジェクト: TellarHK/wwiv
static int read_TYPE(const SOCKET sock, TYPE* data, const milliseconds d, std::size_t size = SIZE) {
  auto end = system_clock::now() + d;
  char *p = reinterpret_cast<char*>(data);
  std::size_t total_read = 0;
  int remaining = size;
  while (true) {
    if (system_clock::now() > end) {
      throw timeout_error("timeout error reading from socket.");
    }
    int result = ::recv(sock, p, remaining, 0);
    if (result == SOCKET_ERROR) {
      if (WouldSocketBlock()) {
        sleep_for(SLEEP_MS);
        continue;
      }
    }
    if (result == 0) {
      return total_read;
    }
    total_read += result;
    if (total_read < size) {
      p += result;
      remaining -= result;
      continue;
    }
    return total_read;
  }
  throw socket_error("unknown error reading from socket.");
}
コード例 #3
0
ファイル: exception.cpp プロジェクト: miz-take/elliptics
static void throw_error_detail(int err, const std::string &message)
{
	switch (err) {
		case -ENOENT:
			throw not_found_error(message);
			break;
		case -ETIMEDOUT:
			throw timeout_error(message);
			break;
		default:
			throw error(err, message);
			break;
	}
}
コード例 #4
0
ファイル: exception.cpp プロジェクト: SaveTheRbtz/elliptics
void error_info::throw_error() const
{
	switch (m_code) {
		case -ENOENT:
			throw not_found_error(m_message);
			break;
		case -ETIMEDOUT:
			throw timeout_error(m_message);
			break;
		case -ENOMEM:
			throw std::bad_alloc();
			break;
		case -ENXIO:
			throw no_such_address_error(m_message);
			break;
		case 0:
			// Do nothing, it's not an error
			break;
		default:
			throw error(m_code, m_message);
			break;
	}
}
コード例 #5
0
	void take()
	{
		if (twai_sem(semid_, 500*5) == E_TMOUT)
			throw timeout_error();
		used_ = true;
	}