XRootD
XrdCl::AsyncSocketHandler Class Reference

#include <XrdClAsyncSocketHandler.hh>

+ Inheritance diagram for XrdCl::AsyncSocketHandler:
+ Collaboration diagram for XrdCl::AsyncSocketHandler:

Public Member Functions

 AsyncSocketHandler (const AsyncSocketHandler &other)
 
 AsyncSocketHandler (const URL &url, Poller *poller, TransportHandler *transport, AnyObject *channelData, uint16_t subStreamNum, Stream *strm)
 Constructors. More...
 
 ~AsyncSocketHandler ()
 Destructor. More...
 
XRootDStatus Close ()
 
XRootDStatus Connect (time_t timeout)
 Connect to the currently set address. More...
 
XRootDStatus DisableUplink ()
 Disable uplink. More...
 
XRootDStatus EnableUplink ()
 Enable uplink. More...
 
virtual void Event (uint8_t type, XrdCl::Socket *)
 Handle a socket event. More...
 
const XrdNetAddrGetAddress () const
 Get the address that the socket is connected to. More...
 
std::string GetHostName ()
 Get hostname. More...
 
std::string GetIpAddr ()
 Get IP address. More...
 
std::string GetIpStack () const
 Get the IP stack. More...
 
time_t GetLastActivity ()
 Get timestamp of last registered socket activity. More...
 
const std::string & GetStreamName ()
 Get stream name. More...
 
XRootDStatus PreClose ()
 
void SetAddress (const XrdNetAddr &address)
 Set address. More...
 
- Public Member Functions inherited from XrdCl::SocketHandler
virtual ~SocketHandler ()
 
virtual void Finalize ()
 Finalizer. More...
 
virtual void Initialize (Poller *)
 Initializer. More...
 

Protected Member Functions

bool CheckHSWait () XRD_WARN_UNUSED_RESULT
 
XRootDStatus DoTlsHandShake ()
 
bool EventRead (uint8_t type) XRD_WARN_UNUSED_RESULT
 
bool EventWrite (uint8_t type) XRD_WARN_UNUSED_RESULT
 
bool HandleHandShake (std::unique_ptr< Message > msg) XRD_WARN_UNUSED_RESULT
 
kXR_int32 HandleWaitRsp (Message *rsp)
 
bool HandShakeNextStep (bool done) XRD_WARN_UNUSED_RESULT
 
virtual bool OnConnectionReturn () XRD_WARN_UNUSED_RESULT
 
void OnFault (XRootDStatus st)
 
void OnFaultWhileHandshaking (XRootDStatus st)
 
void OnHeaderCorruption ()
 
bool OnRead () XRD_WARN_UNUSED_RESULT
 
bool OnReadTimeout () XRD_WARN_UNUSED_RESULT
 
bool OnReadWhileHandshaking () XRD_WARN_UNUSED_RESULT
 
bool OnTimeoutWhileHandshaking () XRD_WARN_UNUSED_RESULT
 
bool OnTLSHandShake () XRD_WARN_UNUSED_RESULT
 
bool OnWrite () XRD_WARN_UNUSED_RESULT
 
bool OnWriteTimeout () XRD_WARN_UNUSED_RESULT
 
bool OnWriteWhileHandshaking () XRD_WARN_UNUSED_RESULT
 
bool SendHSMsg () XRD_WARN_UNUSED_RESULT
 

Static Protected Member Functions

static std::string ToStreamName (const URL &url, uint16_t strmnb)
 Convert Stream object and sub-stream number to stream name. More...
 

Protected Attributes

std::unique_ptr< AsyncHSReaderhsreader
 
std::unique_ptr< AsyncHSWriterhswriter
 
AnyObjectpChannelData
 
time_t pConnectionStarted
 
time_t pConnectionTimeout
 
bool pDoTransportDisc
 
std::unique_ptr< HandShakeDatapHandShakeData
 
bool pHandShakeDone
 
time_t pHSWaitSeconds
 
time_t pHSWaitStarted
 
time_t pLastActivity
 
std::shared_ptr< ChannelpOpenChannel
 
PollerpPoller
 
XRootDStatus pReqConnResetError
 
XrdNetAddr pSockAddr
 
SocketpSocket
 
StreampStream
 
std::string pStreamName
 
uint16_t pSubStreamNum
 
time_t pTimeoutResolution
 
bool pTlsHandShakeOngoing
 
TransportHandlerpTransport
 
URL pUrl
 
std::unique_ptr< AsyncMsgWriterreqwriter
 
std::unique_ptr< AsyncMsgReaderrspreader
 

Additional Inherited Members

- Public Types inherited from XrdCl::SocketHandler
enum  EventType {
  ReadyToRead = 0x01 ,
  ReadTimeOut = 0x02 ,
  ReadyToWrite = 0x04 ,
  WriteTimeOut = 0x08
}
 Event type. More...
 
- Static Public Member Functions inherited from XrdCl::SocketHandler
static std::string EventTypeToString (uint8_t event)
 Translate the event type to a string. More...
 

Detailed Description

Utility class handling asynchronous socket interactions and forwarding events to the parent stream.

Definition at line 43 of file XrdClAsyncSocketHandler.hh.

Constructor & Destructor Documentation

◆ AsyncSocketHandler() [1/2]

XrdCl::AsyncSocketHandler::AsyncSocketHandler ( const URL url,
Poller poller,
TransportHandler transport,
AnyObject channelData,
uint16_t  subStreamNum,
Stream strm 
)

Constructors.

Definition at line 35 of file XrdClAsyncSocketHandler.cc.

40  :
41  pPoller( poller ),
42  pTransport( transport ),
43  pChannelData( channelData ),
44  pSubStreamNum( subStreamNum ),
45  pStream( strm ),
46  pStreamName( ToStreamName( url, subStreamNum ) ),
47  pSocket( new Socket() ),
48  pHandShakeDone( false ),
49  pConnectionStarted( 0 ),
50  pConnectionTimeout( 0 ),
51  pHSWaitStarted( 0 ),
52  pHSWaitSeconds( 0 ),
53  pUrl( url ),
54  pTlsHandShakeOngoing( false ),
55  pDoTransportDisc( false )
56  {
57  Env *env = DefaultEnv::GetEnv();
58 
59  int timeoutResolution = DefaultTimeoutResolution;
60  env->GetInt( "TimeoutResolution", timeoutResolution );
61  pTimeoutResolution = timeoutResolution;
62 
64  pLastActivity = time(0);
65  }
static std::string ToStreamName(const URL &url, uint16_t strmnb)
Convert Stream object and sub-stream number to stream name.
static Env * GetEnv()
Get default client environment.
void SetChannelID(AnyObject *channelID)
Definition: XrdClSocket.hh:246
const int DefaultTimeoutResolution

References XrdCl::DefaultTimeoutResolution, XrdCl::DefaultEnv::GetEnv(), XrdCl::Env::GetInt(), pChannelData, pLastActivity, pSocket, pTimeoutResolution, and XrdCl::Socket::SetChannelID().

+ Here is the call graph for this function:

◆ AsyncSocketHandler() [2/2]

XrdCl::AsyncSocketHandler::AsyncSocketHandler ( const AsyncSocketHandler other)
inline

Definition at line 56 of file XrdClAsyncSocketHandler.hh.

56  :
57  AsyncSocketHandler( other.pUrl, other.pPoller, other.pTransport,
58  other.pChannelData, other.pSubStreamNum,
59  other.pStream )
60  {
61  pLastActivity = other.pLastActivity;
62  }
AsyncSocketHandler(const URL &url, Poller *poller, TransportHandler *transport, AnyObject *channelData, uint16_t subStreamNum, Stream *strm)
Constructors.

References pLastActivity.

◆ ~AsyncSocketHandler()

XrdCl::AsyncSocketHandler::~AsyncSocketHandler ( )

Destructor.

Definition at line 70 of file XrdClAsyncSocketHandler.cc.

