当前位置: 首页>>代码示例>>C++>>正文


C++ IOBufQueue类代码示例

本文整理汇总了C++中IOBufQueue的典型用法代码示例。如果您正苦于以下问题:C++ IOBufQueue类的具体用法?C++ IOBufQueue怎么用?C++ IOBufQueue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IOBufQueue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: LOG

void helper<ProtocolReader, ProtocolWriter>::process_exn(
    const char* func,
    const string& msg,
    unique_ptr<ResponseChannel::Request> req,
    Cpp2RequestContext* ctx,
    EventBase* eb,
    int32_t protoSeqId) {
  ProtocolWriter oprot;
  if (req) {
    LOG(ERROR) << msg << " in function " << func;
    TApplicationException x(msg);
    IOBufQueue queue = helper_w<ProtocolWriter>::write_exn(
        func, &oprot, protoSeqId, nullptr, x);
    queue.append(THeader::transform(
          queue.move(),
          ctx->getHeader()->getWriteTransforms(),
          ctx->getHeader()->getMinCompressBytes()));
    auto queue_mw = makeMoveWrapper(move(queue));
    auto req_mw = makeMoveWrapper(move(req));
    eb->runInEventBaseThread([=]() mutable {
      (*req_mw)->sendReply(queue_mw->move());
    });
  } else {
    LOG(ERROR) << msg << " in oneway function " << func;
  }
}
开发者ID:Patrick-Park,项目名称:fbthrift,代码行数:26,代码来源:GeneratedCodeHelper.cpp

示例2: runtime_error

std::unique_ptr<IOBuf> LengthFieldBasedFrameDecoder::decode(
  Context* ctx, IOBufQueue& buf, size_t&) {
  // discarding too long frame
  if (buf.chainLength() <= lengthFieldEndOffset_) {
    return nullptr;
  }

  uint64_t frameLength = getUnadjustedFrameLength(
    buf, lengthFieldOffset_, lengthFieldLength_, networkByteOrder_);

  frameLength += lengthAdjustment_ + lengthFieldEndOffset_;

  if (frameLength < lengthFieldEndOffset_) {
    throw std::runtime_error("Frame too small");
  }

  if (frameLength > maxFrameLength_) {
    throw std::runtime_error("Frame larger than " +
                             folly::to<std::string>(maxFrameLength_));
  }

  if (buf.chainLength() < frameLength) {
    return nullptr;
  }

  if (initialBytesToStrip_ > frameLength) {
    throw std::runtime_error("InitialBytesToSkip larger than frame");
  }

  buf.trimStart(initialBytesToStrip_);
  int actualFrameLength = frameLength - initialBytesToStrip_;
  return buf.split(actualFrameLength);
}
开发者ID:AddictXQ,项目名称:folly,代码行数:33,代码来源:LengthFieldBasedFrameDecoder.cpp

示例3: decode

 bool decode(Context*,
             IOBufQueue& buf,
             std::string& result,
             size_t&) override {
   if (buf.chainLength() > 0) {
     result = buf.move()->moveToFbString().toStdString();
     return true;
   }
   return false;
 }
开发者ID:derskeal,项目名称:wangle,代码行数:10,代码来源:BroadcastProxy.cpp

示例4: sendResponseHeaders

void FastCGITransport::sendResponseHeaders(IOBufQueue& queue, int code) {
  CHECK(!m_headersSent);
  m_headersSent = true;

  if (code != 200) {
    queue.append(s_status);
    queue.append(std::to_string(code));
    auto reasonStr = getResponseInfo();
    if (reasonStr.empty()) {
      reasonStr = HttpProtocol::GetReasonString(code);
    }
    queue.append(s_space);
    queue.append(reasonStr);
    queue.append(s_newline);
  }

  for (auto& header : m_responseHeaders) {
    for (auto& value : header.second) {
      queue.append(header.first);
      queue.append(s_colon);
      queue.append(value);
      queue.append(s_newline);
    }
  }
  queue.append(s_newline);
}
开发者ID:Mo-k-tec,项目名称:hhvm,代码行数:26,代码来源:fastcgi-transport.cpp

