AsyncSocket::writeRequest() and its first user wangle::FileRegion
[folly.git] / folly / wangle / channel / HandlerContext-inl.h
index 49f2517f1eeaedea94fdd9ffb54adfa1f3f744f5..9a220bcd3e8b8b847df4c9cf1f970418bd5311ec 100644 (file)
@@ -25,9 +25,6 @@ class PipelineContext {
   virtual void attachPipeline() = 0;
   virtual void detachPipeline() = 0;
 
-  virtual void attachTransport() = 0;
-  virtual void detachTransport() = 0;
-
   template <class H, class HandlerContext>
   void attachContext(H* handler, HandlerContext* ctx) {
     if (++handler->attachCount_ == 1) {
@@ -48,6 +45,8 @@ class InboundLink {
   virtual void read(In msg) = 0;
   virtual void readEOF() = 0;
   virtual void readException(exception_wrapper e) = 0;
+  virtual void transportActive() = 0;
+  virtual void transportInactive() = 0;
 };
 
 template <class Out>
@@ -86,16 +85,6 @@ class ContextImplBase : public PipelineContext {
     attached_ = false;
   }
 
-  void attachTransport() override {
-    DestructorGuard dg(pipeline_);
-    handler_->attachTransport(impl_);
-  }
-
-  void detachTransport() override {
-    DestructorGuard dg(pipeline_);
-    handler_->detachTransport(impl_);
-  }
-
   void setNextIn(PipelineContext* ctx) override {
     auto nextIn = dynamic_cast<InboundLink<typename H::rout>*>(ctx);
     if (nextIn) {
@@ -181,6 +170,20 @@ class ContextImpl
     }
   }
 
+  void fireTransportActive() override {
+    DestructorGuard dg(this->pipeline_);
+    if (this->nextIn_) {
+      this->nextIn_->transportActive();
+    }
+  }
+
+  void fireTransportInactive() override {
+    DestructorGuard dg(this->pipeline_);
+    if (this->nextIn_) {
+      this->nextIn_->transportInactive();
+    }
+  }
+
   Future<void> fireWrite(Wout msg) override {
     DestructorGuard dg(this->pipeline_);
     if (this->nextOut_) {
@@ -205,10 +208,6 @@ class ContextImpl
     return this->pipeline_;
   }
 
-  std::shared_ptr<AsyncTransport> getTransport() override {
-    return this->pipeline_->getTransport();
-  }
-
   void setWriteFlags(WriteFlags flags) override {
     this->pipeline_->setWriteFlags(flags);
   }
@@ -243,6 +242,16 @@ class ContextImpl
     this->handler_->readException(this, std::move(e));
   }
 
+  void transportActive() override {
+    DestructorGuard dg(this->pipeline_);
+    this->handler_->transportActive(this);
+  }
+
+  void transportInactive() override {
+    DestructorGuard dg(this->pipeline_);
+    this->handler_->transportInactive(this);
+  }
+
   // OutboundLink overrides
   Future<void> write(Win msg) override {
     DestructorGuard dg(this->pipeline_);
@@ -310,12 +319,22 @@ class InboundContextImpl
     }
   }
 
-  PipelineBase* getPipeline() override {
-    return this->pipeline_;
+  void fireTransportActive() override {
+    DestructorGuard dg(this->pipeline_);
+    if (this->nextIn_) {
+      this->nextIn_->transportActive();
+    }
   }
 
-  std::shared_ptr<AsyncTransport> getTransport() override {
-    return this->pipeline_->getTransport();
+  void fireTransportInactive() override {
+    DestructorGuard dg(this->pipeline_);
+    if (this->nextIn_) {
+      this->nextIn_->transportInactive();
+    }
+  }
+
+  PipelineBase* getPipeline() override {
+    return this->pipeline_;
   }
 
   // InboundLink overrides
@@ -334,6 +353,16 @@ class InboundContextImpl
     this->handler_->readException(this, std::move(e));
   }
 
+  void transportActive() override {
+    DestructorGuard dg(this->pipeline_);
+    this->handler_->transportActive(this);
+  }
+
+  void transportInactive() override {
+    DestructorGuard dg(this->pipeline_);
+    this->handler_->transportInactive(this);
+  }
+
  private:
   using DestructorGuard = typename P::DestructorGuard;
 };
@@ -387,10 +416,6 @@ class OutboundContextImpl
     return this->pipeline_;
   }
 
-  std::shared_ptr<AsyncTransport> getTransport() override {
-    return this->pipeline_->getTransport();
-  }
-
   // OutboundLink overrides
   Future<void> write(Win msg) override {
     DestructorGuard dg(this->pipeline_);