Pipeline OutputBufferingHandler
authorDave Watson <davejwatson@fb.com>
Wed, 8 Apr 2015 20:54:59 +0000 (13:54 -0700)
committerViswanath Sivakumar <viswanath@fb.com>
Fri, 10 Apr 2015 03:35:11 +0000 (20:35 -0700)
Summary: Part 2 of pipeline.  Use OutputBufferingHandler, which is exactly the same output buffering thrift does currently.

Test Plan:
A couple canaries, unittests.
Specific issues of previous pipeline diffs I think are fixed already and should be fine with this one:
* Previously there were missing DestructorGuards.  I don't think anything in OutputBUfferHandler needs a DG
* previously broke http GET handling.  There is a unittest for it now.

Canary

Reviewed By: alandau@fb.com

Subscribers: doug, fugalh, alandau, bmatheny, mshneer, folly-diffs@, jsedgwick, yfeldblum, chalfant, vloh, andreib

FB internal diff: D1970949

Signature: t1:1970949:1428360621:a0db142032894525f69c2b144cf946d63f790fe1

folly/wangle/channel/OutputBufferingHandler.h

index f9a4306e015591866fb77ab335b2a7b65fbe8562..a1165ca1286f322e16d0ab2b0ed026a72f3285a3 100644 (file)
@@ -63,6 +63,22 @@ class OutputBufferingHandler : public BytesToBytesHandler,
     });
   }
 
+  Future<void> close(Context* ctx) override {
+    if (isLoopCallbackScheduled()) {
+      cancelLoopCallback();
+    }
+
+    // If there are sends queued, cancel them
+    for (auto& promise : promises_) {
+      promise.setException(
+        folly::make_exception_wrapper<std::runtime_error>(
+          "close() called while sends still pending"));
+    }
+    sends_.reset();
+    promises_.clear();
+    return ctx->fireClose();
+  }
+
   std::vector<Promise<void>> promises_;
   std::unique_ptr<IOBuf> sends_{nullptr};
   bool queueSends_{true};