示例5: TEST

TEST(SerializationTest, DeserializeReturningObjGivenStringPiece) {
  using serializer = SimpleJSONSerializer;

  auto s = makeTestStruct();
  IOBufQueue q;
  serializer::serialize(s, &q);
  auto b = q.move();

  auto out = serializer::deserialize<TestStruct>(StringPiece(b->coalesce()));
  EXPECT_EQ(s, out);
}
开发者ID:facebook,项目名称:fbthrift,代码行数:11,代码来源:SerializationTest.cpp

示例6: TEST_F

TEST_F(BroadcastHandlerTest, OnCompleted) {
  // Test with EOF on the handler
  EXPECT_CALL(*decoder, decode(_, _, _, _))
      .WillRepeatedly(
          Invoke([&](MockByteToMessageDecoder<std::string>::Context*,
                     IOBufQueue& q, std::string& data, size_t&) {
            auto buf = q.move();
            if (buf) {
              buf->coalesce();
              data = buf->moveToFbString().toStdString();
              return true;
            }
            return false;
          }));

  InSequence dummy;

  // Add a subscriber
  EXPECT_EQ(handler->subscribe(&subscriber0), 0);

  EXPECT_CALL(subscriber0, onNext("data1")).Times(1);

  // Push some data
  IOBufQueue q;
  q.append(IOBuf::copyBuffer("data1"));
  pipeline->read(q);
  q.clear();

  // Add another subscriber
  EXPECT_EQ(handler->subscribe(&subscriber1), 1);

  EXPECT_CALL(subscriber0, onNext("data2")).Times(1);
  EXPECT_CALL(subscriber1, onNext("data2")).Times(1);

  // Push more data
  q.append(IOBuf::copyBuffer("data2"));
  pipeline->read(q);
  q.clear();

  // Unsubscribe one of the subscribers
  handler->unsubscribe(0);

  EXPECT_CALL(subscriber1, onCompleted()).Times(1);

  EXPECT_CALL(*handler, close(_))
      .WillOnce(InvokeWithoutArgs([this] {
        pipeline.reset();
        return makeFuture();
      }));

  // The handler should be deleted now
  handler->readEOF(nullptr);
}
开发者ID:project-zerus,项目名称:wangle,代码行数:53,代码来源:BroadcastHandlerTest.cpp

示例7: findEndOfLine

int64_t LineBasedFrameDecoder::findEndOfLine(IOBufQueue& buf) {
  Cursor c(buf.front());
  for (uint32_t i = 0; i < maxLength_ && i < buf.chainLength(); i++) {
    auto b = c.read<char>();
    if (b == '\n' && terminatorType_ != TerminatorType::CARRIAGENEWLINE) {
      return i;
    } else if (terminatorType_ != TerminatorType::NEWLINE &&
               b == '\r' && !c.isAtEnd() && c.read<char>() == '\n') {
      return i;
    }
  }

  return -1;
}
开发者ID:HanumathRao,项目名称:wangle,代码行数:14,代码来源:LineBasedFrameDecoder.cpp

示例8: readBench

void readBench(size_t iters) {
  BenchmarkSuspender susp;
  auto strct = create<Struct>();
  IOBufQueue q;
  Serializer::serialize(strct, &q);
  auto buf = q.move();
  susp.dismiss();

  while (iters--) {
    Struct data;
    Serializer::deserialize(buf.get(), data);
  }
  susp.rehire();
}
开发者ID:ConfusedReality,项目名称:pkg_serialization_fbthrift,代码行数:14,代码来源:ProtocolBench.cpp

示例9: sendResponseHeaders

void FastCGITransport::sendResponseHeaders(IOBufQueue& queue) {
  CHECK(!m_headersSent);
  m_headersSent = true;

  for (auto header : m_responseHeaders) {
    for (auto value : header.second) {
      queue.append(header.first);
      queue.append(": ");
      queue.append(value);
      queue.append("\r\n");
    }
  }
  queue.append("\r\n");
}
开发者ID:Jumbal,项目名称:hhvm,代码行数:14,代码来源:fastcgi-transport.cpp