71  {
72  Close();
73  delete pSocket;
74  }

References Close(), and pSocket.

+ Here is the call graph for this function:

Member Function Documentation

◆ CheckHSWait()

bool XrdCl::AsyncSocketHandler::CheckHSWait ( )
protected

Definition at line 926 of file XrdClAsyncSocketHandler.cc.

927  {
928  time_t now = time( 0 );
929  if( now - pHSWaitStarted >= pHSWaitSeconds )
930  {
931  Log *log = DefaultEnv::GetLog();
932  log->Debug( AsyncSockMsg, "[%s] The hand-shake wait time elapsed, will "
933  "replay the endsess request.", pStreamName.c_str() );
934  if( !SendHSMsg() )
935  return false;
936  //------------------------------------------------------------------------
937  // Make sure the wait state is reset
938  //------------------------------------------------------------------------
939  pHSWaitSeconds = 0;
940  pHSWaitStarted = 0;
941  }
942  return true;
943  }
bool SendHSMsg() XRD_WARN_UNUSED_RESULT
static Log * GetLog()
Get default log.
const uint64_t AsyncSockMsg
XrdSysError Log
Definition: XrdConfig.cc:113

References XrdCl::AsyncSockMsg, XrdCl::Log::Debug(), XrdCl::DefaultEnv::GetLog(), pHSWaitSeconds, pHSWaitStarted, pStreamName, and SendHSMsg().

Referenced by EventRead().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Close()

XRootDStatus XrdCl::AsyncSocketHandler::Close ( )

Close the connection. Can block until the poller can remove the socket, which may require waiting for dispatch of all queued events to all other sockets the poller thread is serving.

Definition at line 216 of file XrdClAsyncSocketHandler.cc.

217  {
218  Log *log = DefaultEnv::GetLog();
219  log->Debug( AsyncSockMsg, "[%s] Closing the socket", pStreamName.c_str() );
220 
222 
223  if( pDoTransportDisc )
224  {
226  pSubStreamNum );
227  pDoTransportDisc = false;
228  }
229 
230  pSocket->Close();
231  //--------------------------------------------------------------------------
232  // Releases a reference count on Channel. May possibly cause it to be
233  // destroyed, which will in turn destory pStream and thus us.
234  //--------------------------------------------------------------------------
235  pOpenChannel.reset();
236  return XRootDStatus();
237  }
std::shared_ptr< Channel > pOpenChannel
virtual bool RemoveSocket(Socket *socket)=0
void Close()
Disconnect.
Definition: XrdClSocket.cc:262
virtual void Disconnect(AnyObject &channelData, uint16_t subStreamId)=0
The stream has been disconnected, do the cleanups.

References XrdCl::AsyncSockMsg, XrdCl::Socket::Close(), XrdCl::Log::Debug(), XrdCl::TransportHandler::Disconnect(), XrdCl::DefaultEnv::GetLog(), pChannelData, pDoTransportDisc, pOpenChannel, pPoller, pSocket, pStreamName, pSubStreamNum, pTransport, and XrdCl::Poller::RemoveSocket().

Referenced by ~AsyncSocketHandler().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Connect()

XRootDStatus XrdCl::AsyncSocketHandler::Connect ( time_t  timeout)

Connect to the currently set address.

Definition at line 79 of file XrdClAsyncSocketHandler.cc.

80  {
81  Log *log = DefaultEnv::GetLog();
82  pLastActivity = pConnectionStarted = ::time(0);
83  pConnectionTimeout = timeout;
84 
85  //--------------------------------------------------------------------------
86  // Initialize the socket
87  //--------------------------------------------------------------------------
88  XRootDStatus st = pSocket->Initialize( pSockAddr.Family() );
89  if( !st.IsOK() )
90  {
91  log->Error( AsyncSockMsg, "[%s] Unable to initialize socket: %s",
92  pStreamName.c_str(), st.ToString().c_str() );
93  st.status = stFatal;
94  return st;
95  }
96 
97  //--------------------------------------------------------------------------
98  // Set the keep-alive up
99  //--------------------------------------------------------------------------
100  Env *env = DefaultEnv::GetEnv();
101 
102  int keepAlive = DefaultTCPKeepAlive;
103  env->GetInt( "TCPKeepAlive", keepAlive );
104  if( keepAlive )
105  {
106  int param = 1;
107  XRootDStatus st = pSocket->SetSockOpt( SOL_SOCKET, SO_KEEPALIVE, &param,
108  sizeof(param) );
109  if( !st.IsOK() )
110  log->Error( AsyncSockMsg, "[%s] Unable to turn on keepalive: %s",
111  pStreamName.c_str(), st.ToString().c_str() );
112 
113 #if ( defined(__linux__) || defined(__GNU__) ) && defined( TCP_KEEPIDLE ) && \
114  defined( TCP_KEEPINTVL ) && defined( TCP_KEEPCNT )
115 
116  param = DefaultTCPKeepAliveTime;
117  env->GetInt( "TCPKeepAliveTime", param );
118  st = pSocket->SetSockOpt(SOL_TCP, TCP_KEEPIDLE, &param, sizeof(param));
119  if( !st.IsOK() )
120  log->Error( AsyncSockMsg, "[%s] Unable to set keepalive time: %s",
121  pStreamName.c_str(), st.ToString().c_str() );
122 
124  env->GetInt( "TCPKeepAliveInterval", param );
125  st = pSocket->SetSockOpt(SOL_TCP, TCP_KEEPINTVL, &param, sizeof(param));
126  if( !st.IsOK() )
127  log->Error( AsyncSockMsg, "[%s] Unable to set keepalive interval: %s",
128  pStreamName.c_str(), st.ToString().c_str() );
129 
131  env->GetInt( "TCPKeepAliveProbes", param );
132  st = pSocket->SetSockOpt(SOL_TCP, TCP_KEEPCNT, &param, sizeof(param));
133  if( !st.IsOK() )
134  log->Error( AsyncSockMsg, "[%s] Unable to set keepalive probes: %s",
135  pStreamName.c_str(), st.ToString().c_str() );
136 #endif
137  }
138 
139  pHandShakeDone = false;
140  pTlsHandShakeOngoing = false;
141  pHSWaitStarted = 0;
142  pHSWaitSeconds = 0;
143  pReqConnResetError = XRootDStatus();
144 
145  //--------------------------------------------------------------------------
146  // Initiate async connection to the address
147  //--------------------------------------------------------------------------
148  char nameBuff[256];
149  pSockAddr.Format( nameBuff, sizeof(nameBuff), XrdNetAddrInfo::fmtAdv6 );
150  log->Debug( AsyncSockMsg, "[%s] Attempting connection to %s",
151  pStreamName.c_str(), nameBuff );
152 
153  st = pSocket->ConnectToAddress( pSockAddr, 0 );
154  if( !st.IsOK() )
155  {
156  log->Error( AsyncSockMsg, "[%s] Unable to initiate the connection: %s",
157  pStreamName.c_str(), st.ToString().c_str() );
158  return st;
159  }
160 
162 
164  pDoTransportDisc = true;
165 
166  //--------------------------------------------------------------------------
167  // We should get the ready to write event once we're really connected
168  // so we need to listen to it
169  //--------------------------------------------------------------------------
170  if( !pPoller->AddSocket( pSocket, this ) )
171  {
172  XRootDStatus st( stFatal, errPollerError );
173  pSocket->Close();
174  pDoTransportDisc = false;
175  pOpenChannel.reset();
176  return st;
177  }
178 
180  {
181  XRootDStatus st( stFatal, errPollerError );
183  pSocket->Close();
184  pDoTransportDisc = false;
185  pOpenChannel.reset();
186  return st;
187  }
188 
189  return XRootDStatus();
190  }
virtual bool AddSocket(Socket *socket, SocketHandler *handler)=0
virtual bool EnableWriteNotification(Socket *socket, bool notify, time_t timeout=60)=0
XRootDStatus ConnectToAddress(const XrdNetAddr &addr, time_t timeout=10)
Definition: XrdClSocket.cc:212
XRootDStatus Initialize(int family=AF_INET)
Initialize the socket.
Definition: XrdClSocket.cc:63
@ Connecting
The connection process is in progress.
Definition: XrdClSocket.hh:52
XRootDStatus SetSockOpt(int level, int optname, const void *optval, socklen_t optlen)
Set socket options.
Definition: XrdClSocket.cc:167
void SetStatus(SocketStatus status)
Set socket status - do not use unless you know what you're doing.
Definition: XrdClSocket.hh:133
std::shared_ptr< Channel > GetChannel()
Definition: XrdClStream.hh:414
int Format(char *bAddr, int bLen, fmtUse fmtType=fmtAuto, int fmtOpts=0)
int Family() const
const int DefaultTCPKeepAliveProbes
const uint16_t stFatal
Fatal error, it's still an error.
Definition: XrdClStatus.hh:33
const uint16_t errPollerError
Definition: XrdClStatus.hh:75
const int DefaultTCPKeepAliveInterval
const int DefaultTCPKeepAlive
const int DefaultTCPKeepAliveTime
uint16_t status
Status of the execution.
Definition: XrdClStatus.hh:146

