proxygen
ProxyFrontendHandler Class Reference
Inheritance diagram for ProxyFrontendHandler:
wangle::HandlerAdapter< R, W > wangle::Handler< R, R, W, W > wangle::HandlerBase< HandlerContext< R, W > >

Public Member Functions

 ProxyFrontendHandler (SocketAddress remoteAddress)
 
void read (Context *, IOBufQueue &q) override
 
void readEOF (Context *ctx) override
 
void readException (Context *ctx, exception_wrapper e) override
 
void transportActive (Context *ctx) override
 
- Public Member Functions inherited from wangle::HandlerAdapter< R, W >
void read (Context *ctx, R msg) override
 
folly::Future< folly::Unitwrite (Context *ctx, W msg) override
 
- Public Member Functions inherited from wangle::Handler< R, R, W, W >
 ~Handler () override=default
 
virtual void read (Context *ctx, Rmsg)=0
 
virtual void readEOF (Context *ctx)
 
virtual void readException (Context *ctx, folly::exception_wrapper e)
 
virtual void transportActive (Context *ctx)
 
virtual void transportInactive (Context *ctx)
 
virtual folly::Future< folly::Unitwrite (Context *ctx, Wmsg)=0
 
virtual folly::Future< folly::UnitwriteException (Context *ctx, folly::exception_wrapper e)
 
virtual folly::Future< folly::Unitclose (Context *ctx)
 
- Public Member Functions inherited from wangle::HandlerBase< HandlerContext< R, W > >
virtual ~HandlerBase ()=default
 
virtual void attachPipeline (HandlerContext< R, W > *)
 
virtual void detachPipeline (HandlerContext< R, W > *)
 
HandlerContext< R, W > * getContext ()
 

Private Attributes

SocketAddress remoteAddress_
 
ClientBootstrap< DefaultPipelineclient_
 
DefaultPipelinebackendPipeline_ {nullptr}
 
folly::IOBufQueue buffer_ {folly::IOBufQueue::cacheChainLength()}
 

Additional Inherited Members

- Public Types inherited from wangle::HandlerAdapter< R, W >
typedef Handler< R, R, W, W >::Context Context
 
- Public Types inherited from wangle::Handler< R, R, W, W >
typedef R rin
 
typedef R rout
 
typedef W win
 
typedef W wout
 
typedef HandlerContext< R, W > Context
 
- Static Public Attributes inherited from wangle::Handler< R, R, W, W >
static const HandlerDir dir
 

Detailed Description

Definition at line 72 of file Proxy.cpp.

Constructor & Destructor Documentation

ProxyFrontendHandler::ProxyFrontendHandler ( SocketAddress  remoteAddress)
inlineexplicit

Definition at line 74 of file Proxy.cpp.

74  :
75  remoteAddress_(remoteAddress) {}
SocketAddress remoteAddress_
Definition: Proxy.cpp:131

Member Function Documentation

void ProxyFrontendHandler::read ( Context ,
IOBufQueue q 
)
inlineoverride

Definition at line 77 of file Proxy.cpp.

References buffer_.

77  {
78  buffer_.append(q);
79  if (!backendPipeline_) {
80  return;
81  }
82 
84  }
folly::IOBufQueue buffer_
Definition: Proxy.cpp:134
void append(std::unique_ptr< folly::IOBuf > &&buf, bool pack=false)
Definition: IOBufQueue.cpp:143
std::unique_ptr< folly::IOBuf > move()
Definition: IOBufQueue.h:459
DefaultPipeline * backendPipeline_
Definition: Proxy.cpp:133
std::enable_if<!std::is_same< T, folly::Unit >::value, folly::Future< folly::Unit > >::type write(W msg)
Definition: Pipeline-inl.h:235
void ProxyFrontendHandler::readEOF ( Context ctx)
inlineoverride

Definition at line 86 of file Proxy.cpp.

References folly::netops::close(), and folly::INFO.

