Add ability to get application protocol from AsyncTransportWrapper
authorSubodh Iyengar <subodh@fb.com>
Wed, 4 Nov 2015 05:38:07 +0000 (21:38 -0800)
committerfacebook-github-bot-1 <folly-bot@fb.com>
Wed, 4 Nov 2015 06:20:21 +0000 (22:20 -0800)
Summary: Allows AsyncTransportWrapper's to supply the underlying application
protocol being used, for example using NPN for SSL or some other
generic protocol indication mechanism.

Reviewed By: ranjeeth

Differential Revision: D2614179

fb-gh-sync-id: 2079782bb7d44f898fb14c7df15077209b022424

folly/io/async/AsyncSSLSocket.cpp
folly/io/async/AsyncSSLSocket.h
folly/io/async/AsyncTransport.h

index e34df5641d6510bf7ccf32f56b01eb8d128a2dc1..101c1fc69edbbcf39019d4dca6c926c56cfac173 100644 (file)
@@ -402,6 +402,15 @@ bool AsyncSSLSocket::connecting() const {
                                      sslState_ == STATE_CONNECTING))));
 }
 
+std::string AsyncSSLSocket::getApplicationProtocol() noexcept {
+  const unsigned char* protoName = nullptr;
+  unsigned protoLength;
+  if (getSelectedNextProtocolNoThrow(&protoName, &protoLength)) {
+    return std::string(reinterpret_cast<const char*>(protoName), protoLength);
+  }
+  return "";
+}
+
 bool AsyncSSLSocket::isEorTrackingEnabled() const {
   const BIO *wb = SSL_get_wbio(ssl_);
   return wb && wb->method == &eorAwareBioMethod;
index 91d7849c1c7a56483fa0e0022c0ce4a85ed65ff3..b70fd2839256771a74075e7aba19b958656927f8 100644 (file)
@@ -273,6 +273,7 @@ class AsyncSSLSocket : public virtual AsyncSocket {
   virtual void shutdownWriteNow() override;
   virtual bool good() const override;
   virtual bool connecting() const override;
+  virtual std::string getApplicationProtocol() noexcept override;
 
   bool isEorTrackingEnabled() const override;
   virtual void setEorTracking(bool track) override;
index 26cafbff99d1d7b13e352e302a0cdf4aba89ff8f..13bc6c94625cb317fe90656fd6e6b53382ce58f1 100644 (file)
@@ -533,6 +533,15 @@ class AsyncTransportWrapper : virtual public AsyncTransport,
   virtual AsyncTransportWrapper* getWrappedTransport() {
     return nullptr;
   }
+
+  /**
+   * Return the application protocol being used by the underlying transport
+   * protocol. This is useful for transports which are used to tunnel other
+   * protocols.
+   */
+  virtual std::string getApplicationProtocol() noexcept {
+    return "";
+  }
 };
 
 } // folly