- try {
- readCallback_->getReadBuffer(&buf, &buflen);
- } catch (const std::exception& ex) {
- AsyncSocketException aex(AsyncSocketException::BAD_ARGS,
- string("ReadCallback::getReadBuffer() "
- "threw exception: ") + ex.what());
- failRead(aex);
- return;
- } catch (...) {
- AsyncSocketException ex(AsyncSocketException::BAD_ARGS,
- string("ReadCallback::getReadBuffer() "
- "threw non-exception type"));
- failRead(ex);
- return;
- }
- if (buf == nullptr || buflen == 0) {
- AsyncSocketException ex(AsyncSocketException::INVALID_STATE,
- string("ReadCallback::getReadBuffer() "
- "returned empty buffer"));
- failRead(ex);
- return;
+ std::unique_ptr<IOBuf> ioBuf;
+
+ if (movable) {
+ ioBuf = IOBuf::create(readCallback_->maxBufferSize());
+ buf = ioBuf->writableBuffer();
+ buflen = ioBuf->capacity();
+ } else {
+ try {
+ readCallback_->getReadBuffer(&buf, &buflen);
+ } catch (const std::exception& ex) {
+ AsyncSocketException aex(
+ AsyncSocketException::BAD_ARGS,
+ string("ReadCallback::getReadBuffer() "
+ "threw exception: ") +
+ ex.what());
+ failRead(aex);
+ return;
+ } catch (...) {
+ AsyncSocketException aex(
+ AsyncSocketException::BAD_ARGS,
+ string("ReadCallback::getReadBuffer() "
+ "threw non-exception type"));
+ failRead(aex);
+ return;
+ }
+ if (buf == nullptr || buflen == 0) {
+ AsyncSocketException aex(
+ AsyncSocketException::INVALID_STATE,
+ string("ReadCallback::getReadBuffer() "
+ "returned empty buffer"));
+ failRead(aex);
+ return;
+ }