Пример #1
0
void AsyncMcServerWorker::addClientSocket(
    folly::AsyncSocket::UniquePtr&& socket,
    void* userCtxt) {
  if (!onRequest_) {
    throw std::logic_error("can't add a socket without onRequest callback");
  }

  if (onAccepted_) {
    onAccepted_();
  }

  socket->setSendTimeout(opts_.sendTimeout.count());
  socket->setMaxReadsPerEvent(opts_.maxReadsPerEvent);
  socket->setNoDelay(true);

  sessions_.push_back(
    McServerSession::create(
      std::move(socket),
      onRequest_,
      onWriteQuiescence_,
      onCloseStart_,
      [this] (McServerSession& session) {
        if (onCloseFinish_) {
          onCloseFinish_(session);
        }
        sessions_.erase(sessions_.iterator_to(session));
      },
      onShutdown_,
      opts_,
      userCtxt
    ));
}
Пример #2
0
McServerSession* AsyncMcServerWorker::addClientTransport(
    folly::AsyncTransportWrapper::UniquePtr transport,
    void* userCtxt) {
  if (!onRequest_) {
    throw std::logic_error("can't add a transport without onRequest callback");
  }

  if (onAccepted_) {
    onAccepted_();
  }

  transport->setSendTimeout(opts_.sendTimeout.count());

  try {
    return std::addressof(tracker_.add(
        std::move(transport),
        onRequest_,
        opts_,
        userCtxt,
        compressionCodecMap_));
  } catch (const std::exception& ex) {
    // TODO: record stats about failure
    return nullptr;
  }
}