示例10: readBenchMemory

int readBenchMemory(size_t iters) {
  auto strct = create<Struct>();
  IOBufQueue q;
  Serializer::serialize(strct, &q);
  auto buf = q.move();

  auto before = getMemoryRequestsCounter();

  while (iters--) {
    Struct data;
    Serializer::deserialize(buf.get(), data);
  }

  auto after = getMemoryRequestsCounter();
  return after - before;
}
开发者ID:facebook,项目名称:fbthrift,代码行数:16,代码来源:ThriftVsProtoBufBench.cpp

示例11: sendImpl

void FastCGITransport::sendImpl(const void *data, int size, int code,
                                bool chunked) {
  IOBufQueue queue;
  if (!m_headersSent) {
    sendResponseHeaders(queue, code);
  }
  queue.append(IOBuf::copyBuffer(data, size));
  folly::MoveWrapper<std::unique_ptr<IOBuf>> chain_wrapper(queue.move());
  Callback* callback = m_callback;
  auto fn = [callback, chain_wrapper]() mutable {
    if (callback) {
      callback->onStdOut(std::move(*chain_wrapper));
    }
  };
  m_connection->getEventBase()->runInEventBaseThread(fn);
}
开发者ID:Mo-k-tec,项目名称:hhvm,代码行数:16,代码来源:fastcgi-transport.cpp

示例12: read

  void read(Context* ctx, IOBufQueue& q) override {
    auto buf = q.pop_front();
    buf->coalesce();
    std::string data((const char*)buf->data(), buf->length());

    ctx->fireRead(data);
  }
开发者ID:ramgtv,项目名称:folly,代码行数:7,代码来源:ServiceTest.cpp

示例13: decode

 bool decode(Context* ctx,
             IOBufQueue& buf,
             std::unique_ptr<IOBuf>& result,
             size_t&) override {
   result = buf.move();
   return result != nullptr;
 }
开发者ID:raphaelamorim,项目名称:wangle,代码行数:7,代码来源:ServiceTest.cpp

示例14: sendResponseHeaders

void FastCGITransport::sendResponseHeaders(IOBufQueue& queue, int code) {
  auto appender = [&](folly::StringPiece sp) mutable { queue.append(sp); };
  if (code != 200) {
    auto info = getResponseInfo();
    auto reason = !info.empty() ? info : HttpProtocol::GetReasonString(code);

    folly::format("Status: {} {}\r\n", code, reason)(appender);
  }

  for (auto& header : m_responseHeaders) {
    for (auto& value : header.second) {
      folly::format("{}: {}\r\n", header.first, value)(appender);
    }
  }

  queue.append("\r\n", 2);
}
开发者ID:bjori,项目名称:hhvm,代码行数:17,代码来源:fastcgi-transport.cpp

示例15: communicateIOBuf

std::pair<std::string, std::string> Subprocess::communicate(
    StringPiece input) {
  IOBufQueue inputQueue;
  inputQueue.wrapBuffer(input.data(), input.size());

  auto outQueues = communicateIOBuf(std::move(inputQueue));
  auto outBufs = std::make_pair(outQueues.first.move(),
                                outQueues.second.move());
  std::pair<std::string, std::string> out;
  if (outBufs.first) {
    outBufs.first->coalesce();
    out.first.assign(reinterpret_cast<const char*>(outBufs.first->data()),
                     outBufs.first->length());
  }
  if (outBufs.second) {
    outBufs.second->coalesce();
    out.second.assign(reinterpret_cast<const char*>(outBufs.second->data()),
                     outBufs.second->length());
  }
  return out;
}
开发者ID:PKUKitty,项目名称:folly,代码行数:21,代码来源:Subprocess.cpp


注:本文中的IOBufQueue类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。