86  {
87  LOG(INFO) << "Connection closed by local host";
88  if (!backendPipeline_) {
89  return;
90  }
91  backendPipeline_->close().thenValue([this, ctx](auto&&){
92  this->close(ctx);
93  });
94  }
std::enable_if<!std::is_same< T, folly::Unit >::value, folly::Future< folly::Unit > >::type close()
Definition: Pipeline-inl.h:258
DefaultPipeline * backendPipeline_
Definition: Proxy.cpp:133
virtual folly::Future< folly::Unit > close(Context *ctx)
Definition: Handler.h:79
void ProxyFrontendHandler::readException ( Context ctx,
exception_wrapper  e 
)
inlineoverride

Definition at line 96 of file Proxy.cpp.

References folly::netops::close(), and folly::exceptionStr().

96  {
97  LOG(ERROR) << "Local error: " << exceptionStr(e);
98  if (!backendPipeline_) {
99  return;
100  }
101  backendPipeline_->close().thenValue([this, ctx](auto&&){
102  this->close(ctx);
103  });
104  }
std::enable_if<!std::is_same< T, folly::Unit >::value, folly::Future< folly::Unit > >::type close()
Definition: Pipeline-inl.h:258
fbstring exceptionStr(const std::exception &e)
DefaultPipeline * backendPipeline_
Definition: Proxy.cpp:133
virtual folly::Future< folly::Unit > close(Context *ctx)
Definition: Handler.h:79
void ProxyFrontendHandler::transportActive ( Context ctx)
inlineoverride

Definition at line 106 of file Proxy.cpp.

References folly::netops::close(), folly::exceptionStr(), wangle::Pipeline< R, W >::transportActive(), and wangle::Pipeline< R, W >::transportInactive().

106  {
107  if (backendPipeline_) {
108  // Already connected
109  return;
110  }
111 
112  // Pause reading from the socket until remote connection succeeds
113  auto frontendPipeline = dynamic_cast<DefaultPipeline*>(ctx->getPipeline());
114  frontendPipeline->transportInactive();
115 
117  std::make_shared<ProxyBackendPipelineFactory>(frontendPipeline));
119  .thenValue([this, frontendPipeline](DefaultPipeline* pipeline){
120  backendPipeline_ = pipeline;
121  // Resume read
122  frontendPipeline->transportActive();
123  })
124  .onError([this, ctx](const std::exception& e){
125  LOG(ERROR) << "Connect error: " << exceptionStr(e);
126  this->close(ctx);
127  });
128  }
std::enable_if<!std::is_same< T, folly::Unit >::value >::type transportInactive()
Definition: Pipeline-inl.h:214
fbstring exceptionStr(const std::exception &e)
folly::Future< Pipeline * > connect(const folly::SocketAddress &address, std::chrono::milliseconds timeout=std::chrono::milliseconds(0)) override
DefaultPipeline * backendPipeline_
Definition: Proxy.cpp:133
std::enable_if<!std::is_same< T, folly::Unit >::value >::type transportActive()
Definition: Pipeline-inl.h:205
BaseClientBootstrap< P > * pipelineFactory(std::shared_ptr< PipelineFactory< P >> factory) noexcept
virtual folly::Future< folly::Unit > close(Context *ctx)
Definition: Handler.h:79
ClientBootstrap< DefaultPipeline > client_
Definition: Proxy.cpp:132
SocketAddress remoteAddress_
Definition: Proxy.cpp:131

Member Data Documentation

DefaultPipeline* ProxyFrontendHandler::backendPipeline_ {nullptr}
private

Definition at line 133 of file Proxy.cpp.

folly::IOBufQueue ProxyFrontendHandler::buffer_ {folly::IOBufQueue::cacheChainLength()}
private

Definition at line 134 of file Proxy.cpp.

ClientBootstrap<DefaultPipeline> ProxyFrontendHandler::client_
private

Definition at line 132 of file Proxy.cpp.

SocketAddress ProxyFrontendHandler::remoteAddress_
private

Definition at line 131 of file Proxy.cpp.


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