use Unit in Pipeline
authorJames Sedgwick <jsedgwick@fb.com>
Tue, 16 Jun 2015 17:31:02 +0000 (10:31 -0700)
committerSara Golemon <sgolemon@fb.com>
Wed, 17 Jun 2015 17:26:16 +0000 (10:26 -0700)
Summary: Instead of the one-off Nothing struct

Reviewed By: @yfeldblum

Differential Revision: D2158621

folly/wangle/channel/Handler.h
folly/wangle/channel/Pipeline-inl.h
folly/wangle/channel/Pipeline.h

index 4228ca4292cd4ab142fc30b96cdc8c2090b7a52e..d0b9edde3424eaabe7f7670ce6699bf76603b4a2 100644 (file)
@@ -109,8 +109,8 @@ class InboundHandler : public HandlerBase<InboundHandlerContext<Rout>> {
 
   typedef Rin rin;
   typedef Rout rout;
-  typedef Nothing win;
-  typedef Nothing wout;
+  typedef Unit win;
+  typedef Unit wout;
   typedef InboundHandlerContext<Rout> Context;
   virtual ~InboundHandler() = default;
 
@@ -134,8 +134,8 @@ class OutboundHandler : public HandlerBase<OutboundHandlerContext<Wout>> {
  public:
   static const HandlerDir dir = HandlerDir::OUT;
 
-  typedef Nothing rin;
-  typedef Nothing rout;
+  typedef Unit rin;
+  typedef Unit rout;
   typedef Win win;
   typedef Wout wout;
   typedef OutboundHandlerContext<Wout> Context;
index dde1f39eda93360eaa42460c0c9709389aa9ee46..f4f7e000b9ee5a1a40cb385f677d9e29808bc440 100644 (file)
@@ -59,7 +59,7 @@ std::pair<uint64_t, uint64_t> Pipeline<R, W>::getReadBufferSettings() {
 
 template <class R, class W>
 template <class T>
-typename std::enable_if<!std::is_same<T, Nothing>::value>::type
+typename std::enable_if<!std::is_same<T, Unit>::value>::type
 Pipeline<R, W>::read(R msg) {
   if (!front_) {
     throw std::invalid_argument("read(): no inbound handler in Pipeline");
@@ -69,7 +69,7 @@ Pipeline<R, W>::read(R msg) {
 
 template <class R, class W>
 template <class T>
-typename std::enable_if<!std::is_same<T, Nothing>::value>::type
+typename std::enable_if<!std::is_same<T, Unit>::value>::type
 Pipeline<R, W>::readEOF() {
   if (!front_) {
     throw std::invalid_argument("readEOF(): no inbound handler in Pipeline");
@@ -79,7 +79,7 @@ Pipeline<R, W>::readEOF() {
 
 template <class R, class W>
 template <class T>
-typename std::enable_if<!std::is_same<T, Nothing>::value>::type
+typename std::enable_if<!std::is_same<T, Unit>::value>::type
 Pipeline<R, W>::transportActive() {
   if (front_) {
     front_->transportActive();
@@ -88,7 +88,7 @@ Pipeline<R, W>::transportActive() {
 
 template <class R, class W>
 template <class T>
-typename std::enable_if<!std::is_same<T, Nothing>::value>::type
+typename std::enable_if<!std::is_same<T, Unit>::value>::type
 Pipeline<R, W>::transportInactive() {
   if (front_) {
     front_->transportInactive();
@@ -97,7 +97,7 @@ Pipeline<R, W>::transportInactive() {
 
 template <class R, class W>
 template <class T>
-typename std::enable_if<!std::is_same<T, Nothing>::value>::type
+typename std::enable_if<!std::is_same<T, Unit>::value>::type
 Pipeline<R, W>::readException(exception_wrapper e) {
   if (!front_) {
     throw std::invalid_argument(
@@ -108,7 +108,7 @@ Pipeline<R, W>::readException(exception_wrapper e) {
 
 template <class R, class W>
 template <class T>
-typename std::enable_if<!std::is_same<T, Nothing>::value, Future<void>>::type
+typename std::enable_if<!std::is_same<T, Unit>::value, Future<void>>::type
 Pipeline<R, W>::write(W msg) {
   if (!back_) {
     throw std::invalid_argument("write(): no outbound handler in Pipeline");
@@ -118,7 +118,7 @@ Pipeline<R, W>::write(W msg) {
 
 template <class R, class W>
 template <class T>
-typename std::enable_if<!std::is_same<T, Nothing>::value, Future<void>>::type
+typename std::enable_if<!std::is_same<T, Unit>::value, Future<void>>::type
 Pipeline<R, W>::close() {
   if (!back_) {
     throw std::invalid_argument("close(): no outbound handler in Pipeline");
@@ -250,12 +250,12 @@ H* Pipeline<R, W>::getHandler(int i) {
 namespace detail {
 
 template <class T>
-inline void logWarningIfNotNothing(const std::string& warning) {
+inline void logWarningIfNotUnit(const std::string& warning) {
   LOG(WARNING) << warning;
 }
 
 template <>
-inline void logWarningIfNotNothing<Nothing>(const std::string& warning) {
+inline void logWarningIfNotUnit<Unit>(const std::string& warning) {
   // do nothing
 }
 
@@ -283,12 +283,12 @@ void Pipeline<R, W>::finalize() {
   }
 
   if (!front_) {
-    detail::logWarningIfNotNothing<R>(
+    detail::logWarningIfNotUnit<R>(
         "No inbound handler in Pipeline, inbound operations will throw "
         "std::invalid_argument");
   }
   if (!back_) {
-    detail::logWarningIfNotNothing<W>(
+    detail::logWarningIfNotUnit<W>(
         "No outbound handler in Pipeline, outbound operations will throw "
         "std::invalid_argument");
   }
index 7138ab1c10728759ce80d6a9f70960fbe201cea9..85d89d894fa72a0e0ebae47af234489a8bbacf99 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <folly/wangle/channel/HandlerContext.h>
 #include <folly/futures/Future.h>
+#include <folly/futures/Unit.h>
 #include <folly/io/async/AsyncTransport.h>
 #include <folly/io/async/DelayedDestruction.h>
 #include <folly/ExceptionWrapper.h>
@@ -58,17 +59,15 @@ class PipelineBase : public DelayedDestruction {
   std::shared_ptr<AsyncTransport> transport_;
 };
 
-struct Nothing{};
-
 /*
  * R is the inbound type, i.e. inbound calls start with pipeline.read(R)
  * W is the outbound type, i.e. outbound calls start with pipeline.write(W)
  *
- * Use Nothing for one of the types if your pipeline is unidirectional.
- * If R is Nothing, read(), readEOF(), and readException() will be disabled.
- * If W is Nothing, write() and close() will be disabled.
+ * Use Unit for one of the types if your pipeline is unidirectional.
+ * If R is Unit, read(), readEOF(), and readException() will be disabled.
+ * If W is Unit, write() and close() will be disabled.
  */
-template <class R, class W = Nothing>
+template <class R, class W = Unit>
 class Pipeline : public PipelineBase {
  public:
   Pipeline();
@@ -81,31 +80,31 @@ class Pipeline : public PipelineBase {
   std::pair<uint64_t, uint64_t> getReadBufferSettings();
 
   template <class T = R>
-  typename std::enable_if<!std::is_same<T, Nothing>::value>::type
+  typename std::enable_if<!std::is_same<T, Unit>::value>::type
   read(R msg);
 
   template <class T = R>
-  typename std::enable_if<!std::is_same<T, Nothing>::value>::type
+  typename std::enable_if<!std::is_same<T, Unit>::value>::type
   readEOF();
 
   template <class T = R>
-  typename std::enable_if<!std::is_same<T, Nothing>::value>::type
+  typename std::enable_if<!std::is_same<T, Unit>::value>::type
   readException(exception_wrapper e);
 
   template <class T = R>
-  typename std::enable_if<!std::is_same<T, Nothing>::value>::type
+  typename std::enable_if<!std::is_same<T, Unit>::value>::type
   transportActive();
 
   template <class T = R>
-  typename std::enable_if<!std::is_same<T, Nothing>::value>::type
+  typename std::enable_if<!std::is_same<T, Unit>::value>::type
   transportInactive();
 
   template <class T = W>
-  typename std::enable_if<!std::is_same<T, Nothing>::value, Future<void>>::type
+  typename std::enable_if<!std::is_same<T, Unit>::value, Future<void>>::type
   write(W msg);
 
   template <class T = W>
-  typename std::enable_if<!std::is_same<T, Nothing>::value, Future<void>>::type
+  typename std::enable_if<!std::is_same<T, Unit>::value, Future<void>>::type
   close();
 
   template <class H>