Commit 594b7e77 authored by Alan Frindell's avatar Alan Frindell Committed by Facebook GitHub Bot

Implement 'isBufferMovable' in ReadCallback

Summary: This is more efficient for some underlying transports, including Fizz.

Reviewed By: yfeldblum

Differential Revision: D33724711

fbshipit-source-id: 35ebcce83da4a9289f7f083c8873142e9b844ca0
parent 7f73100f
...@@ -167,6 +167,14 @@ class ReadCallback : public CallbackBase, ...@@ -167,6 +167,14 @@ class ReadCallback : public CallbackBase,
// //
// ReadCallback methods // ReadCallback methods
// //
bool isBufferMovable() noexcept override { return readBuf_; }
void readBufferAvailable(
std::unique_ptr<folly::IOBuf> readBuf) noexcept override {
CHECK(readBuf_);
readBuf_->append(std::move(readBuf));
post();
}
// this is called right before readDataAvailable(), always // this is called right before readDataAvailable(), always
// in the same sequence // in the same sequence
...@@ -330,6 +338,7 @@ Task<size_t> Transport::read( ...@@ -330,6 +338,7 @@ Task<size_t> Transport::read(
} }
VLOG(5) << "Transport::read(), expecting minReadSize=" << minReadSize; VLOG(5) << "Transport::read(), expecting minReadSize=" << minReadSize;
auto readBufStartLength = readBuf.chainLength();
ReadCallback cb{ ReadCallback cb{
eventBase_->timer(), eventBase_->timer(),
*transport_, *transport_,
...@@ -350,8 +359,9 @@ Task<size_t> Transport::read( ...@@ -350,8 +359,9 @@ Task<size_t> Transport::read(
co_yield co_error(std::move(waitRet.exception())); co_yield co_error(std::move(waitRet.exception()));
} }
transport_->setReadCB(nullptr); transport_->setReadCB(nullptr);
deferredReadEOF_ = (cb.eof && cb.length > 0); auto length = readBuf.chainLength() - readBufStartLength;
co_return cb.length; deferredReadEOF_ = (cb.eof && length > 0);
co_return length;
} }
Task<folly::Unit> Transport::write( Task<folly::Unit> Transport::write(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment