Skip to content

Commit

Permalink
[XrdCl] Use unique_ptr to manage TLS object in socket class.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmichal committed Jun 22, 2020
1 parent b2e0d91 commit f0ee743
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
21 changes: 18 additions & 3 deletions src/XrdCl/XrdClSocket.cc
Expand Up @@ -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();
};

Expand Down Expand Up @@ -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 )
Expand All @@ -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() );
}

}


37 changes: 14 additions & 23 deletions src/XrdCl/XrdClSocket.hh
Expand Up @@ -22,6 +22,7 @@
#include <stdint.h>
#include <string>
#include <sys/socket.h>
#include <memory>

#include "XrdCl/XrdClXRootDResponses.hh"
#include "XrdNet/XrdNetAddr.hh"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
//------------------------------------------------------------------------
Expand All @@ -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<Tls> pTls;
};
}

Expand Down

0 comments on commit f0ee743

Please sign in to comment.