References XrdCl::Poller::AddSocket(), XrdCl::AsyncSockMsg, XrdCl::Socket::Close(), XrdCl::Socket::Connecting, XrdCl::Socket::ConnectToAddress(), XrdCl::Log::Debug(), XrdCl::DefaultTCPKeepAlive, XrdCl::DefaultTCPKeepAliveInterval, XrdCl::DefaultTCPKeepAliveProbes, XrdCl::DefaultTCPKeepAliveTime, XrdCl::Poller::EnableWriteNotification(), XrdCl::Log::Error(), XrdCl::errPollerError, XrdNetAddrInfo::Family(), XrdNetAddrInfo::fmtAdv6, XrdNetAddrInfo::Format(), XrdCl::Stream::GetChannel(), XrdCl::DefaultEnv::GetEnv(), XrdCl::Env::GetInt(), XrdCl::DefaultEnv::GetLog(), XrdCl::Socket::Initialize(), XrdCl::Status::IsOK(), pConnectionStarted, pConnectionTimeout, pDoTransportDisc, pHandShakeDone, pHSWaitSeconds, pHSWaitStarted, pLastActivity, pOpenChannel, pPoller, pReqConnResetError, pSockAddr, pSocket, pStream, pStreamName, pTimeoutResolution, pTlsHandShakeOngoing, XrdCl::Poller::RemoveSocket(), XrdCl::Socket::SetSockOpt(), XrdCl::Socket::SetStatus(), XrdCl::Status::status, XrdCl::stFatal, and XrdCl::Status::ToString().

+ Here is the call graph for this function:

◆ DisableUplink()

XRootDStatus XrdCl::AsyncSocketHandler::DisableUplink ( )
inline

Disable uplink.

Definition at line 122 of file XrdClAsyncSocketHandler.hh.

123  {
124  if( !pPoller->EnableWriteNotification( pSocket, false ) )
125  return XRootDStatus( stFatal, errPollerError );
126  return XRootDStatus();
127  }

References XrdCl::Poller::EnableWriteNotification(), XrdCl::errPollerError, pPoller, pSocket, and XrdCl::stFatal.

Referenced by XrdCl::Tls::Connect(), OnWrite(), OnWriteWhileHandshaking(), XrdCl::Tls::Read(), and XrdCl::Tls::Send().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DoTlsHandShake()

XRootDStatus XrdCl::AsyncSocketHandler::DoTlsHandShake ( )
protected

Definition at line 836 of file XrdClAsyncSocketHandler.cc.

837  {
838  Log *log = DefaultEnv::GetLog();
839  log->Debug( AsyncSockMsg, "[%s] TLS hand-shake exchange.", pStreamName.c_str() );
840 
841  XRootDStatus st;
842  if( !( st = pSocket->TlsHandShake( this, pUrl.GetHostName() ) ).IsOK() )
843  {
844  pTlsHandShakeOngoing = false;
846  return st;
847  }
848 
849  if( st.code == suRetry )
850  {
851  pTlsHandShakeOngoing = true;
852  return st;
853  }
854 
855  pTlsHandShakeOngoing = false;
856  log->Info( AsyncSockMsg, "[%s] TLS hand-shake done.", pStreamName.c_str() );
857 
858  return st;
859  }
void OnFaultWhileHandshaking(XRootDStatus st)
XRootDStatus TlsHandShake(AsyncSocketHandler *socketHandler, const std::string &thehost=std::string())
Definition: XrdClSocket.cc:844
const std::string & GetHostName() const
Get the name of the target host.
Definition: XrdClURL.hh:170
const uint16_t suRetry
Definition: XrdClStatus.hh:40

References XrdCl::AsyncSockMsg, XrdCl::Status::code, XrdCl::Log::Debug(), XrdCl::URL::GetHostName(), XrdCl::DefaultEnv::GetLog(), XrdCl::Log::Info(), OnFaultWhileHandshaking(), pSocket, pStreamName, pTlsHandShakeOngoing, pUrl, XrdCl::suRetry, and XrdCl::Socket::TlsHandShake().

Referenced by HandleHandShake(), and OnTLSHandShake().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ EnableUplink()

XRootDStatus XrdCl::AsyncSocketHandler::EnableUplink ( )
inline

Enable uplink.

Definition at line 112 of file XrdClAsyncSocketHandler.hh.

113  {
115  return XRootDStatus( stFatal, errPollerError );
116  return XRootDStatus();
117  }

References XrdCl::Poller::EnableWriteNotification(), XrdCl::errPollerError, pPoller, pSocket, pTimeoutResolution, and XrdCl::stFatal.

Referenced by XrdCl::Tls::Connect(), HandShakeNextStep(), XrdCl::Tls::Read(), XrdCl::Tls::Send(), and SendHSMsg().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Event()

void XrdCl::AsyncSocketHandler::Event ( uint8_t  type,
XrdCl::Socket  
)
virtual

Handle a socket event.

Implements XrdCl::SocketHandler.

Definition at line 250 of file XrdClAsyncSocketHandler.cc.

251  {
252  //--------------------------------------------------------------------------
253  // First check if the socket itself wants to apply some mapping on the
254  // event. E.g. in case of TLS socket it might want to map read events to
255  // write events and vice-versa.
256  //--------------------------------------------------------------------------
257  type = pSocket->MapEvent( type );
258 
259  //--------------------------------------------------------------------------
260  // Handle any read or write events. If any of the handlers indicate an error
261  // we will have been disconnected. A disconnection may cause the current
262  // object to be asynchronously reused or deleted, so we return immediately.
263  //--------------------------------------------------------------------------
264  if( !EventRead( type ) )
265  return;
266 
267  //--------------------------------------------------------------------------
268  // If there's a previosuly noted ECONNRESET error from write we give the
269  // fault now. This gave us the chance to process a read event.
270  //--------------------------------------------------------------------------
271  if( !pReqConnResetError.IsOK() )
272  {
274  return;
275  }
276 
277  if( !EventWrite( type ) )
278  return;
279  }
bool EventRead(uint8_t type) XRD_WARN_UNUSED_RESULT
bool EventWrite(uint8_t type) XRD_WARN_UNUSED_RESULT
uint8_t MapEvent(uint8_t event)
Definition: XrdClSocket.cc:835
bool IsOK() const
We're fine.
Definition: XrdClStatus.hh:124

References EventRead(), EventWrite(), XrdCl::Status::IsOK(), XrdCl::Socket::MapEvent(), OnFault(), pReqConnResetError, and pSocket.

+ Here is the call graph for this function:

◆ EventRead()

