From 3444ffba56927ac7e682dafd92ccc37a0f50c8ad Mon Sep 17 00:00:00 2001 From: James Sedgwick Date: Mon, 27 Apr 2015 11:19:18 -0700 Subject: [PATCH] strip Channel from all class names Summary: as above. Only got a little messy when components within folly::wangle typedefed things to Pipeline Test Plan: unit tests Reviewed By: davejwatson@fb.com Subscribers: wormhole-diffs@, fugalh, alandau, bmatheny, folly-diffs@, jsedgwick, yfeldblum, chalfant FB internal diff: D2022181 Tasks: 6836580 Signature: t1:2022181:1430157032:df0bdfb9ca0d76b86d52c55c4ad41ea953a18cb4 --- folly/Makefile.am | 6 +- folly/wangle/bootstrap/BootstrapTest.cpp | 30 +++--- folly/wangle/bootstrap/ClientBootstrap.h | 4 +- folly/wangle/bootstrap/ServerBootstrap-inl.h | 22 ++--- folly/wangle/bootstrap/ServerBootstrap.cpp | 2 +- folly/wangle/bootstrap/ServerBootstrap.h | 8 +- folly/wangle/channel/AsyncSocketHandler.h | 2 +- .../channel/{ChannelHandler.h => Handler.h} | 78 +++++++-------- ...annelHandlerContext.h => HandlerContext.h} | 32 +++--- folly/wangle/channel/OutputBufferingHandler.h | 2 +- .../channel/{ChannelPipeline.h => Pipeline.h} | 98 +++++++++---------- .../{MockChannelHandler.h => MockHandler.h} | 12 +-- .../test/OutputBufferingHandlerTest.cpp | 14 +-- ...annelPipelineTest.cpp => PipelineTest.cpp} | 58 +++++------ folly/wangle/codec/ByteToMessageCodec.h | 4 +- folly/wangle/codec/CodecTest.cpp | 36 +++---- folly/wangle/codec/StringCodec.h | 8 +- folly/wangle/service/ClientDispatcher.h | 8 +- folly/wangle/service/ServerDispatcher.h | 6 +- folly/wangle/service/Service.h | 2 +- folly/wangle/service/ServiceTest.cpp | 20 ++-- 21 files changed, 226 insertions(+), 226 deletions(-) rename folly/wangle/channel/{ChannelHandler.h => Handler.h} (63%) rename folly/wangle/channel/{ChannelHandlerContext.h => HandlerContext.h} (88%) rename folly/wangle/channel/{ChannelPipeline.h => Pipeline.h} (70%) rename folly/wangle/channel/test/{MockChannelHandler.h => MockHandler.h} (83%) rename folly/wangle/channel/test/{ChannelPipelineTest.cpp => PipelineTest.cpp} (79%) diff --git a/folly/Makefile.am b/folly/Makefile.am index 0cfbed97..adba4d1e 100644 --- a/folly/Makefile.am +++ b/folly/Makefile.am @@ -273,10 +273,10 @@ nobase_follyinclude_HEADERS = \ wangle/bootstrap/ServerSocketFactory.h \ wangle/bootstrap/ClientBootstrap.h \ wangle/channel/AsyncSocketHandler.h \ - wangle/channel/ChannelHandler.h \ - wangle/channel/ChannelHandlerContext.h \ - wangle/channel/ChannelPipeline.h \ + wangle/channel/Handler.h \ + wangle/channel/HandlerContext.h \ wangle/channel/OutputBufferingHandler.h \ + wangle/channel/Pipeline.h \ wangle/concurrent/BlockingQueue.h \ wangle/concurrent/Codel.h \ wangle/concurrent/CPUThreadPoolExecutor.h \ diff --git a/folly/wangle/bootstrap/BootstrapTest.cpp b/folly/wangle/bootstrap/BootstrapTest.cpp index d0ee7e2a..9087be57 100644 --- a/folly/wangle/bootstrap/BootstrapTest.cpp +++ b/folly/wangle/bootstrap/BootstrapTest.cpp @@ -16,7 +16,7 @@ #include "folly/wangle/bootstrap/ServerBootstrap.h" #include "folly/wangle/bootstrap/ClientBootstrap.h" -#include "folly/wangle/channel/ChannelHandler.h" +#include "folly/wangle/channel/Handler.h" #include #include @@ -25,14 +25,14 @@ using namespace folly::wangle; using namespace folly; -typedef ChannelPipeline> Pipeline; +typedef Pipeline> BytesPipeline; -typedef ServerBootstrap TestServer; -typedef ClientBootstrap TestClient; +typedef ServerBootstrap TestServer; +typedef ClientBootstrap TestClient; -class TestClientPipelineFactory : public PipelineFactory { +class TestClientPipelineFactory : public PipelineFactory { public: - Pipeline* newPipeline(std::shared_ptr sock) { + BytesPipeline* newPipeline(std::shared_ptr sock) { CHECK(sock->good()); // We probably aren't connected immedately, check after a small delay @@ -43,11 +43,11 @@ class TestClientPipelineFactory : public PipelineFactory { } }; -class TestPipelineFactory : public PipelineFactory { +class TestPipelineFactory : public PipelineFactory { public: - Pipeline* newPipeline(std::shared_ptr sock) { + BytesPipeline* newPipeline(std::shared_ptr sock) { pipelines++; - return new Pipeline(); + return new BytesPipeline(); } std::atomic pipelines{0}; }; @@ -268,7 +268,7 @@ TEST(Bootstrap, ExistingSocket) { std::atomic connections{0}; class TestHandlerPipeline - : public ChannelHandlerAdapter { public: void read(Context* ctx, void* conn) { @@ -283,12 +283,12 @@ class TestHandlerPipeline template class TestHandlerPipelineFactory - : public PipelineFactory::AcceptPipeline> { + : public PipelineFactory::AcceptPipeline> { public: - ServerBootstrap::AcceptPipeline* newPipeline(std::shared_ptr) { - auto pipeline = new ServerBootstrap::AcceptPipeline; + ServerBootstrap::AcceptPipeline* newPipeline(std::shared_ptr) { + auto pipeline = new ServerBootstrap::AcceptPipeline; auto handler = std::make_shared(); - pipeline->addBack(ChannelHandlerPtr(handler)); + pipeline->addBack(HandlerPtr(handler)); return pipeline; } }; @@ -318,7 +318,7 @@ TEST(Bootstrap, LoadBalanceHandler) { } class TestUDPPipeline - : public ChannelHandlerAdapter { public: void read(Context* ctx, void* conn) { diff --git a/folly/wangle/bootstrap/ClientBootstrap.h b/folly/wangle/bootstrap/ClientBootstrap.h index 37179fda..2b3f3be2 100644 --- a/folly/wangle/bootstrap/ClientBootstrap.h +++ b/folly/wangle/bootstrap/ClientBootstrap.h @@ -15,12 +15,12 @@ */ #pragma once -#include +#include namespace folly { /* - * A thin wrapper around ChannelPipeline and AsyncSocket to match + * A thin wrapper around Pipeline and AsyncSocket to match * ServerBootstrap. On connect() a new pipeline is created. */ template diff --git a/folly/wangle/bootstrap/ServerBootstrap-inl.h b/folly/wangle/bootstrap/ServerBootstrap-inl.h index e1909265..1e0ebc75 100644 --- a/folly/wangle/bootstrap/ServerBootstrap-inl.h +++ b/folly/wangle/bootstrap/ServerBootstrap-inl.h @@ -20,15 +20,15 @@ #include #include #include -#include -#include +#include +#include namespace folly { template class ServerAcceptor : public Acceptor - , public folly::wangle::ChannelHandlerAdapter { + , public folly::wangle::HandlerAdapter { typedef std::unique_ptr PipelinePtr; @@ -60,7 +60,7 @@ class ServerAcceptor public: explicit ServerAcceptor( std::shared_ptr> pipelineFactory, - std::shared_ptr> acceptorPipeline, EventBase* base) : Acceptor(ServerSocketConfig()) @@ -70,7 +70,7 @@ class ServerAcceptor Acceptor::init(nullptr, base_); CHECK(acceptorPipeline_); - acceptorPipeline_->addBack(folly::wangle::ChannelHandlerPtr(this)); + acceptorPipeline_->addBack(folly::wangle::HandlerPtr(this)); acceptorPipeline_->finalize(); } @@ -109,7 +109,7 @@ class ServerAcceptor EventBase* base_; std::shared_ptr> childPipelineFactory_; - std::shared_ptr> acceptorPipeline_; }; @@ -118,13 +118,13 @@ class ServerAcceptorFactory : public AcceptorFactory { public: explicit ServerAcceptorFactory( std::shared_ptr> factory, - std::shared_ptr>> pipeline) : factory_(factory) , pipeline_(pipeline) {} std::shared_ptr newAcceptor(EventBase* base) { - std::shared_ptr> pipeline( pipeline_->newPipeline(nullptr)); return std::make_shared>(factory_, pipeline, base); @@ -132,7 +132,7 @@ class ServerAcceptorFactory : public AcceptorFactory { private: std::shared_ptr> factory_; std::shared_ptr>> pipeline_; }; @@ -183,8 +183,8 @@ void ServerWorkerPool::forEachWorker(F&& f) const { } class DefaultAcceptPipelineFactory - : public PipelineFactory> { - typedef wangle::ChannelPipeline< + : public PipelineFactory> { + typedef wangle::Pipeline< void*, std::exception> AcceptPipeline; diff --git a/folly/wangle/bootstrap/ServerBootstrap.cpp b/folly/wangle/bootstrap/ServerBootstrap.cpp index e59ed657..6b7a4101 100644 --- a/folly/wangle/bootstrap/ServerBootstrap.cpp +++ b/folly/wangle/bootstrap/ServerBootstrap.cpp @@ -15,7 +15,7 @@ */ #include #include -#include +#include #include namespace folly { diff --git a/folly/wangle/bootstrap/ServerBootstrap.h b/folly/wangle/bootstrap/ServerBootstrap.h index 3520b0f5..28785a1b 100644 --- a/folly/wangle/bootstrap/ServerBootstrap.h +++ b/folly/wangle/bootstrap/ServerBootstrap.h @@ -17,11 +17,11 @@ #include #include -#include +#include namespace folly { -typedef folly::wangle::ChannelPipeline< +typedef folly::wangle::Pipeline< folly::IOBufQueue&, std::unique_ptr> DefaultPipeline; /* @@ -30,7 +30,7 @@ typedef folly::wangle::ChannelPipeline< * accepting threads, any number of accepting sockets, a pool of * IO-worker threads, and connection pool for each IO thread for you. * - * The output is given as a ChannelPipeline template: given a + * The output is given as a Pipeline template: given a * PipelineFactory, it will create a new pipeline for each connection, * and your server can handle the incoming bytes. * @@ -52,7 +52,7 @@ class ServerBootstrap { join(); } - typedef wangle::ChannelPipeline< + typedef wangle::Pipeline< void*, std::exception> AcceptPipeline; /* diff --git a/folly/wangle/channel/AsyncSocketHandler.h b/folly/wangle/channel/AsyncSocketHandler.h index b5be966f..014812b8 100644 --- a/folly/wangle/channel/AsyncSocketHandler.h +++ b/folly/wangle/channel/AsyncSocketHandler.h @@ -16,7 +16,7 @@ #pragma once -#include +#include #include #include #include diff --git a/folly/wangle/channel/ChannelHandler.h b/folly/wangle/channel/Handler.h similarity index 63% rename from folly/wangle/channel/ChannelHandler.h rename to folly/wangle/channel/Handler.h index e1aa6d5e..67219f17 100644 --- a/folly/wangle/channel/ChannelHandler.h +++ b/folly/wangle/channel/Handler.h @@ -17,21 +17,21 @@ #pragma once #include -#include +#include #include #include namespace folly { namespace wangle { template -class ChannelHandler { +class Handler { public: typedef Rin rin; typedef Rout rout; typedef Win win; typedef Wout wout; - typedef ChannelHandlerContext Context; - virtual ~ChannelHandler() {} + typedef HandlerContext Context; + virtual ~Handler() {} virtual void read(Context* ctx, Rin msg) = 0; virtual void readEOF(Context* ctx) { @@ -56,34 +56,34 @@ class ChannelHandler { // Other sorts of things we might want, all shamelessly stolen from Netty // inbound virtual void exceptionCaught( - ChannelHandlerContext* ctx, + HandlerContext* ctx, exception_wrapper e) {} - virtual void channelRegistered(ChannelHandlerContext* ctx) {} - virtual void channelUnregistered(ChannelHandlerContext* ctx) {} - virtual void channelActive(ChannelHandlerContext* ctx) {} - virtual void channelInactive(ChannelHandlerContext* ctx) {} - virtual void channelReadComplete(ChannelHandlerContext* ctx) {} - virtual void userEventTriggered(ChannelHandlerContext* ctx, void* evt) {} - virtual void channelWritabilityChanged(ChannelHandlerContext* ctx) {} + virtual void channelRegistered(HandlerContext* ctx) {} + virtual void channelUnregistered(HandlerContext* ctx) {} + virtual void channelActive(HandlerContext* ctx) {} + virtual void channelInactive(HandlerContext* ctx) {} + virtual void channelReadComplete(HandlerContext* ctx) {} + virtual void userEventTriggered(HandlerContext* ctx, void* evt) {} + virtual void channelWritabilityChanged(HandlerContext* ctx) {} // outbound virtual Future bind( - ChannelHandlerContext* ctx, + HandlerContext* ctx, SocketAddress localAddress) {} virtual Future connect( - ChannelHandlerContext* ctx, + HandlerContext* ctx, SocketAddress remoteAddress, SocketAddress localAddress) {} - virtual Future disconnect(ChannelHandlerContext* ctx) {} - virtual Future deregister(ChannelHandlerContext* ctx) {} - virtual Future read(ChannelHandlerContext* ctx) {} - virtual void flush(ChannelHandlerContext* ctx) {} + virtual Future disconnect(HandlerContext* ctx) {} + virtual Future deregister(HandlerContext* ctx) {} + virtual Future read(HandlerContext* ctx) {} + virtual void flush(HandlerContext* ctx) {} */ }; template -class ChannelHandlerAdapter : public ChannelHandler { +class HandlerAdapter : public Handler { public: - typedef typename ChannelHandler::Context Context; + typedef typename Handler::Context Context; void read(Context* ctx, R msg) override { ctx->fireRead(std::forward(msg)); @@ -94,32 +94,32 @@ class ChannelHandlerAdapter : public ChannelHandler { } }; -typedef ChannelHandlerAdapter> +typedef HandlerAdapter> BytesToBytesHandler; -template -class ChannelHandlerPtr : public ChannelHandler< - typename Handler::rin, - typename Handler::rout, - typename Handler::win, - typename Handler::wout> { +template +class HandlerPtr : public Handler< + typename HandlerT::rin, + typename HandlerT::rout, + typename HandlerT::win, + typename HandlerT::wout> { public: typedef typename std::conditional< Shared, - std::shared_ptr, - Handler*>::type - HandlerPtr; + std::shared_ptr, + HandlerT*>::type + Ptr; - typedef typename Handler::Context Context; + typedef typename HandlerT::Context Context; - explicit ChannelHandlerPtr(HandlerPtr handler) + explicit HandlerPtr(Ptr handler) : handler_(std::move(handler)) {} - HandlerPtr getHandler() { + Ptr getHandler() { return handler_; } - void setHandler(HandlerPtr handler) { + void setHandler(Ptr handler) { if (handler == handler_) { return; } @@ -163,9 +163,9 @@ class ChannelHandlerPtr : public ChannelHandler< } } - void read(Context* ctx, typename Handler::rin msg) override { + void read(Context* ctx, typename HandlerT::rin msg) override { DCHECK(handler_); - handler_->read(ctx, std::forward(msg)); + handler_->read(ctx, std::forward(msg)); } void readEOF(Context* ctx) override { @@ -178,9 +178,9 @@ class ChannelHandlerPtr : public ChannelHandler< handler_->readException(ctx, std::move(e)); } - Future write(Context* ctx, typename Handler::win msg) override { + Future write(Context* ctx, typename HandlerT::win msg) override { DCHECK(handler_); - return handler_->write(ctx, std::forward(msg)); + return handler_->write(ctx, std::forward(msg)); } Future close(Context* ctx) override { @@ -190,7 +190,7 @@ class ChannelHandlerPtr : public ChannelHandler< private: Context* ctx_; - HandlerPtr handler_; + Ptr handler_; }; }} diff --git a/folly/wangle/channel/ChannelHandlerContext.h b/folly/wangle/channel/HandlerContext.h similarity index 88% rename from folly/wangle/channel/ChannelHandlerContext.h rename to folly/wangle/channel/HandlerContext.h index 0cb0fceb..809f2b1a 100644 --- a/folly/wangle/channel/ChannelHandlerContext.h +++ b/folly/wangle/channel/HandlerContext.h @@ -23,9 +23,9 @@ namespace folly { namespace wangle { template -class ChannelHandlerContext { +class HandlerContext { public: - virtual ~ChannelHandlerContext() {} + virtual ~HandlerContext() {} virtual void fireRead(In msg) = 0; virtual void fireReadEOF() = 0; @@ -73,27 +73,27 @@ class PipelineContext { }; template -class InboundChannelHandlerContext { +class InboundHandlerContext { public: - virtual ~InboundChannelHandlerContext() {} + virtual ~InboundHandlerContext() {} virtual void read(In msg) = 0; virtual void readEOF() = 0; virtual void readException(exception_wrapper e) = 0; }; template -class OutboundChannelHandlerContext { +class OutboundHandlerContext { public: - virtual ~OutboundChannelHandlerContext() {} + virtual ~OutboundHandlerContext() {} virtual Future write(Out msg) = 0; virtual Future close() = 0; }; template -class ContextImpl : public ChannelHandlerContext, - public InboundChannelHandlerContext, - public OutboundChannelHandlerContext, + public InboundHandlerContext, + public OutboundHandlerContext, public PipelineContext { public: typedef typename H::rin Rin; @@ -118,7 +118,7 @@ class ContextImpl : public ChannelHandlerContext*>(ctx); + auto nextIn = dynamic_cast*>(ctx); if (nextIn) { nextIn_ = nextIn; } else { @@ -127,7 +127,7 @@ class ContextImpl : public ChannelHandlerContext*>(ctx); + auto nextOut = dynamic_cast*>(ctx); if (nextOut) { nextOut_ = nextOut; } else { @@ -145,7 +145,7 @@ class ContextImpl : public ChannelHandlerContext(pipeline_)); if (nextIn_) { @@ -215,7 +215,7 @@ class ContextImpl : public ChannelHandlerContextgetReadBufferSettings(); } - // InboundChannelHandlerContext overrides + // InboundHandlerContext overrides void read(Rin msg) override { typename P::DestructorGuard dg(static_cast(pipeline_)); handler_.read(this, std::forward(msg)); @@ -231,7 +231,7 @@ class ContextImpl : public ChannelHandlerContext write(Win msg) override { typename P::DestructorGuard dg(static_cast(pipeline_)); return handler_.write(this, std::forward(msg)); @@ -245,8 +245,8 @@ class ContextImpl : public ChannelHandlerContext* nextIn_{nullptr}; - OutboundChannelHandlerContext* nextOut_{nullptr}; + InboundHandlerContext* nextIn_{nullptr}; + OutboundHandlerContext* nextOut_{nullptr}; }; }} diff --git a/folly/wangle/channel/OutputBufferingHandler.h b/folly/wangle/channel/OutputBufferingHandler.h index e5ca99ae..73fc0666 100644 --- a/folly/wangle/channel/OutputBufferingHandler.h +++ b/folly/wangle/channel/OutputBufferingHandler.h @@ -16,7 +16,7 @@ #pragma once -#include +#include #include #include #include diff --git a/folly/wangle/channel/ChannelPipeline.h b/folly/wangle/channel/Pipeline.h similarity index 70% rename from folly/wangle/channel/ChannelPipeline.h rename to folly/wangle/channel/Pipeline.h index f7918370..7d4fd2a6 100644 --- a/folly/wangle/channel/ChannelPipeline.h +++ b/folly/wangle/channel/Pipeline.h @@ -16,7 +16,7 @@ #pragma once -#include +#include #include #include #include @@ -31,13 +31,13 @@ namespace folly { namespace wangle { * W is the outbound type, i.e. outbound calls start with pipeline.write(W) */ template -class ChannelPipeline; +class Pipeline; template -class ChannelPipeline : public DelayedDestruction { +class Pipeline : public DelayedDestruction { public: - ChannelPipeline() {} - ~ChannelPipeline() {} + Pipeline() {} + ~Pipeline() {} std::shared_ptr getTransport() { return transport_; @@ -80,17 +80,17 @@ class ChannelPipeline : public DelayedDestruction { } template - ChannelPipeline& addBack(H&& handler) { - ctxs_.push_back(folly::make_unique>( + Pipeline& addBack(H&& handler) { + ctxs_.push_back(folly::make_unique>( this, std::forward(handler))); return *this; } template - ChannelPipeline& addFront(H&& handler) { + Pipeline& addFront(H&& handler) { ctxs_.insert( ctxs_.begin(), - folly::make_unique>( + folly::make_unique>( this, std::forward(handler))); return *this; @@ -98,15 +98,15 @@ class ChannelPipeline : public DelayedDestruction { template H* getHandler(int i) { - auto ctx = dynamic_cast*>(ctxs_[i].get()); + auto ctx = dynamic_cast*>(ctxs_[i].get()); CHECK(ctx); return ctx->getHandler(); } void finalize() { finalizeHelper(); - InboundChannelHandlerContext* front; - front_ = dynamic_cast*>( + InboundHandlerContext* front; + front_ = dynamic_cast*>( ctxs_.front().get()); if (!front_) { throw std::invalid_argument("wrong type for first handler"); @@ -114,7 +114,7 @@ class ChannelPipeline : public DelayedDestruction { } protected: - explicit ChannelPipeline(bool shouldFinalize) { + explicit Pipeline(bool shouldFinalize) { CHECK(!shouldFinalize); } @@ -127,7 +127,7 @@ class ChannelPipeline : public DelayedDestruction { ctxs_[i]->link(ctxs_[i+1].get()); } - back_ = dynamic_cast*>(ctxs_.back().get()); + back_ = dynamic_cast*>(ctxs_.back().get()); if (!back_) { throw std::invalid_argument("wrong type for last handler"); } @@ -154,23 +154,23 @@ class ChannelPipeline : public DelayedDestruction { transport_ = nullptr; } - OutboundChannelHandlerContext* back_{nullptr}; + OutboundHandlerContext* back_{nullptr}; private: - InboundChannelHandlerContext* front_{nullptr}; + InboundHandlerContext* front_{nullptr}; std::vector> ctxs_; }; template -class ChannelPipeline - : public ChannelPipeline { +class Pipeline + : public Pipeline { protected: template - ChannelPipeline( + Pipeline( bool shouldFinalize, HandlerArg&& handlerArg, HandlersArgs&&... handlersArgs) - : ChannelPipeline( + : Pipeline( false, std::forward(handlersArgs)...), ctx_(this, std::forward(handlerArg)) { @@ -181,76 +181,76 @@ class ChannelPipeline public: template - explicit ChannelPipeline(HandlersArgs&&... handlersArgs) - : ChannelPipeline(true, std::forward(handlersArgs)...) {} + explicit Pipeline(HandlersArgs&&... handlersArgs) + : Pipeline(true, std::forward(handlersArgs)...) {} - ~ChannelPipeline() {} + ~Pipeline() {} void read(R msg) { - typename ChannelPipeline::DestructorGuard dg( + typename Pipeline::DestructorGuard dg( static_cast(this)); front_->read(std::forward(msg)); } void readEOF() { - typename ChannelPipeline::DestructorGuard dg( + typename Pipeline::DestructorGuard dg( static_cast(this)); front_->readEOF(); } void readException(exception_wrapper e) { - typename ChannelPipeline::DestructorGuard dg( + typename Pipeline::DestructorGuard dg( static_cast(this)); front_->readException(std::move(e)); } Future write(W msg) { - typename ChannelPipeline::DestructorGuard dg( + typename Pipeline::DestructorGuard dg( static_cast(this)); return back_->write(std::forward(msg)); } Future close() { - typename ChannelPipeline::DestructorGuard dg( + typename Pipeline::DestructorGuard dg( static_cast(this)); return back_->close(); } void attachTransport( std::shared_ptr transport) { - typename ChannelPipeline::DestructorGuard dg( + typename Pipeline::DestructorGuard dg( static_cast(this)); - CHECK((!ChannelPipeline::transport_)); - ChannelPipeline::attachTransport(std::move(transport)); + CHECK((!Pipeline::transport_)); + Pipeline::attachTransport(std::move(transport)); forEachCtx([&](PipelineContext* ctx){ ctx->attachTransport(); }); } void detachTransport() { - typename ChannelPipeline::DestructorGuard dg( + typename Pipeline::DestructorGuard dg( static_cast(this)); - ChannelPipeline::detachTransport(); + Pipeline::detachTransport(); forEachCtx([&](PipelineContext* ctx){ ctx->detachTransport(); }); } std::shared_ptr getTransport() { - return ChannelPipeline::transport_; + return Pipeline::transport_; } template - ChannelPipeline& addBack(H&& handler) { - ChannelPipeline::addBack(std::move(handler)); + Pipeline& addBack(H&& handler) { + Pipeline::addBack(std::move(handler)); return *this; } template - ChannelPipeline& addFront(H&& handler) { + Pipeline& addFront(H&& handler) { ctxs_.insert( ctxs_.begin(), - folly::make_unique>( + folly::make_unique>( this, std::move(handler))); return *this; @@ -259,11 +259,11 @@ class ChannelPipeline template H* getHandler(size_t i) { if (i > ctxs_.size()) { - return ChannelPipeline::template getHandler( + return Pipeline::template getHandler( i - (ctxs_.size() + 1)); } else { auto pctx = (i == ctxs_.size()) ? &ctx_ : ctxs_[i].get(); - auto ctx = dynamic_cast*>(pctx); + auto ctx = dynamic_cast*>(pctx); return ctx->getHandler(); } } @@ -271,7 +271,7 @@ class ChannelPipeline void finalize() { finalizeHelper(); auto ctx = ctxs_.empty() ? &ctx_ : ctxs_.front().get(); - front_ = dynamic_cast*>(ctx); + front_ = dynamic_cast*>(ctx); if (!front_) { throw std::invalid_argument("wrong type for first handler"); } @@ -279,12 +279,12 @@ class ChannelPipeline protected: void finalizeHelper() { - ChannelPipeline::finalizeHelper(); - back_ = ChannelPipeline::back_; + Pipeline::finalizeHelper(); + back_ = Pipeline::back_; if (!back_) { - auto is_at_end = ChannelPipeline::is_end; + auto is_at_end = Pipeline::is_end; CHECK(is_at_end); - back_ = dynamic_cast*>(&ctx_); + back_ = dynamic_cast*>(&ctx_); if (!back_) { throw std::invalid_argument("wrong type for last handler"); } @@ -297,7 +297,7 @@ class ChannelPipeline ctxs_.back()->link(&ctx_); } - auto nextFront = ChannelPipeline::getLocalFront(); + auto nextFront = Pipeline::getLocalFront(); if (nextFront) { ctx_.link(nextFront); } @@ -308,8 +308,8 @@ class ChannelPipeline } static const bool is_end{false}; - InboundChannelHandlerContext* front_{nullptr}; - OutboundChannelHandlerContext* back_{nullptr}; + InboundHandlerContext* front_{nullptr}; + OutboundHandlerContext* back_{nullptr}; private: template @@ -320,7 +320,7 @@ class ChannelPipeline func(&ctx_); } - ContextImpl ctx_; + ContextImpl ctx_; std::vector> ctxs_; }; diff --git a/folly/wangle/channel/test/MockChannelHandler.h b/folly/wangle/channel/test/MockHandler.h similarity index 83% rename from folly/wangle/channel/test/MockChannelHandler.h rename to folly/wangle/channel/test/MockHandler.h index 15b88cb7..5a476646 100644 --- a/folly/wangle/channel/test/MockChannelHandler.h +++ b/folly/wangle/channel/test/MockHandler.h @@ -16,18 +16,18 @@ #pragma once -#include +#include #include namespace folly { namespace wangle { template -class MockChannelHandler : public ChannelHandler { +class MockHandler : public Handler { public: - typedef typename ChannelHandler::Context Context; + typedef typename Handler::Context Context; - MockChannelHandler() = default; - MockChannelHandler(MockChannelHandler&&) = default; + MockHandler() = default; + MockHandler(MockHandler&&) = default; #ifdef __clang__ # pragma clang diagnostic push @@ -70,6 +70,6 @@ class MockChannelHandler : public ChannelHandler { }; template -using MockChannelHandlerAdapter = MockChannelHandler; +using MockHandlerAdapter = MockHandler; }} diff --git a/folly/wangle/channel/test/OutputBufferingHandlerTest.cpp b/folly/wangle/channel/test/OutputBufferingHandlerTest.cpp index e99d43e5..a08509b6 100644 --- a/folly/wangle/channel/test/OutputBufferingHandlerTest.cpp +++ b/folly/wangle/channel/test/OutputBufferingHandlerTest.cpp @@ -14,9 +14,9 @@ * limitations under the License. */ -#include +#include #include -#include +#include #include #include #include @@ -25,18 +25,18 @@ using namespace folly; using namespace folly::wangle; using namespace testing; -typedef StrictMock>> -MockHandler; +MockBytesHandler; MATCHER_P(IOBufContains, str, "") { return arg->moveToFbString() == str; } TEST(OutputBufferingHandlerTest, Basic) { - MockHandler mockHandler; + MockBytesHandler mockHandler; EXPECT_CALL(mockHandler, attachPipeline(_)); - ChannelPipeline, - ChannelHandlerPtr, + Pipeline, + HandlerPtr, OutputBufferingHandler> pipeline(&mockHandler, OutputBufferingHandler{}); diff --git a/folly/wangle/channel/test/ChannelPipelineTest.cpp b/folly/wangle/channel/test/PipelineTest.cpp similarity index 79% rename from folly/wangle/channel/test/ChannelPipelineTest.cpp rename to folly/wangle/channel/test/PipelineTest.cpp index 0be3db28..5fa97a64 100644 --- a/folly/wangle/channel/test/ChannelPipelineTest.cpp +++ b/folly/wangle/channel/test/PipelineTest.cpp @@ -14,11 +14,11 @@ * limitations under the License. */ -#include -#include +#include +#include #include #include -#include +#include #include #include @@ -26,8 +26,8 @@ using namespace folly; using namespace folly::wangle; using namespace testing; -typedef StrictMock> IntHandler; -typedef ChannelHandlerPtr IntHandlerPtr; +typedef StrictMock> IntHandler; +typedef HandlerPtr IntHandlerPtr; ACTION(FireRead) { arg0->fireRead(arg1); @@ -50,12 +50,12 @@ ACTION(FireClose) { } // Test move only types, among other things -TEST(ChannelTest, RealHandlersCompile) { +TEST(PipelineTest, RealHandlersCompile) { EventBase eb; auto socket = AsyncSocket::newSocket(&eb); // static { - ChannelPipeline, + Pipeline, AsyncSocketHandler, OutputBufferingHandler> pipeline{AsyncSocketHandler(socket), OutputBufferingHandler()}; @@ -64,7 +64,7 @@ TEST(ChannelTest, RealHandlersCompile) { } // dynamic { - ChannelPipeline> pipeline; + Pipeline> pipeline; pipeline .addBack(AsyncSocketHandler(socket)) .addBack(OutputBufferingHandler()) @@ -75,14 +75,14 @@ TEST(ChannelTest, RealHandlersCompile) { } // Test that handlers correctly fire the next handler when directed -TEST(ChannelTest, FireActions) { +TEST(PipelineTest, FireActions) { IntHandler handler1; IntHandler handler2; EXPECT_CALL(handler1, attachPipeline(_)); EXPECT_CALL(handler2, attachPipeline(_)); - ChannelPipeline + Pipeline pipeline(&handler1, &handler2); EXPECT_CALL(handler1, read_(_, _)).WillOnce(FireRead()); @@ -111,10 +111,10 @@ TEST(ChannelTest, FireActions) { // Test that nothing bad happens when actions reach the end of the pipeline // (a warning will be logged, however) -TEST(ChannelTest, ReachEndOfPipeline) { +TEST(PipelineTest, ReachEndOfPipeline) { IntHandler handler; EXPECT_CALL(handler, attachPipeline(_)); - ChannelPipeline + Pipeline pipeline(&handler); EXPECT_CALL(handler, read_(_, _)).WillOnce(FireRead()); @@ -136,14 +136,14 @@ TEST(ChannelTest, ReachEndOfPipeline) { } // Test having the last read handler turn around and write -TEST(ChannelTest, TurnAround) { +TEST(PipelineTest, TurnAround) { IntHandler handler1; IntHandler handler2; EXPECT_CALL(handler1, attachPipeline(_)); EXPECT_CALL(handler2, attachPipeline(_)); - ChannelPipeline + Pipeline pipeline(&handler1, &handler2); EXPECT_CALL(handler1, read_(_, _)).WillOnce(FireRead()); @@ -155,10 +155,10 @@ TEST(ChannelTest, TurnAround) { EXPECT_CALL(handler2, detachPipeline(_)); } -TEST(ChannelTest, DynamicFireActions) { +TEST(PipelineTest, DynamicFireActions) { IntHandler handler1, handler2, handler3; EXPECT_CALL(handler2, attachPipeline(_)); - ChannelPipeline + Pipeline pipeline(&handler2); EXPECT_CALL(handler1, attachPipeline(_)); @@ -189,35 +189,35 @@ TEST(ChannelTest, DynamicFireActions) { } template -class ConcreteChannelHandler : public ChannelHandler { - typedef typename ChannelHandler::Context Context; +class ConcreteHandler : public Handler { + typedef typename Handler::Context Context; public: void read(Context* ctx, Rin msg) {} Future write(Context* ctx, Win msg) { return makeFuture(); } }; -typedef ChannelHandlerAdapter StringHandler; -typedef ConcreteChannelHandler IntToStringHandler; -typedef ConcreteChannelHandler StringToIntHandler; +typedef HandlerAdapter StringHandler; +typedef ConcreteHandler IntToStringHandler; +typedef ConcreteHandler StringToIntHandler; -TEST(ChannelPipeline, DynamicConstruction) { +TEST(Pipeline, DynamicConstruction) { { - ChannelPipeline pipeline; + Pipeline pipeline; EXPECT_THROW( pipeline - .addBack(ChannelHandlerAdapter{}) + .addBack(HandlerAdapter{}) .finalize(), std::invalid_argument); } { - ChannelPipeline pipeline; + Pipeline pipeline; EXPECT_THROW( pipeline - .addFront(ChannelHandlerAdapter{}) + .addFront(HandlerAdapter{}) .finalize(), std::invalid_argument); } { - ChannelPipeline + Pipeline pipeline{StringHandler(), StringHandler()}; // Exercise both addFront and addBack. Final pipeline is @@ -232,10 +232,10 @@ TEST(ChannelPipeline, DynamicConstruction) { } } -TEST(ChannelPipeline, AttachTransport) { +TEST(Pipeline, AttachTransport) { IntHandler handler; EXPECT_CALL(handler, attachPipeline(_)); - ChannelPipeline + Pipeline pipeline(&handler); EventBase eb; diff --git a/folly/wangle/codec/ByteToMessageCodec.h b/folly/wangle/codec/ByteToMessageCodec.h index 96680002..20d6e7fe 100644 --- a/folly/wangle/codec/ByteToMessageCodec.h +++ b/folly/wangle/codec/ByteToMessageCodec.h @@ -15,12 +15,12 @@ */ #pragma once -#include +#include namespace folly { namespace wangle { /** - * A ChannelHandler which decodes bytes in a stream-like fashion from + * A Handler which decodes bytes in a stream-like fashion from * IOBufQueue to a Message type. * * Frame detection diff --git a/folly/wangle/codec/CodecTest.cpp b/folly/wangle/codec/CodecTest.cpp index 7657c715..80bb83d3 100644 --- a/folly/wangle/codec/CodecTest.cpp +++ b/folly/wangle/codec/CodecTest.cpp @@ -55,7 +55,7 @@ class BytesReflector }; TEST(FixedLengthFrameDecoder, FailWhenLengthFieldEndOffset) { - ChannelPipeline> pipeline; + Pipeline> pipeline; int called = 0; pipeline @@ -90,7 +90,7 @@ TEST(FixedLengthFrameDecoder, FailWhenLengthFieldEndOffset) { } TEST(LengthFieldFramePipeline, SimpleTest) { - ChannelPipeline> pipeline; + Pipeline> pipeline; int called = 0; pipeline @@ -111,7 +111,7 @@ TEST(LengthFieldFramePipeline, SimpleTest) { } TEST(LengthFieldFramePipeline, LittleEndian) { - ChannelPipeline> pipeline; + Pipeline> pipeline; int called = 0; pipeline @@ -132,7 +132,7 @@ TEST(LengthFieldFramePipeline, LittleEndian) { } TEST(LengthFieldFrameDecoder, Simple) { - ChannelPipeline> pipeline; + Pipeline> pipeline; int called = 0; pipeline @@ -163,7 +163,7 @@ TEST(LengthFieldFrameDecoder, Simple) { } TEST(LengthFieldFrameDecoder, NoStrip) { - ChannelPipeline> pipeline; + Pipeline> pipeline; int called = 0; pipeline @@ -194,7 +194,7 @@ TEST(LengthFieldFrameDecoder, NoStrip) { } TEST(LengthFieldFrameDecoder, Adjustment) { - ChannelPipeline> pipeline; + Pipeline> pipeline; int called = 0; pipeline @@ -225,7 +225,7 @@ TEST(LengthFieldFrameDecoder, Adjustment) { } TEST(LengthFieldFrameDecoder, PreHeader) { - ChannelPipeline> pipeline; + Pipeline> pipeline; int called = 0; pipeline @@ -257,7 +257,7 @@ TEST(LengthFieldFrameDecoder, PreHeader) { } TEST(LengthFieldFrameDecoder, PostHeader) { - ChannelPipeline> pipeline; + Pipeline> pipeline; int called = 0; pipeline @@ -289,7 +289,7 @@ TEST(LengthFieldFrameDecoder, PostHeader) { } TEST(LengthFieldFrameDecoderStrip, PrePostHeader) { - ChannelPipeline> pipeline; + Pipeline> pipeline; int called = 0; pipeline @@ -322,7 +322,7 @@ TEST(LengthFieldFrameDecoderStrip, PrePostHeader) { } TEST(LengthFieldFrameDecoder, StripPrePostHeaderFrameInclHeader) { - ChannelPipeline> pipeline; + Pipeline> pipeline; int called = 0; pipeline @@ -355,7 +355,7 @@ TEST(LengthFieldFrameDecoder, StripPrePostHeaderFrameInclHeader) { } TEST(LengthFieldFrameDecoder, FailTestLengthFieldEndOffset) { - ChannelPipeline> pipeline; + Pipeline> pipeline; int called = 0; pipeline @@ -380,7 +380,7 @@ TEST(LengthFieldFrameDecoder, FailTestLengthFieldEndOffset) { } TEST(LengthFieldFrameDecoder, FailTestLengthFieldFrameSize) { - ChannelPipeline> pipeline; + Pipeline> pipeline; int called = 0; pipeline @@ -407,7 +407,7 @@ TEST(LengthFieldFrameDecoder, FailTestLengthFieldFrameSize) { } TEST(LengthFieldFrameDecoder, FailTestLengthFieldInitialBytes) { - ChannelPipeline> pipeline; + Pipeline> pipeline; int called = 0; pipeline @@ -434,7 +434,7 @@ TEST(LengthFieldFrameDecoder, FailTestLengthFieldInitialBytes) { } TEST(LineBasedFrameDecoder, Simple) { - ChannelPipeline> pipeline; + Pipeline> pipeline; int called = 0; pipeline @@ -485,7 +485,7 @@ TEST(LineBasedFrameDecoder, Simple) { } TEST(LineBasedFrameDecoder, SaveDelimiter) { - ChannelPipeline> pipeline; + Pipeline> pipeline; int called = 0; pipeline @@ -534,7 +534,7 @@ TEST(LineBasedFrameDecoder, SaveDelimiter) { } TEST(LineBasedFrameDecoder, Fail) { - ChannelPipeline> pipeline; + Pipeline> pipeline; int called = 0; pipeline @@ -582,7 +582,7 @@ TEST(LineBasedFrameDecoder, Fail) { } TEST(LineBasedFrameDecoder, NewLineOnly) { - ChannelPipeline> pipeline; + Pipeline> pipeline; int called = 0; pipeline @@ -609,7 +609,7 @@ TEST(LineBasedFrameDecoder, NewLineOnly) { } TEST(LineBasedFrameDecoder, CarriageNewLineOnly) { - ChannelPipeline> pipeline; + Pipeline> pipeline; int called = 0; pipeline diff --git a/folly/wangle/codec/StringCodec.h b/folly/wangle/codec/StringCodec.h index 0f8c96d4..226a3677 100644 --- a/folly/wangle/codec/StringCodec.h +++ b/folly/wangle/codec/StringCodec.h @@ -16,17 +16,17 @@ #pragma once -#include +#include namespace folly { namespace wangle { /* * StringCodec converts a pipeline from IOBufs to std::strings. */ -class StringCodec : public ChannelHandler> { +class StringCodec : public Handler> { public: - typedef typename ChannelHandler< + typedef typename Handler< IOBufQueue&, std::string, std::string, std::unique_ptr>::Context Context; diff --git a/folly/wangle/service/ClientDispatcher.h b/folly/wangle/service/ClientDispatcher.h index f0a5e89c..ac8ccc92 100644 --- a/folly/wangle/service/ClientDispatcher.h +++ b/folly/wangle/service/ClientDispatcher.h @@ -15,7 +15,7 @@ */ #pragma once -#include +#include #include namespace folly { namespace wangle { @@ -26,16 +26,16 @@ namespace folly { namespace wangle { * only one request is allowed at a time. */ template -class SerialClientDispatcher : public ChannelHandlerAdapter +class SerialClientDispatcher : public HandlerAdapter , public Service { public: - typedef typename ChannelHandlerAdapter::Context Context; + typedef typename HandlerAdapter::Context Context; void setPipeline(Pipeline* pipeline) { pipeline_ = pipeline; pipeline->addBack( - ChannelHandlerPtr, false>( + HandlerPtr, false>( this)); pipeline->finalize(); } diff --git a/folly/wangle/service/ServerDispatcher.h b/folly/wangle/service/ServerDispatcher.h index 8152dc60..0b3167e0 100644 --- a/folly/wangle/service/ServerDispatcher.h +++ b/folly/wangle/service/ServerDispatcher.h @@ -15,7 +15,7 @@ */ #pragma once -#include +#include #include namespace folly { namespace wangle { @@ -25,10 +25,10 @@ namespace folly { namespace wangle { * Concurrent requests are queued in the pipeline. */ template -class SerialServerDispatcher : public ChannelHandlerAdapter { +class SerialServerDispatcher : public HandlerAdapter { public: - typedef typename ChannelHandlerAdapter::Context Context; + typedef typename HandlerAdapter::Context Context; explicit SerialServerDispatcher(Service* service) : service_(service) {} diff --git a/folly/wangle/service/Service.h b/folly/wangle/service/Service.h index 7d78defd..1d9aab24 100644 --- a/folly/wangle/service/Service.h +++ b/folly/wangle/service/Service.h @@ -20,7 +20,7 @@ #include #include -#include +#include #include namespace folly { diff --git a/folly/wangle/service/ServiceTest.cpp b/folly/wangle/service/ServiceTest.cpp index 843f80d0..b9c6d815 100644 --- a/folly/wangle/service/ServiceTest.cpp +++ b/folly/wangle/service/ServiceTest.cpp @@ -24,7 +24,7 @@ namespace folly { using namespace wangle; -typedef ChannelPipeline Pipeline; +typedef Pipeline ServicePipeline; class EchoService : public Service { public: @@ -42,12 +42,12 @@ class EchoIntService : public Service { template class ServerPipelineFactory - : public PipelineFactory { + : public PipelineFactory { public: - Pipeline* newPipeline( + ServicePipeline* newPipeline( std::shared_ptr socket) override { - auto pipeline = new Pipeline(); + auto pipeline = new ServicePipeline(); pipeline->addBack(AsyncSocketHandler(socket)); pipeline->addBack(StringCodec()); pipeline->addBack(SerialServerDispatcher(&service_)); @@ -61,12 +61,12 @@ class ServerPipelineFactory }; template -class ClientPipelineFactory : public PipelineFactory { +class ClientPipelineFactory : public PipelineFactory { public: - Pipeline* newPipeline( + ServicePipeline* newPipeline( std::shared_ptr socket) override { - auto pipeline = new Pipeline(); + auto pipeline = new ServicePipeline(); pipeline->addBack(AsyncSocketHandler(socket)); pipeline->addBack(StringCodec()); pipeline->template getHandler(0)->attachReadCallback(); @@ -101,14 +101,14 @@ TEST(Wangle, ClientServerTest) { int port = 1234; // server - ServerBootstrap server; + ServerBootstrap server; server.childPipeline( std::make_shared>()); server.bind(port); // client - auto client = std::make_shared>(); - ClientServiceFactory serviceFactory; + auto client = std::make_shared>(); + ClientServiceFactory serviceFactory; client->pipelineFactory( std::make_shared>()); SocketAddress addr("127.0.0.1", port); -- 2.34.1