Exemple #1
0
void HandlerCallbackBase::sendReply(
    folly::IOBufQueue queue,
    apache::thrift::Stream<folly::IOBufQueue>&& stream) {
  folly::Optional<uint32_t> crc32c = checksumIfNeeded(queue);
  transform(queue);
  auto stream_ =
      std::move(stream).map([](auto&& value) mutable { return value.move(); });
  if (getEventBase()->isInEventBaseThread()) {
    req_->sendStreamReply({queue.move(), std::move(stream_)}, nullptr, crc32c);
  } else {
    getEventBase()->runInEventBaseThread([req = std::move(req_),
                                          queue = std::move(queue),
                                          stream = std::move(stream_),
                                          crc32c]() mutable {
      req->sendStreamReply({queue.move(), std::move(stream)}, nullptr, crc32c);
    });
  }
}
  bool parseRoutingData(folly::IOBufQueue& bufQueue,
                        RoutingData& routingData) override {
    if (bufQueue.chainLength() == 0) {
      return false;
    }

    auto buf = bufQueue.move();
    buf->coalesce();
    // Use the first byte for hashing to a worker
    routingData.routingData = buf->data()[0];
    routingData.bufQueue.append(std::move(buf));
    return true;
  }
Exemple #3
0
void Cpp2Channel::read(Context* ctx, folly::IOBufQueue& q) {
    DestructorGuard dg(this);

    if (recvCallback_ && recvCallback_->shouldSample() && !sample_) {
        sample_.reset(new RecvCallback::sample);
        sample_->readBegin = Util::currentTimeUsec();
    }

    if (!recvCallback_) {
        LOG(INFO) << "Received a message, but no recvCallback_ installed!";
        return;
    }

    if (sample_) {
        sample_->readEnd = Util::currentTimeUsec();
    }

    recvCallback_->messageReceived(q.move(), std::move(sample_));
}