Esempio n. 1
0
void TEvhttpClientChannel::finish(struct evhttp_request* req) {
  if (req == NULL) {
    try {
      cob_();
    } catch (const TTransportException& e) {
      if (e.getType() == TTransportException::END_OF_FILE)
        throw TException("connect failed");
      else
        throw;
    }
    return;
  } else if (req->response_code != 200) {
    try {
      cob_();
    } catch (const TTransportException& e) {
      std::stringstream ss;
      ss << "server returned code " << req->response_code;
      if (req->response_code_line)
        ss << ": " << req->response_code_line;
      if (e.getType() == TTransportException::END_OF_FILE)
        throw TException(ss.str());
      else
        throw;
    }
    return;
  }
  recvBuf_->resetBuffer(EVBUFFER_DATA(req->input_buffer),
                        static_cast<uint32_t>(EVBUFFER_LENGTH(req->input_buffer)));
  cob_();
  return;
}
void TEvhttpClientChannel::finish(struct evhttp_request* req) {
  if (req == NULL) {
    return cob_();
  } else if (req->response_code != 200) {
    return cob_();
  }
  recvBuf_->resetBuffer(
      EVBUFFER_DATA(req->input_buffer),
      EVBUFFER_LENGTH(req->input_buffer));
  return cob_();
}
Esempio n. 3
0
void HttpFetcher::readEOF() noexcept {
  // The remote end closed the connection.  This means we have the full
  // request.  (Since we're using HTTP/1.0, the server will immediately close
  // the connection after sending the response.)
  //
  // Invoke the callback object with the full response string
  cob_(response_);

  // HttpFetcher objects are allocated on the heap.
  // Destroy this object after it has finished.
  delete this;
}
Esempio n. 4
0
void EventBase::CobTimeout::timeoutExpired() noexcept {
  // For now, we just swallow any exceptions that the callback threw.
  try {
    cob_();
  } catch (const std::exception& ex) {
    LOG(ERROR) << "EventBase::runAfterDelay() callback threw "
               << typeid(ex).name() << " exception: " << ex.what();
  } catch (...) {
    LOG(ERROR) << "EventBase::runAfterDelay() callback threw non-exception "
               << "type";
  }

  // The CobTimeout object was allocated on the heap by runAfterDelay(),
  // so delete it now that the it has fired.
  delete this;
}