bool XrdCl::AsyncSocketHandler::EventRead ( uint8_t  type)
inlineprotected

Definition at line 284 of file XrdClAsyncSocketHandler.cc.

285  {
286  //--------------------------------------------------------------------------
287  // Read event
288  //--------------------------------------------------------------------------
289  if( type & ReadyToRead )
290  {
291  pLastActivity = time(0);
293  return OnTLSHandShake();
294 
295  if( likely( pHandShakeDone ) )
296  return OnRead();
297 
298  return OnReadWhileHandshaking();
299  }
300 
301  //--------------------------------------------------------------------------
302  // Read timeout
303  //--------------------------------------------------------------------------
304  else if( type & ReadTimeOut )
305  {
306  if( pHSWaitSeconds )
307  {
308  if( !CheckHSWait() )
309  return false;
310  }
311 
312  if( likely( pHandShakeDone ) )
313  return OnReadTimeout();
314 
315  return OnTimeoutWhileHandshaking();
316  }
317 
318  return true;
319  }
#define likely(x)
#define unlikely(x)
bool OnReadTimeout() XRD_WARN_UNUSED_RESULT
bool OnTimeoutWhileHandshaking() XRD_WARN_UNUSED_RESULT
bool CheckHSWait() XRD_WARN_UNUSED_RESULT
bool OnReadWhileHandshaking() XRD_WARN_UNUSED_RESULT
bool OnRead() XRD_WARN_UNUSED_RESULT
bool OnTLSHandShake() XRD_WARN_UNUSED_RESULT
@ ReadTimeOut
Read timeout.
Definition: XrdClPoller.hh:43
@ ReadyToRead
New data has arrived.
Definition: XrdClPoller.hh:42

References CheckHSWait(), likely, OnRead(), OnReadTimeout(), OnReadWhileHandshaking(), OnTimeoutWhileHandshaking(), OnTLSHandShake(), pHandShakeDone, pHSWaitSeconds, pLastActivity, pTlsHandShakeOngoing, XrdCl::SocketHandler::ReadTimeOut, XrdCl::SocketHandler::ReadyToRead, and unlikely.

Referenced by Event().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ EventWrite()

bool XrdCl::AsyncSocketHandler::EventWrite ( uint8_t  type)
inlineprotected

Definition at line 324 of file XrdClAsyncSocketHandler.cc.

325  {
326  //--------------------------------------------------------------------------
327  // Write event
328  //--------------------------------------------------------------------------
329  if( type & ReadyToWrite )
330  {
331  pLastActivity = time(0);
333  return OnConnectionReturn();
334 
335  //------------------------------------------------------------------------
336  // Make sure we are not writing anything if we have been told to wait.
337  //------------------------------------------------------------------------
338  if( pHSWaitSeconds != 0 )
339  return true;
340 
342  return OnTLSHandShake();
343 
344  if( likely( pHandShakeDone ) )
345  return OnWrite();
346 
347  return OnWriteWhileHandshaking();
348  }
349 
350  //--------------------------------------------------------------------------
351  // Write timeout
352  //--------------------------------------------------------------------------
353  else if( type & WriteTimeOut )
354  {
355  if( likely( pHandShakeDone ) )
356  return OnWriteTimeout();
357 
358  return OnTimeoutWhileHandshaking();
359  }
360 
361  return true;
362  }
virtual bool OnConnectionReturn() XRD_WARN_UNUSED_RESULT
bool OnWriteTimeout() XRD_WARN_UNUSED_RESULT
bool OnWrite() XRD_WARN_UNUSED_RESULT
bool OnWriteWhileHandshaking() XRD_WARN_UNUSED_RESULT
@ ReadyToWrite
Writing won't block.
Definition: XrdClPoller.hh:44
@ WriteTimeOut
Write timeout.
Definition: XrdClPoller.hh:45
SocketStatus GetStatus() const
Get the socket status.
Definition: XrdClSocket.hh:125

References XrdCl::Socket::Connecting, XrdCl::Socket::GetStatus(), likely, OnConnectionReturn(), OnTimeoutWhileHandshaking(), OnTLSHandShake(), OnWrite(), OnWriteTimeout(), OnWriteWhileHandshaking(), pHandShakeDone, pHSWaitSeconds, pLastActivity, pSocket, pTlsHandShakeOngoing, XrdCl::SocketHandler::ReadyToWrite, unlikely, and XrdCl::SocketHandler::WriteTimeOut.

Referenced by Event().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetAddress()

const XrdNetAddr& XrdCl::AsyncSocketHandler::GetAddress ( ) const
inline

Get the address that the socket is connected to.

Definition at line 80 of file XrdClAsyncSocketHandler.hh.

81  {
82  return pSockAddr;
83  }

References pSockAddr.

◆ GetHostName()

std::string XrdCl::AsyncSocketHandler::GetHostName ( )

Get hostname.

Definition at line 968 of file XrdClAsyncSocketHandler.cc.

969  {
970  const char *cstr = pSockAddr.Name();
971  if( !cstr )
972  return std::string();
973  return cstr;
974  }
const char * Name(const char *eName=0, const char **eText=0)

References XrdNetAddrInfo::Name(), and pSockAddr.

+ Here is the call graph for this function:

◆ GetIpAddr()

std::string XrdCl::AsyncSocketHandler::GetIpAddr ( )

Get IP address.

Definition at line 958 of file XrdClAsyncSocketHandler.cc.

959  {
960  char nameBuff[256];
961  pSockAddr.Format( nameBuff, sizeof(nameBuff), XrdNetAddrInfo::fmtAddr, XrdNetAddrInfo::noPort );
962  return nameBuff;
963  }
static const int noPort
Do not add port number.
@ fmtAddr
Address using suitable ipv4 or ipv6 format.

References XrdNetAddrInfo::fmtAddr, XrdNetAddrInfo::Format(), XrdNetAddrInfo::noPort, and pSockAddr.

+ Here is the call graph for this function:

◆ GetIpStack()

std::string XrdCl::AsyncSocketHandler::GetIpStack ( ) const

Get the IP stack.

Definition at line 948 of file XrdClAsyncSocketHandler.cc.

949  {
950  std::string ipstack( ( pSockAddr.isIPType( XrdNetAddr::IPType::IPv6 ) &&
951  !pSockAddr.isMapped() ) ? "IPv6" : "IPv4" );
952  return ipstack;
953  }
bool isMapped() const
bool isIPType(IPType ipType) const

References XrdNetAddrInfo::isIPType(), XrdNetAddrInfo::isMapped(), and pSockAddr.

+ Here is the call graph for this function:

◆ GetLastActivity()

time_t XrdCl::AsyncSocketHandler::GetLastActivity ( )
inline

Get timestamp of last registered socket activity.

Definition at line 140 of file XrdClAsyncSocketHandler.hh.

141  {
142  return pLastActivity;
143  }

References pLastActivity.

◆ GetStreamName()

const std::string& XrdCl::AsyncSocketHandler::GetStreamName ( )
inline

Get stream name.

Definition at line 132 of file XrdClAsyncSocketHandler.hh.

133  {
134  return pStreamName;
135  }

References pStreamName.

◆ HandleHandShake()

bool XrdCl::AsyncSocketHandler::HandleHandShake ( std::unique_ptr< Message msg)
protected

Definition at line 641 of file XrdClAsyncSocketHandler.cc.

