From f0ee7438db5f3c071c662b2d51a39066c3b83ad3 Mon Sep 17 00:00:00 2001 From: Michal Simon Date: Mon, 22 Jun 2020 18:03:08 +0200 Subject: [PATCH] [XrdCl] Use unique_ptr to manage TLS object in socket class. --- src/XrdCl/XrdClSocket.cc | 21 ++++++++++++++++++--- src/XrdCl/XrdClSocket.hh | 37 ++++++++++++++----------------------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/XrdCl/XrdClSocket.cc b/src/XrdCl/XrdClSocket.cc index 7ed74c341e8..22b6d05e321 100644 --- a/src/XrdCl/XrdClSocket.cc +++ b/src/XrdCl/XrdClSocket.cc @@ -40,13 +40,19 @@ namespace XrdCl { + Socket::Socket( int socket, SocketStatus status ): + pSocket(socket), pStatus( status ), pServerAddr( 0 ), + pProtocolFamily( AF_INET ), + pChannelID( 0 ), + pCorked( false ) + { + }; + //------------------------------------------------------------------------ // Desctuctor //------------------------------------------------------------------------ Socket::~Socket() { - if( pTls ) delete pTls; - Close(); }; @@ -752,7 +758,7 @@ namespace XrdCl { try { - if( !pTls ) pTls = new Tls( this, socketHandler ); + if( !pTls ) pTls.reset( new Tls( this, socketHandler ) ); return pTls->Connect( thehost, &pServerAddr ); } catch( std::exception& ex ) @@ -765,6 +771,15 @@ namespace XrdCl return XRootDStatus(); } + //------------------------------------------------------------------------ + // @return : true if socket is using TLS layer for encryption, + // false otherwise + //------------------------------------------------------------------------ + bool Socket::IsEncrypted() + { + return bool( pTls.get() ); + } + } diff --git a/src/XrdCl/XrdClSocket.hh b/src/XrdCl/XrdClSocket.hh index bbcb7e91700..f0507dc8a9e 100644 --- a/src/XrdCl/XrdClSocket.hh +++ b/src/XrdCl/XrdClSocket.hh @@ -22,6 +22,7 @@ #include #include #include +#include #include "XrdCl/XrdClXRootDResponses.hh" #include "XrdNet/XrdNetAddr.hh" @@ -55,14 +56,7 @@ namespace XrdCl //! @param socket already connected socket if available, -1 otherwise //! @param status status of a socket if available //------------------------------------------------------------------------ - Socket( int socket = -1, SocketStatus status = Disconnected ): - pSocket(socket), pStatus( status ), pServerAddr( 0 ), - pProtocolFamily( AF_INET ), - pChannelID( 0 ), - pCorked( false ), - pTls( 0 ) - { - }; + Socket( int socket = -1, SocketStatus status = Disconnected ); //------------------------------------------------------------------------ //! Desctuctor @@ -281,10 +275,7 @@ namespace XrdCl // @return : true if socket is using TLS layer for encryption, // false otherwise //------------------------------------------------------------------------ - inline bool IsEncrypted() - { - return bool( pTls ); - } + bool IsEncrypted(); protected: //------------------------------------------------------------------------ @@ -302,17 +293,17 @@ namespace XrdCl XRootDStatus Poll( bool readyForReading, bool readyForWriting, int32_t timeout ); - int pSocket; - SocketStatus pStatus; - XrdNetAddr pServerAddr; - mutable std::string pSockName; // mutable because it's for caching - mutable std::string pPeerName; - mutable std::string pName; - int pProtocolFamily; - AnyObject *pChannelID; - bool pCorked; - - Tls *pTls; + int pSocket; + SocketStatus pStatus; + XrdNetAddr pServerAddr; + mutable std::string pSockName; // mutable because it's for caching + mutable std::string pPeerName; + mutable std::string pName; + int pProtocolFamily; + AnyObject *pChannelID; + bool pCorked; + + std::unique_ptr pTls; }; }