Make getWrappedTransport/getUnderlyingTransport const.
authorKyle Nekritz <knekritz@fb.com>
Fri, 4 Dec 2015 17:18:44 +0000 (09:18 -0800)
committerfacebook-github-bot-4 <folly-bot@fb.com>
Sun, 6 Dec 2015 03:20:29 +0000 (19:20 -0800)
Reviewed By: mzlee

Differential Revision: D2709222

fb-gh-sync-id: 67a00a49bbcef5572b6092d7bfba1842d985e643

folly/io/async/AsyncTransport.h
folly/io/async/test/MockAsyncTransport.h

index f9925d841c9485c071914996a4103ef538441cbb..8fdbefce013f869f5c81d7cbe6a2a40c4855daed 100644 (file)
@@ -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 <class T>
-  T* getUnderlyingTransport() {
-    AsyncTransportWrapper* current = this;
+  const T* getUnderlyingTransport() const {
+    const AsyncTransportWrapper* current = this;
     while (current) {
-      auto sock = dynamic_cast<T*>(current);
+      auto sock = dynamic_cast<const T*>(current);
       if (sock) {
         return sock;
       }
@@ -565,6 +565,12 @@ class AsyncTransportWrapper : virtual public AsyncTransport,
     return nullptr;
   }
 
+  template <class T>
+  T* getUnderlyingTransport() {
+    return const_cast<T*>(static_cast<const AsyncTransportWrapper*>(this)
+        ->getUnderlyingTransport<T>());
+  }
+
   /**
    * Return the application protocol being used by the underlying transport
    * protocol. This is useful for transports which are used to tunnel other
index 1e987d3db92a934a4cdf894ee45d599ed4dbe5a6..bd091056514341e8348212be7622cd81eb5f9c00 100644 (file)
@@ -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*());
 
 };