642  {
643  //--------------------------------------------------------------------------
644  // OK, we have a new message, let's deal with it;
645  //--------------------------------------------------------------------------
646  pHandShakeData->in = msg.release();
647  XRootDStatus st = pTransport->HandShake( pHandShakeData.get(), *pChannelData );
648 
649  //--------------------------------------------------------------------------
650  // Deal with wait responses
651  //--------------------------------------------------------------------------
652  kXR_int32 waitSeconds = HandleWaitRsp( pHandShakeData->in );
653 
654  delete pHandShakeData->in;
655  pHandShakeData->in = 0;
656 
657  if( !st.IsOK() )
658  {
660  return false;
661  }
662 
663  if( st.code == suRetry )
664  {
665  //------------------------------------------------------------------------
666  // We are handling a wait response and the transport handler told
667  // as to retry the request
668  //------------------------------------------------------------------------
669  if( waitSeconds >=0 )
670  {
671  time_t resendTime = ::time( 0 ) + waitSeconds;
672  if( resendTime > pConnectionStarted + pConnectionTimeout )
673  {
674  Log *log = DefaultEnv::GetLog();
675  log->Error( AsyncSockMsg,
676  "[%s] Won't retry kXR_endsess request because would"
677  "reach connection timeout.",
678  pStreamName.c_str() );
679 
681  return false;
682  }
683  else
684  {
685  //--------------------------------------------------------------------
686  // We need to wait before replaying the request
687  //--------------------------------------------------------------------
688  Log *log = DefaultEnv::GetLog();
689  log->Debug( AsyncSockMsg, "[%s] Received a wait response to endsess request, "
690  "will wait for %d seconds before replaying the endsess request",
691  pStreamName.c_str(), waitSeconds );
692  pHSWaitStarted = time( 0 );
693  pHSWaitSeconds = waitSeconds;
694  }
695  return true;
696  }
697  //------------------------------------------------------------------------
698  // We are re-sending a protocol request
699  //------------------------------------------------------------------------
700  else if( pHandShakeData->out )
701  {
702  return SendHSMsg();
703  }
704  }
705 
706  //--------------------------------------------------------------------------
707  // If now is the time to enable encryption
708  //--------------------------------------------------------------------------
709  if( !pSocket->IsEncrypted() &&
711  {
712  XRootDStatus st = DoTlsHandShake();
713  if( !st.IsOK() )
714  return false;
715  if ( st.code == suRetry )
716  return true;
717  }
718 
719  //--------------------------------------------------------------------------
720  // Now prepare the next step of the hand-shake procedure
721  //--------------------------------------------------------------------------
722  return HandShakeNextStep( st.IsOK() && st.code == suDone );
723  }
int kXR_int32
Definition: XPtypes.hh:89
kXR_int32 HandleWaitRsp(Message *rsp)
bool HandShakeNextStep(bool done) XRD_WARN_UNUSED_RESULT
std::unique_ptr< HandShakeData > pHandShakeData
bool IsEncrypted()
Definition: XrdClSocket.cc:867
virtual bool NeedEncryption(HandShakeData *handShakeData, AnyObject &channelData)=0
virtual XRootDStatus HandShake(HandShakeData *handShakeData, AnyObject &channelData)=0
HandHake.
const uint16_t stError
An error occurred that could potentially be retried.
Definition: XrdClStatus.hh:32
const uint16_t errSocketTimeout
Definition: XrdClStatus.hh:73
const uint16_t suDone
Definition: XrdClStatus.hh:38

References XrdCl::AsyncSockMsg, XrdCl::Status::code, XrdCl::Log::Debug(), DoTlsHandShake(), XrdCl::Log::Error(), XrdCl::errSocketTimeout, XrdCl::DefaultEnv::GetLog(), HandleWaitRsp(), XrdCl::TransportHandler::HandShake(), HandShakeNextStep(), XrdCl::Socket::IsEncrypted(), XrdCl::Status::IsOK(), XrdCl::TransportHandler::NeedEncryption(), OnFaultWhileHandshaking(), pChannelData, pConnectionStarted, pConnectionTimeout, pHandShakeData, pHSWaitSeconds, pHSWaitStarted, pSocket, pStreamName, pTransport, SendHSMsg(), XrdCl::stError, XrdCl::suDone, and XrdCl::suRetry.

Referenced by OnReadWhileHandshaking().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HandleWaitRsp()

kXR_int32 XrdCl::AsyncSocketHandler::HandleWaitRsp ( Message rsp)
inlineprotected

Definition at line 912 of file XrdClAsyncSocketHandler.cc.

913  {
914  // It would be more coherent if this could be done in the
915  // transport layer, unfortunately the API does not allow it.
916  kXR_int32 waitSeconds = -1;
917  ServerResponse *rsp = (ServerResponse*)msg->GetBuffer();
918  if( rsp->hdr.status == kXR_wait )
919  waitSeconds = rsp->body.wait.seconds;
920  return waitSeconds;
921  }
union ServerResponse::@0 body
@ kXR_wait
Definition: XProtocol.hh:947
ServerResponseHeader hdr
Definition: XProtocol.hh:1330

References ServerResponse::body, XrdCl::Buffer::GetBuffer(), ServerResponse::hdr, kXR_wait, and ServerResponseHeader::status.

Referenced by HandleHandShake().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HandShakeNextStep()

bool XrdCl::AsyncSocketHandler::HandShakeNextStep ( bool  done)
protected

Definition at line 728 of file XrdClAsyncSocketHandler.cc.

729  {
730  //--------------------------------------------------------------------------
731  // We successfully proceeded to the next step
732  //--------------------------------------------------------------------------
733  ++pHandShakeData->step;
734 
735  //--------------------------------------------------------------------------
736  // The hand shake process is done
737  //--------------------------------------------------------------------------
738  if( done )
739  {
740  pHandShakeData.reset();
741  hswriter.reset();
742  hsreader.reset();
743  //------------------------------------------------------------------------
744  // Initialize the request writer & reader
745  //------------------------------------------------------------------------
746  reqwriter.reset( new AsyncMsgWriter( *pTransport, *pSocket, pStreamName, *pStream, pSubStreamNum, *pChannelData ) );
747  rspreader.reset( new AsyncMsgReader( *pTransport, *pSocket, pStreamName, *pStream, pSubStreamNum ) );
748  XRootDStatus st;
749  if( !(st = EnableUplink()).IsOK() )
750  {
752  return false;
753  }
754  pHandShakeDone = true;
756  }
757  //--------------------------------------------------------------------------
758  // The transport handler gave us something to write
759  //--------------------------------------------------------------------------
760  else if( pHandShakeData->out )
761  {
762  return SendHSMsg();
763  }
764  return true;
765  }
std::unique_ptr< AsyncHSWriter > hswriter
std::unique_ptr< AsyncHSReader > hsreader
std::unique_ptr< AsyncMsgWriter > reqwriter
XRootDStatus EnableUplink()
Enable uplink.
std::unique_ptr< AsyncMsgReader > rspreader
void OnConnect(uint16_t subStream)
Call back when a message has been reconstructed.
Definition: XrdClStream.cc:834

References EnableUplink(), hsreader, hswriter, XrdCl::Stream::OnConnect(), OnFaultWhileHandshaking(), pChannelData, pHandShakeData, pHandShakeDone, pSocket, pStream, pStreamName, pSubStreamNum, pTransport, reqwriter, rspreader, and SendHSMsg().

Referenced by HandleHandShake(), and OnTLSHandShake().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OnConnectionReturn()

bool XrdCl::AsyncSocketHandler::OnConnectionReturn ( )
protectedvirtual

Definition at line 367 of file XrdClAsyncSocketHandler.cc.

368  {
369  //--------------------------------------------------------------------------
370  // Check whether we were able to connect
371  //--------------------------------------------------------------------------
372  Log *log = DefaultEnv::GetLog();
373  log->Debug( AsyncSockMsg, "[%s] Async connection call returned",
374  pStreamName.c_str() );
375 
376  int errorCode = 0;
377  socklen_t optSize = sizeof( errorCode );
378  XRootDStatus st = pSocket->GetSockOpt( SOL_SOCKET, SO_ERROR, &errorCode,
379  &optSize );
380 
381  //--------------------------------------------------------------------------
382  // This is an internal error really (either logic or system fault),
383  // so we call it a day and don't retry
384  //--------------------------------------------------------------------------
385  if( !st.IsOK() )
386  {
387  log->Error( AsyncSockMsg, "[%s] Unable to get the status of the "
388  "connect operation: %s", pStreamName.c_str(),
389  XrdSysE2T( errno ) );
391  XRootDStatus( stFatal, errSocketOptError, errno ) );
392  return false;
393  }
394 
395  //--------------------------------------------------------------------------
396  // We were unable to connect
397  //--------------------------------------------------------------------------
398  if( errorCode )
399  {
400  log->Error( AsyncSockMsg, "[%s] Unable to connect: %s",
401  pStreamName.c_str(), XrdSysE2T( errorCode ) );
403  XRootDStatus( stError, errConnectionError ) );
404  return false;
405  }
407 
408  //--------------------------------------------------------------------------
409  // Cork the socket
410  //--------------------------------------------------------------------------
411  st = pSocket->Cork();
412  if( !st.IsOK() )
413  {
415  return false;
416  }
417 
418  //--------------------------------------------------------------------------
419  // Initialize the handshake
420  //--------------------------------------------------------------------------
421  pHandShakeData.reset( new HandShakeData( pStream->GetURL(),
422  pSubStreamNum ) );
423  pHandShakeData->serverAddr = pSocket->GetServerAddress();
424  pHandShakeData->clientName = pSocket->GetSockName();
425  pHandShakeData->streamName = pStreamName;
426 
428  if( !st.IsOK() )
429  {
430  log->Error( AsyncSockMsg, "[%s] Connection negotiation failed",
431  pStreamName.c_str() );
433  return false;
434  }
435 
436  if( st.code != suRetry )
437  ++pHandShakeData->step;
438 
439  //--------------------------------------------------------------------------
440  // Initialize the hand-shake reader and writer
441  //--------------------------------------------------------------------------
442  hswriter.reset( new AsyncHSWriter( *pSocket, pStreamName ) );
443  hsreader.reset( new AsyncHSReader( *pTransport, *pSocket, pStreamName, *pStream, pSubStreamNum ) );
444 
445  //--------------------------------------------------------------------------
446  // Transport has given us something to send
447  //--------------------------------------------------------------------------
448  if( pHandShakeData->out )
449  {
450  hswriter->Reset( pHandShakeData->out );
451  pHandShakeData->out = nullptr;
452  }
453 
454  //--------------------------------------------------------------------------
455  // Listen to what the server has to say
456  //--------------------------------------------------------------------------
458  {
460  XRootDStatus( stFatal, errPollerError ) );
461  return false;
462  }
463  return true;
464  }
const char * XrdSysE2T(int errcode)
Definition: XrdSysE2T.cc:104
virtual bool EnableReadNotification(Socket *socket, bool notify, time_t timeout=60)=0
std::string GetSockName() const
Get the name of the socket.
Definition: XrdClSocket.cc:632
@ Connected
The socket is connected.
Definition: XrdClSocket.hh:51
const XrdNetAddr * GetServerAddress() const
Get the server address.
Definition: XrdClSocket.hh:237
XRootDStatus Cork()
Definition: XrdClSocket.cc:782
XRootDStatus GetSockOpt(int level, int optname, void *optval, socklen_t *optlen)
Get socket options.
Definition: XrdClSocket.cc:152
void OnConnectError(uint16_t subStream, XRootDStatus status)
On connect error.
Definition: XrdClStream.cc:947
const URL * GetURL() const
Get the URL.
Definition: XrdClStream.hh:284
const uint16_t errSocketOptError
Definition: XrdClStatus.hh:76
const uint16_t errConnectionError
Definition: XrdClStatus.hh:78

