From: Subodh Iyengar Date: Wed, 4 Nov 2015 05:38:07 +0000 (-0800) Subject: Add ability to get application protocol from AsyncTransportWrapper X-Git-Tag: deprecate-dynamic-initializer~277 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=commitdiff_plain;h=8f06296efe2460dd6166e65d0d5fcd187c5163d6;hp=46bf40d1c82f1190c384222b2cf9cb2525c6e081 Add ability to get application protocol from AsyncTransportWrapper 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 --- diff --git a/folly/io/async/AsyncSSLSocket.cpp b/folly/io/async/AsyncSSLSocket.cpp index e34df564..101c1fc6 100644 --- a/folly/io/async/AsyncSSLSocket.cpp +++ b/folly/io/async/AsyncSSLSocket.cpp @@ -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(protoName), protoLength); + } + return ""; +} + bool AsyncSSLSocket::isEorTrackingEnabled() const { const BIO *wb = SSL_get_wbio(ssl_); return wb && wb->method == &eorAwareBioMethod; diff --git a/folly/io/async/AsyncSSLSocket.h b/folly/io/async/AsyncSSLSocket.h index 91d7849c..b70fd283 100644 --- a/folly/io/async/AsyncSSLSocket.h +++ b/folly/io/async/AsyncSSLSocket.h @@ -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; diff --git a/folly/io/async/AsyncTransport.h b/folly/io/async/AsyncTransport.h index 26cafbff..13bc6c94 100644 --- a/folly/io/async/AsyncTransport.h +++ b/folly/io/async/AsyncTransport.h @@ -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