From: Kyle Nekritz Date: Fri, 4 Dec 2015 17:18:44 +0000 (-0800) Subject: Make getWrappedTransport/getUnderlyingTransport const. X-Git-Tag: deprecate-dynamic-initializer~207 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=d662c1b73b6ee85b0743b19883bfc7606e3f6e6c;p=folly.git Make getWrappedTransport/getUnderlyingTransport const. Reviewed By: mzlee Differential Revision: D2709222 fb-gh-sync-id: 67a00a49bbcef5572b6092d7bfba1842d985e643 --- diff --git a/folly/io/async/AsyncTransport.h b/folly/io/async/AsyncTransport.h index f9925d84..8fdbefce 100644 --- a/folly/io/async/AsyncTransport.h +++ b/folly/io/async/AsyncTransport.h @@ -543,7 +543,7 @@ class AsyncTransportWrapper : virtual public AsyncTransport, * transport that is wrapped. It returns nullptr if there is no wrapped * transport. */ - virtual AsyncTransportWrapper* getWrappedTransport() { + virtual const AsyncTransportWrapper* getWrappedTransport() const { return nullptr; } @@ -553,10 +553,10 @@ class AsyncTransportWrapper : virtual public AsyncTransport, * the derived classes of the underlying transport. */ template - T* getUnderlyingTransport() { - AsyncTransportWrapper* current = this; + const T* getUnderlyingTransport() const { + const AsyncTransportWrapper* current = this; while (current) { - auto sock = dynamic_cast(current); + auto sock = dynamic_cast(current); if (sock) { return sock; } @@ -565,6 +565,12 @@ class AsyncTransportWrapper : virtual public AsyncTransport, return nullptr; } + template + T* getUnderlyingTransport() { + return const_cast(static_cast(this) + ->getUnderlyingTransport()); + } + /** * Return the application protocol being used by the underlying transport * protocol. This is useful for transports which are used to tunnel other diff --git a/folly/io/async/test/MockAsyncTransport.h b/folly/io/async/test/MockAsyncTransport.h index 1e987d3d..bd091056 100644 --- a/folly/io/async/test/MockAsyncTransport.h +++ b/folly/io/async/test/MockAsyncTransport.h @@ -77,7 +77,7 @@ class MockAsyncTransport: public AsyncTransportWrapper { MOCK_CONST_METHOD0(getRawBytesReceived, size_t()); MOCK_CONST_METHOD0(isEorTrackingEnabled, bool()); MOCK_METHOD1(setEorTracking, void(bool)); - MOCK_METHOD0(getWrappedTransport, AsyncTransportWrapper*()); + MOCK_CONST_METHOD0(getWrappedTransport, AsyncTransportWrapper*()); };