proxygen
wangle::OutputBufferingHandler Class Reference

#include <OutputBufferingHandler.h>

Inheritance diagram for wangle::OutputBufferingHandler:
wangle::OutboundHandler< Win, Wout > folly::EventBase::LoopCallback wangle::HandlerBase< OutboundHandlerContext< Wout > >

Public Member Functions

folly::Future< folly::Unitwrite (Context *ctx, std::unique_ptr< folly::IOBuf > buf) override
 
void runLoopCallback () noexceptoverride
 
void cleanUp ()
 
folly::Future< folly::Unitclose (Context *ctx) override
 
- Public Member Functions inherited from wangle::OutboundHandler< Win, Wout >
 ~OutboundHandler () override=default
 
virtual folly::Future< folly::Unitwrite (Context *ctx, Win msg)=0
 
virtual folly::Future< folly::UnitwriteException (Context *ctx, folly::exception_wrapper e)
 
- Public Member Functions inherited from wangle::HandlerBase< OutboundHandlerContext< Wout > >
virtual ~HandlerBase ()=default
 
virtual void attachPipeline (OutboundHandlerContext< Wout > *)
 
virtual void detachPipeline (OutboundHandlerContext< Wout > *)
 
OutboundHandlerContext< Wout > * getContext ()
 

Public Attributes

folly::SharedPromise< folly::UnitsharedPromise_
 
std::unique_ptr< folly::IOBufsends_ {nullptr}
 
bool queueSends_ {true}
 

Additional Inherited Members

- Public Types inherited from wangle::OutboundHandler< Win, Wout >
typedef folly::Unit rin
 
typedef folly::Unit rout
 
typedef Win win
 
typedef Wout wout
 
typedef OutboundHandlerContext< Wout > Context
 
- Static Public Attributes inherited from wangle::OutboundHandler< Win, Wout >
static const HandlerDir dir = HandlerDir::OUT
 
- Protected Member Functions inherited from folly::EventBase::LoopCallback
virtual ~LoopCallback ()=default
 
void cancelLoopCallback ()
 
bool isLoopCallbackScheduled () const
 

Detailed Description

Definition at line 34 of file OutputBufferingHandler.h.

Member Function Documentation

void wangle::OutputBufferingHandler::cleanUp ( )
inline
folly::Future<folly::Unit> wangle::OutputBufferingHandler::close ( Context ctx)
inlineoverridevirtual

Reimplemented from wangle::OutboundHandler< Win, Wout >.

Definition at line 78 of file OutputBufferingHandler.h.

References folly::EventBase::LoopCallback::cancelLoopCallback(), wangle::OutboundHandlerContext< Out >::fireClose(), folly::EventBase::LoopCallback::isLoopCallbackScheduled(), sends_, folly::SharedPromise< T >::setException(), and sharedPromise_.

78  {
81  }
82 
83  // If there are sends queued, cancel them
85  folly::make_exception_wrapper<std::runtime_error>(
86  "close() called while sends still pending"));
87  sends_.reset();
89  return ctx->fireClose();
90  }
std::unique_ptr< folly::IOBuf > sends_
void setException(exception_wrapper ew)
bool isLoopCallbackScheduled() const
Definition: EventBase.h:160
folly::SharedPromise< folly::Unit > sharedPromise_
void wangle::OutputBufferingHandler::runLoopCallback ( )
inlineoverridevirtualnoexcept

Implements folly::EventBase::LoopCallback.

Definition at line 58 of file OutputBufferingHandler.h.

References wangle::OutboundHandlerContext< Out >::fireWrite(), wangle::HandlerBase< OutboundHandlerContext< Wout > >::getContext(), folly::gen::move, sends_, folly::SharedPromise< T >::setTry(), sharedPromise_, folly::f14::swap(), and folly::pushmi::detail::t.

58  {
60  std::swap(sharedPromise, sharedPromise_);
61  getContext()
63  .thenTry([sharedPromise = std::move(sharedPromise)](
64  folly::Try<folly::Unit> t) mutable {
65  sharedPromise.setTry(std::move(t));
66  });
67  }
virtual folly::Future< folly::Unit > fireWrite(Out msg)=0
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::unique_ptr< folly::IOBuf > sends_
void setTry(Try< T > &&t)
OutboundHandlerContext< Wout > * getContext()
Definition: Handler.h:34
folly::SharedPromise< folly::Unit > sharedPromise_
void swap(SwapTrackingAlloc< T > &, SwapTrackingAlloc< T > &)
Definition: F14TestUtil.h:414
folly::Future<folly::Unit> wangle::OutputBufferingHandler::write ( Context ctx,
std::unique_ptr< folly::IOBuf buf 
)
inlineoverride

Definition at line 37 of file OutputBufferingHandler.h.

References wangle::OutboundHandlerContext< Out >::fireWrite(), folly::SharedPromise< T >::getFuture(), wangle::OutboundHandlerContext< Out >::getTransport(), folly::EventBase::LoopCallback::isLoopCallbackScheduled(), folly::gen::move, queueSends_, sends_, and sharedPromise_.

39  {
40  CHECK(buf);
41  if (!queueSends_) {
42  return ctx->fireWrite(std::move(buf));
43  } else {
44  // Delay sends to optimize for fewer syscalls
45  if (!sends_) {
46  DCHECK(!isLoopCallbackScheduled());
47  // Buffer all the sends, and call writev once per event loop.
48  sends_ = std::move(buf);
49  ctx->getTransport()->getEventBase()->runInLoop(this);
50  } else {
51  DCHECK(isLoopCallbackScheduled());
52  sends_->prependChain(std::move(buf));
53  }
54  return sharedPromise_.getFuture();
55  }
56  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::unique_ptr< folly::IOBuf > sends_
bool isLoopCallbackScheduled() const
Definition: EventBase.h:160
folly::SharedPromise< folly::Unit > sharedPromise_

Member Data Documentation

bool wangle::OutputBufferingHandler::queueSends_ {true}

Definition at line 94 of file OutputBufferingHandler.h.

Referenced by write().

std::unique_ptr<folly::IOBuf> wangle::OutputBufferingHandler::sends_ {nullptr}

Definition at line 93 of file OutputBufferingHandler.h.

Referenced by cleanUp(), close(), runLoopCallback(), and write().

folly::SharedPromise<folly::Unit> wangle::OutputBufferingHandler::sharedPromise_

Definition at line 92 of file OutputBufferingHandler.h.

Referenced by cleanUp(), close(), runLoopCallback(), and write().


The documentation for this class was generated from the following file: