From 8f06296efe2460dd6166e65d0d5fcd187c5163d6 Mon Sep 17 00:00:00 2001 From: Subodh Iyengar Date: Tue, 3 Nov 2015 21:38:07 -0800 Subject: [PATCH] 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 --- folly/io/async/AsyncSSLSocket.cpp | 9 +++++++++ folly/io/async/AsyncSSLSocket.h | 1 + folly/io/async/AsyncTransport.h | 9 +++++++++ 3 files changed, 19 insertions(+) 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 -- 2.34.1