References XrdCl::AsyncSockMsg, XrdCl::Status::code, XrdCl::Socket::Connected, XrdCl::Socket::Cork(), XrdCl::Log::Debug(), XrdCl::Poller::EnableReadNotification(), XrdCl::errConnectionError, XrdCl::Log::Error(), XrdCl::errPollerError, XrdCl::errSocketOptError, XrdCl::DefaultEnv::GetLog(), XrdCl::Socket::GetServerAddress(), XrdCl::Socket::GetSockName(), XrdCl::Socket::GetSockOpt(), XrdCl::Stream::GetURL(), XrdCl::TransportHandler::HandShake(), hsreader, hswriter, XrdCl::Status::IsOK(), XrdCl::Stream::OnConnectError(), pChannelData, pHandShakeData, pPoller, pSocket, pStream, pStreamName, pSubStreamNum, pTimeoutResolution, pTransport, XrdCl::Socket::SetStatus(), XrdCl::stError, XrdCl::stFatal, XrdCl::suRetry, and XrdSysE2T().

Referenced by EventWrite().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OnFault()

void XrdCl::AsyncSocketHandler::OnFault ( XRootDStatus  st)
protected

Definition at line 770 of file XrdClAsyncSocketHandler.cc.

771  {
772  Log *log = DefaultEnv::GetLog();
773  log->Error( AsyncSockMsg, "[%s] Socket error encountered: %s",
774  pStreamName.c_str(), st.ToString().c_str() );
775 
776  pStream->OnError( pSubStreamNum, st );
777  }
void OnError(uint16_t subStream, XRootDStatus status)
On error.

References XrdCl::AsyncSockMsg, XrdCl::Log::Error(), XrdCl::DefaultEnv::GetLog(), XrdCl::Stream::OnError(), pStream, pStreamName, pSubStreamNum, and XrdCl::Status::ToString().

Referenced by Event(), OnRead(), OnReadWhileHandshaking(), and OnWrite().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OnFaultWhileHandshaking()

void XrdCl::AsyncSocketHandler::OnFaultWhileHandshaking ( XRootDStatus  st)
protected

Definition at line 782 of file XrdClAsyncSocketHandler.cc.

783  {
784  Log *log = DefaultEnv::GetLog();
785  log->Error( AsyncSockMsg, "[%s] Socket error while handshaking: %s",
786  pStreamName.c_str(), st.ToString().c_str() );
787 
789  }

References XrdCl::AsyncSockMsg, XrdCl::Log::Error(), XrdCl::DefaultEnv::GetLog(), XrdCl::Stream::OnConnectError(), pStream, pStreamName, pSubStreamNum, and XrdCl::Status::ToString().

Referenced by DoTlsHandShake(), HandleHandShake(), HandShakeNextStep(), OnReadWhileHandshaking(), OnTimeoutWhileHandshaking(), OnWriteWhileHandshaking(), and SendHSMsg().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OnHeaderCorruption()

void XrdCl::AsyncSocketHandler::OnHeaderCorruption ( )
protected

Definition at line 824 of file XrdClAsyncSocketHandler.cc.

825  {
826  //--------------------------------------------------------------------------
827  // We need to force a socket error so this is handled in a similar way as
828  // a stream t/o and all requests are retried
829  //--------------------------------------------------------------------------
830  pStream->ForceError( XRootDStatus( stError, errSocketError ), false, 0 );
831  }
void ForceError(XRootDStatus status, const bool hush, const uint64_t sess)
Force error.
const uint16_t errSocketError
Definition: XrdClStatus.hh:72

References XrdCl::errSocketError, XrdCl::Stream::ForceError(), pStream, and XrdCl::stError.

Referenced by OnRead().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OnRead()

bool XrdCl::AsyncSocketHandler::OnRead ( )
protected

Definition at line 561 of file XrdClAsyncSocketHandler.cc.

