Example #1
0
bool AsciiSerializedReply::prepare(const McReply& reply,
                                   mc_op_t operation,
                                   const folly::Optional<folly::IOBuf>& key,
                                   struct iovec*& iovOut, size_t& niovOut) {
  mc_msg_t replyMsg;
  mc_msg_init_not_refcounted(&replyMsg);
  reply.dependentMsg(operation, &replyMsg);

  nstring_t k;
  if (key.hasValue()) {
    k.str = (char*)key->data();
    k.len = key->length();
  } else {
    k.str = nullptr;
    k.len = 0;
  }
  niovOut = mc_ascii_response_write_iovs(
    &asciiResponse_,
    k,
    operation,
    &replyMsg,
    iovs_,
    kMaxIovs);
  iovOut = iovs_;
  return niovOut != 0;
}
Example #2
0
void McServerTransaction::buildResponseText() {
    niovs_ = mc_ascii_response_write_iovs(&asciiResponse_,
                                          request_.dependentMsg(operation_).get(),
                                          &replyMsg_,
                                          iovs_,
                                          kMaxIovs);
}
Example #3
0
bool WriteBuffer::prepare(McServerRequestContext&& ctx, McReply&& reply,
                          mc_protocol_t protocol,
                          struct iovec*& iovOut, size_t& niovOut) {
  ctx_.emplace(std::move(ctx));
  reply_.emplace(std::move(reply));
  reply_->dependentMsg(ctx_->operation_, &replyMsg_);

  nstring_t k;
  if (ctx_->key_.hasValue()) {
    k.str = (char*)ctx_->key_->data();
    k.len = ctx_->key_->length();
  } else {
    k.str = nullptr;
    k.len = 0;
  }

  if (protocol == mc_ascii_protocol) {
    niovs_ = mc_ascii_response_write_iovs(
      &asciiResponse_,
      k,
      ctx_->operation_,
      &replyMsg_,
      iovs_,
      kMaxIovs);
  } else if (protocol == mc_umbrella_protocol) {
    auto niovs = um_write_iovs(&umMsg_, ctx_->reqid_,
                               &replyMsg_,
                               iovs_, kMaxIovs);
    niovs_ = (niovs == -1 ? 0 : niovs);
  } else {
    CHECK(false) << "Unknown protocol";
  }

  iovOut = iovs_;
  niovOut = niovs_;

  return niovs_ != 0;
}