562  {
563  //--------------------------------------------------------------------------
564  // Make sure the response reader object exists
565  //--------------------------------------------------------------------------
566  if( !rspreader )
567  {
568  OnFault( XRootDStatus( stError, errInternal, 0, "Response reader is null." ) );
569  return false;
570  }
571 
572  //--------------------------------------------------------------------------
573  // Readout the data from the socket
574  //--------------------------------------------------------------------------
575  XRootDStatus st = rspreader->Read();
576 
577  //--------------------------------------------------------------------------
578  // Handler header corruption
579  //--------------------------------------------------------------------------
580  if( !st.IsOK() && st.code == errCorruptedHeader )
581  {
583  return false;
584  }
585 
586  //--------------------------------------------------------------------------
587  // Handler other errors
588  //--------------------------------------------------------------------------
589  if( !st.IsOK() )
590  {
591  OnFault( st );
592  return false;
593  }
594 
595  //--------------------------------------------------------------------------
596  // We are not done yet
597  //--------------------------------------------------------------------------
598  if( st.code == suRetry ) return true;
599 
600  //--------------------------------------------------------------------------
601  // We are done, reset the response reader so we can read out next message
602  //--------------------------------------------------------------------------
603  rspreader->Reset();
604  return true;
605  }
const uint16_t errInternal
Internal error.
Definition: XrdClStatus.hh:56
const uint16_t errCorruptedHeader
Definition: XrdClStatus.hh:103

References XrdCl::Status::code, XrdCl::errCorruptedHeader, XrdCl::errInternal, XrdCl::Status::IsOK(), OnFault(), OnHeaderCorruption(), rspreader, XrdCl::stError, and XrdCl::suRetry.

Referenced by EventRead().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OnReadTimeout()

bool XrdCl::AsyncSocketHandler::OnReadTimeout ( )
protected

Definition at line 802 of file XrdClAsyncSocketHandler.cc.

803  {
805  }
bool OnReadTimeout(uint16_t subStream) XRD_WARN_UNUSED_RESULT
On read timeout.

References XrdCl::Stream::OnReadTimeout(), pStream, and pSubStreamNum.

Referenced by EventRead().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OnReadWhileHandshaking()

bool XrdCl::AsyncSocketHandler::OnReadWhileHandshaking ( )
protected

Definition at line 610 of file XrdClAsyncSocketHandler.cc.

611  {
612  //--------------------------------------------------------------------------
613  // Make sure the response reader object exists
614  //--------------------------------------------------------------------------
615  if( !hsreader )
616  {
617  OnFault( XRootDStatus( stError, errInternal, 0, "Hand-shake reader is null." ) );
618  return false;
619  }
620 
621  //--------------------------------------------------------------------------
622  // Read the message and let the transport handler look at it when
623  // reading has finished
624  //--------------------------------------------------------------------------
625  XRootDStatus st = hsreader->Read();
626  if( !st.IsOK() )
627  {
629  return false;
630  }
631 
632  if( st.code != suDone )
633  return true;
634 
635  return HandleHandShake( hsreader->ReleaseMsg() );
636  }
bool HandleHandShake(std::unique_ptr< Message > msg) XRD_WARN_UNUSED_RESULT

References XrdCl::Status::code, XrdCl::errInternal, HandleHandShake(), hsreader, XrdCl::Status::IsOK(), OnFault(), OnFaultWhileHandshaking(), XrdCl::stError, and XrdCl::suDone.

Referenced by EventRead().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OnTimeoutWhileHandshaking()

bool XrdCl::AsyncSocketHandler::OnTimeoutWhileHandshaking ( )
protected

Definition at line 810 of file XrdClAsyncSocketHandler.cc.

811  {
812  time_t now = time(0);
814  {
816  return false;
817  }
818  return true;
819  }

References XrdCl::errSocketTimeout, OnFaultWhileHandshaking(), pConnectionStarted, pConnectionTimeout, and XrdCl::stError.

Referenced by EventRead(), and EventWrite().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OnTLSHandShake()

bool XrdCl::AsyncSocketHandler::OnTLSHandShake ( )
inlineprotected

Definition at line 864 of file XrdClAsyncSocketHandler.cc.

865  {
866  XRootDStatus st = DoTlsHandShake();
867  if( !st.IsOK() )
868  return false;
869  if ( st.code == suRetry )
870  return true;
871 
873  *pChannelData ) );
874  }
virtual bool HandShakeDone(HandShakeData *handShakeData, AnyObject &channelData)=0

References XrdCl::Status::code, DoTlsHandShake(), XrdCl::TransportHandler::HandShakeDone(), HandShakeNextStep(), XrdCl::Status::IsOK(), pChannelData, pHandShakeData, pTransport, and XrdCl::suRetry.

Referenced by EventRead(), and EventWrite().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OnWrite()

bool XrdCl::AsyncSocketHandler::OnWrite ( )
protected

Definition at line 469 of file XrdClAsyncSocketHandler.cc.

470  {
471  if( !reqwriter )
472  {
473  OnFault( XRootDStatus( stError, errInternal, 0, "Request writer is null." ) );
474  return false;
475  }
476  //--------------------------------------------------------------------------
477  // Let's do the writing ...
478  //--------------------------------------------------------------------------
479  XRootDStatus st = reqwriter->Write();
480 
481  //--------------------------------------------------------------------------
482  // In the case of ECONNRESET perhaps the server sent us something.
483  // To give a chance to read it in the next event poll we pass this as a
484  // retry, but return the error after the next event.
485  //--------------------------------------------------------------------------
486  if( st.code == errSocketError && st.errNo == ECONNRESET )
487  {
488  if( (DisableUplink()).IsOK() )
489  {
490  pReqConnResetError = st;
491  st = XRootDStatus( stOK, suRetry );
492  }
493  }
494  if( !st.IsOK() )
495  {
496  //------------------------------------------------------------------------
497  // We failed
498  //------------------------------------------------------------------------
499  OnFault( st );
500  return false;
501  }
502  //--------------------------------------------------------------------------
503  // We are not done yet
504  //--------------------------------------------------------------------------
505  if( st.code == suRetry) return true;
506  //--------------------------------------------------------------------------
507  // Disable the respective substream if empty
508  //--------------------------------------------------------------------------
509  reqwriter->Reset();
511  return true;
512  }
XRootDStatus DisableUplink()
Disable uplink.
void DisableIfEmpty(uint16_t subStream)
Disables respective uplink if empty.
Definition: XrdClStream.cc:794
const uint16_t stOK
Everything went OK.
Definition: XrdClStatus.hh:31

References XrdCl::Status::code, XrdCl::Stream::DisableIfEmpty(), DisableUplink(), XrdCl::errInternal, XrdCl::Status::errNo, XrdCl::errSocketError, XrdCl::Status::IsOK(), OnFault(), pReqConnResetError, pStream, pSubStreamNum, reqwriter, XrdCl::stError, XrdCl::stOK, and XrdCl::suRetry.

Referenced by EventWrite().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OnWriteTimeout()

bool XrdCl::AsyncSocketHandler::OnWriteTimeout ( )
protected

Definition at line 794 of file XrdClAsyncSocketHandler.cc.

795  {
797  }
bool OnWriteTimeout(uint16_t subStream) XRD_WARN_UNUSED_RESULT
On write timeout.

References XrdCl::Stream::OnWriteTimeout(), pStream, and pSubStreamNum.

Referenced by EventWrite().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OnWriteWhileHandshaking()

bool XrdCl::AsyncSocketHandler::OnWriteWhileHandshaking ( )
protected

Definition at line 517 of file XrdClAsyncSocketHandler.cc.

518  {
519  XRootDStatus st;
520  if( !hswriter || !hswriter->HasMsg() )
521  {
522  if( !(st = DisableUplink()).IsOK() )
523  {
525  return false;
526  }
527  return true;
528  }
529  //--------------------------------------------------------------------------
530  // Let's do the writing ...
531  //--------------------------------------------------------------------------
532  st = hswriter->Write();
533  if( !st.IsOK() )
534  {
535  //------------------------------------------------------------------------
536  // We failed
537  //------------------------------------------------------------------------
539  return false;
540  }
541  //--------------------------------------------------------------------------
542  // We are not done yet
543  //--------------------------------------------------------------------------
544  if( st.code == suRetry ) return true;
545  //--------------------------------------------------------------------------
546  // Disable the uplink
547  // Note: at this point we don't deallocate the HS message as we might need
548  // to re-send it in case of a kXR_wait response
549  //--------------------------------------------------------------------------
550  if( !(st = DisableUplink()).IsOK() )
551  {
553  return false;
554  }
555  return true;
556  }

References XrdCl::Status::code, DisableUplink(), hswriter, XrdCl::Status::IsOK(), OnFaultWhileHandshaking(), and XrdCl::suRetry.

Referenced by EventWrite().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PreClose()

XRootDStatus XrdCl::AsyncSocketHandler::PreClose ( )

Disable further event callbacks and performs close action on the transport. Will block until any currently running callback for this socket completes, unless called from within the callback itself.

Definition at line 196 of file XrdClAsyncSocketHandler.cc.

197  {
198  Log *log = DefaultEnv::GetLog();
199  log->Debug( AsyncSockMsg, "[%s] PreClosing the socket", pStreamName.c_str() );
200 
202 
203  if( pDoTransportDisc )
204  {
206  pSubStreamNum );
207  pDoTransportDisc = false;
208  }
209 
210  return XRootDStatus();
211  }
virtual void ShutdownEvents(Socket *socket)=0

References XrdCl::AsyncSockMsg, XrdCl::Log::Debug(), XrdCl::TransportHandler::Disconnect(), XrdCl::DefaultEnv::GetLog(), pChannelData, pDoTransportDisc, pPoller, pSocket, pStreamName, pSubStreamNum, pTransport, and XrdCl::Poller::ShutdownEvents().

+ Here is the call graph for this function:

◆ SendHSMsg()

bool XrdCl::AsyncSocketHandler::SendHSMsg ( )
protected

Definition at line 879 of file XrdClAsyncSocketHandler.cc.

880  {
881  if( !hswriter )
882  {
883  OnFaultWhileHandshaking( XRootDStatus( stError, errInternal, 0,
884  "HS writer object missing!" ) );
885  return false;
886  }
887  //--------------------------------------------------------------------------
888  // We only set a new HS message if this is not a replay due to kXR_wait
889  //--------------------------------------------------------------------------
890  if( !pHSWaitSeconds )
891  {
892  hswriter->Reset( pHandShakeData->out );
893  pHandShakeData->out = nullptr;
894  }
895  //--------------------------------------------------------------------------
896  // otherwise we replay the kXR_endsess request
897  //--------------------------------------------------------------------------
898  else
899  hswriter->Replay();
900  //--------------------------------------------------------------------------
901  // Enable writing so we can replay the HS message
902  //--------------------------------------------------------------------------
903  XRootDStatus st;
904  if( !(st = EnableUplink()).IsOK() )
905  {
907  return false;
908  }
909  return true;
910  }

References EnableUplink(), XrdCl::errInternal, hswriter, OnFaultWhileHandshaking(), pHandShakeData, pHSWaitSeconds, and XrdCl::stError.

Referenced by CheckHSWait(), HandleHandShake(), and HandShakeNextStep().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetAddress()

void XrdCl::AsyncSocketHandler::SetAddress ( const XrdNetAddr address)
inline

Set address.

Definition at line 72 of file XrdClAsyncSocketHandler.hh.

73  {
74  pSockAddr = address;
75  }

References pSockAddr.

◆ ToStreamName()

std::string XrdCl::AsyncSocketHandler::ToStreamName ( const URL url,
uint16_t  strmnb 
)
staticprotected

Convert Stream object and sub-stream number to stream name.

Definition at line 239 of file XrdClAsyncSocketHandler.cc.

240  {
241  std::ostringstream o;
242  o << url.GetHostId();
243  o << "." << strmnb;
244  return o.str();
245  }

References XrdCl::URL::GetHostId().

+ Here is the call graph for this function:

Member Data Documentation

◆ hsreader

std::unique_ptr<AsyncHSReader> XrdCl::AsyncSocketHandler::hsreader
protected

◆ hswriter

std::unique_ptr<AsyncHSWriter> XrdCl::AsyncSocketHandler::hswriter
protected

◆ pChannelData

AnyObject* XrdCl::AsyncSocketHandler::pChannelData
protected

◆ pConnectionStarted

time_t XrdCl::AsyncSocketHandler::pConnectionStarted
protected

Definition at line 296 of file XrdClAsyncSocketHandler.hh.

Referenced by Connect(), HandleHandShake(), and OnTimeoutWhileHandshaking().

◆ pConnectionTimeout

time_t XrdCl::AsyncSocketHandler::pConnectionTimeout
protected

Definition at line 297 of file XrdClAsyncSocketHandler.hh.

Referenced by Connect(), HandleHandShake(), and OnTimeoutWhileHandshaking().

◆ pDoTransportDisc

bool XrdCl::AsyncSocketHandler::pDoTransportDisc
protected

Definition at line 304 of file XrdClAsyncSocketHandler.hh.

Referenced by Close(), Connect(), and PreClose().

◆ pHandShakeData

std::unique_ptr<HandShakeData> XrdCl::AsyncSocketHandler::pHandShakeData
protected

◆ pHandShakeDone

bool XrdCl::AsyncSocketHandler::pHandShakeDone
protected

Definition at line 294 of file XrdClAsyncSocketHandler.hh.

Referenced by Connect(), EventRead(), EventWrite(), and HandShakeNextStep().

◆ pHSWaitSeconds

time_t XrdCl::AsyncSocketHandler::pHSWaitSeconds
protected

◆ pHSWaitStarted

time_t XrdCl::AsyncSocketHandler::pHSWaitStarted
protected

Definition at line 299 of file XrdClAsyncSocketHandler.hh.

Referenced by CheckHSWait(), Connect(), and HandleHandShake().

◆ pLastActivity

time_t XrdCl::AsyncSocketHandler::pLastActivity
protected

◆ pOpenChannel

std::shared_ptr<Channel> XrdCl::AsyncSocketHandler::pOpenChannel
protected

Definition at line 311 of file XrdClAsyncSocketHandler.hh.

Referenced by Close(), and Connect().

◆ pPoller

Poller* XrdCl::AsyncSocketHandler::pPoller
protected

◆ pReqConnResetError

XRootDStatus XrdCl::AsyncSocketHandler::pReqConnResetError
protected

Definition at line 303 of file XrdClAsyncSocketHandler.hh.

Referenced by Connect(), Event(), and OnWrite().

◆ pSockAddr

XrdNetAddr XrdCl::AsyncSocketHandler::pSockAddr
protected

◆ pSocket

◆ pStream

◆ pStreamName

std::string XrdCl::AsyncSocketHandler::pStreamName
protected

◆ pSubStreamNum

uint16_t XrdCl::AsyncSocketHandler::pSubStreamNum
protected

◆ pTimeoutResolution

time_t XrdCl::AsyncSocketHandler::pTimeoutResolution
protected

◆ pTlsHandShakeOngoing

bool XrdCl::AsyncSocketHandler::pTlsHandShakeOngoing
protected

Definition at line 302 of file XrdClAsyncSocketHandler.hh.

Referenced by Connect(), DoTlsHandShake(), EventRead(), and EventWrite().

◆ pTransport

TransportHandler* XrdCl::AsyncSocketHandler::pTransport
protected

◆ pUrl

URL XrdCl::AsyncSocketHandler::pUrl
protected

Definition at line 301 of file XrdClAsyncSocketHandler.hh.

Referenced by DoTlsHandShake().

◆ reqwriter

std::unique_ptr<AsyncMsgWriter> XrdCl::AsyncSocketHandler::reqwriter
protected

Definition at line 309 of file XrdClAsyncSocketHandler.hh.

Referenced by HandShakeNextStep(), and OnWrite().

◆ rspreader

std::unique_ptr<AsyncMsgReader> XrdCl::AsyncSocketHandler::rspreader
protected

Definition at line 307 of file XrdClAsyncSocketHandler.hh.

Referenced by HandShakeNextStep(), and OnRead().


The documentation for this class was generated from the following files: