XRootD
XrdCl::AsyncSocketHandler Class Reference

#include <XrdClAsyncSocketHandler.hh>

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

Public Member Functions

 AsyncSocketHandler (const URL &url, Poller *poller, TransportHandler *transport, AnyObject *channelData, uint16_t subStreamNum, Stream *strm)
 Constructor. More...
 
 ~AsyncSocketHandler ()
 Destructor. More...
 
XRootDStatus Close ()
 Close the connection. More...
 
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...
 
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
 
std::unique_ptr< HandShakeDatapHandShakeData
 
bool pHandShakeDone
 
time_t pHSWaitSeconds
 
time_t pHSWaitStarted
 
time_t pLastActivity
 
PollerpPoller
 
XrdNetAddr pSockAddr
 
SocketpSocket
 
StreampStream
 
std::string pStreamName
 
uint16_t pSubStreamNum
 
uint16_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()

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

Constructor.

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  {
56  Env *env = DefaultEnv::GetEnv();
57 
58  int timeoutResolution = DefaultTimeoutResolution;
59  env->GetInt( "TimeoutResolution", timeoutResolution );
60  pTimeoutResolution = timeoutResolution;
61 
63  pLastActivity = time(0);
64  }
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()

XrdCl::AsyncSocketHandler::~AsyncSocketHandler ( )

Destructor.

Definition at line 69 of file XrdClAsyncSocketHandler.cc.

70  {
71  Close();
72  delete pSocket;
73  }
XRootDStatus Close()
Close the connection.

References Close(), and pSocket.

+ Here is the call graph for this function:

Member Function Documentation

◆ CheckHSWait()

bool XrdCl::AsyncSocketHandler::CheckHSWait ( )
protected

Definition at line 862 of file XrdClAsyncSocketHandler.cc.

863  {
864  time_t now = time( 0 );
865  if( now - pHSWaitStarted >= pHSWaitSeconds )
866  {
867  Log *log = DefaultEnv::GetLog();
868  log->Debug( AsyncSockMsg, "[%s] The hand-shake wait time elapsed, will "
869  "replay the endsess request.", pStreamName.c_str() );
870  if( !SendHSMsg() )
871  return false;
872  //------------------------------------------------------------------------
873  // Make sure the wait state is reset
874  //------------------------------------------------------------------------
875  pHSWaitSeconds = 0;
876  pHSWaitStarted = 0;
877  }
878  return true;
879  }
bool SendHSMsg() XRD_WARN_UNUSED_RESULT
static Log * GetLog()
Get default log.
const uint64_t AsyncSockMsg
XrdSysError Log
Definition: XrdConfig.cc:112

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.

Definition at line 186 of file XrdClAsyncSocketHandler.cc.

187  {
188  Log *log = DefaultEnv::GetLog();
189  log->Debug( AsyncSockMsg, "[%s] Closing the socket", pStreamName.c_str() );
190 
192  pSubStreamNum );
193 
195  pSocket->Close();
196  return XRootDStatus();
197  }
virtual bool RemoveSocket(Socket *socket)=0
Remove the socket.
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, 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 78 of file XrdClAsyncSocketHandler.cc.

79  {
80  Log *log = DefaultEnv::GetLog();
81  pLastActivity = pConnectionStarted = ::time(0);
82  pConnectionTimeout = timeout;
83 
84  //--------------------------------------------------------------------------
85  // Initialize the socket
86  //--------------------------------------------------------------------------
87  XRootDStatus st = pSocket->Initialize( pSockAddr.Family() );
88  if( !st.IsOK() )
89  {
90  log->Error( AsyncSockMsg, "[%s] Unable to initialize socket: %s",
91  pStreamName.c_str(), st.ToString().c_str() );
92  st.status = stFatal;
93  return st;
94  }
95 
96  //--------------------------------------------------------------------------
97  // Set the keep-alive up
98  //--------------------------------------------------------------------------
99  Env *env = DefaultEnv::GetEnv();
100 
101  int keepAlive = DefaultTCPKeepAlive;
102  env->GetInt( "TCPKeepAlive", keepAlive );
103  if( keepAlive )
104  {
105  int param = 1;
106  XRootDStatus st = pSocket->SetSockOpt( SOL_SOCKET, SO_KEEPALIVE, &param,
107  sizeof(param) );
108  if( !st.IsOK() )
109  log->Error( AsyncSockMsg, "[%s] Unable to turn on keepalive: %s",
110  pStreamName.c_str(), st.ToString().c_str() );
111 
112 #if ( defined(__linux__) || defined(__GNU__) ) && defined( TCP_KEEPIDLE ) && \
113  defined( TCP_KEEPINTVL ) && defined( TCP_KEEPCNT )
114 
115  param = DefaultTCPKeepAliveTime;
116  env->GetInt( "TCPKeepAliveTime", param );
117  st = pSocket->SetSockOpt(SOL_TCP, TCP_KEEPIDLE, &param, sizeof(param));
118  if( !st.IsOK() )
119  log->Error( AsyncSockMsg, "[%s] Unable to set keepalive time: %s",
120  pStreamName.c_str(), st.ToString().c_str() );
121 
123  env->GetInt( "TCPKeepAliveInterval", param );
124  st = pSocket->SetSockOpt(SOL_TCP, TCP_KEEPINTVL, &param, sizeof(param));
125  if( !st.IsOK() )
126  log->Error( AsyncSockMsg, "[%s] Unable to set keepalive interval: %s",
127  pStreamName.c_str(), st.ToString().c_str() );
128 
130  env->GetInt( "TCPKeepAliveProbes", param );
131  st = pSocket->SetSockOpt(SOL_TCP, TCP_KEEPCNT, &param, sizeof(param));
132  if( !st.IsOK() )
133  log->Error( AsyncSockMsg, "[%s] Unable to set keepalive probes: %s",
134  pStreamName.c_str(), st.ToString().c_str() );
135 #endif
136  }
137 
138  pHandShakeDone = false;
139  pTlsHandShakeOngoing = false;
140  pHSWaitStarted = 0;
141  pHSWaitSeconds = 0;
142 
143  //--------------------------------------------------------------------------
144  // Initiate async connection to the address
145  //--------------------------------------------------------------------------
146  char nameBuff[256];
147  pSockAddr.Format( nameBuff, sizeof(nameBuff), XrdNetAddrInfo::fmtAdv6 );
148  log->Debug( AsyncSockMsg, "[%s] Attempting connection to %s",
149  pStreamName.c_str(), nameBuff );
150 
151  st = pSocket->ConnectToAddress( pSockAddr, 0 );
152  if( !st.IsOK() )
153  {
154  log->Error( AsyncSockMsg, "[%s] Unable to initiate the connection: %s",
155  pStreamName.c_str(), st.ToString().c_str() );
156  return st;
157  }
158 
160 
161  //--------------------------------------------------------------------------
162  // We should get the ready to write event once we're really connected
163  // so we need to listen to it
164  //--------------------------------------------------------------------------
165  if( !pPoller->AddSocket( pSocket, this ) )
166  {
167  XRootDStatus st( stFatal, errPollerError );
168  pSocket->Close();
169  return st;
170  }
171 
173  {
174  XRootDStatus st( stFatal, errPollerError );
176  pSocket->Close();
177  return st;
178  }
179 
180  return XRootDStatus();
181  }
virtual bool EnableWriteNotification(Socket *socket, bool notify, uint16_t timeout=60)=0
virtual bool AddSocket(Socket *socket, SocketHandler *handler)=0
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 ConnectToAddress(const XrdNetAddr &addr, uint16_t timout=10)
Definition: XrdClSocket.cc:212
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
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::DefaultEnv::GetEnv(), XrdCl::Env::GetInt(), XrdCl::DefaultEnv::GetLog(), XrdCl::Socket::Initialize(), XrdCl::Status::IsOK(), pConnectionStarted, pConnectionTimeout, pHandShakeDone, pHSWaitSeconds, pHSWaitStarted, pLastActivity, pPoller, pSockAddr, pSocket, 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 105 of file XrdClAsyncSocketHandler.hh.

106  {
107  if( !pPoller->EnableWriteNotification( pSocket, false ) )
108  return XRootDStatus( stFatal, errPollerError );
109  return XRootDStatus();
110  }

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

Referenced by XrdCl::Tls::Connect(), 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 772 of file XrdClAsyncSocketHandler.cc.

773  {
774  Log *log = DefaultEnv::GetLog();
775  log->Debug( AsyncSockMsg, "[%s] TLS hand-shake exchange.", pStreamName.c_str() );
776 
777  XRootDStatus st;
778  if( !( st = pSocket->TlsHandShake( this, pUrl.GetHostName() ) ).IsOK() )
779  {
780  pTlsHandShakeOngoing = false;
782  return st;
783  }
784 
785  if( st.code == suRetry )
786  {
787  pTlsHandShakeOngoing = true;
788  return st;
789  }
790 
791  pTlsHandShakeOngoing = false;
792  log->Info( AsyncSockMsg, "[%s] TLS hand-shake done.", pStreamName.c_str() );
793 
794  return st;
795  }
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 95 of file XrdClAsyncSocketHandler.hh.

96  {
98  return XRootDStatus( stFatal, errPollerError );
99  return XRootDStatus();
100  }

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 210 of file XrdClAsyncSocketHandler.cc.

211  {
212  //--------------------------------------------------------------------------
213  // First check if the socket itself wants to apply some mapping on the
214  // event. E.g. in case of TLS socket it might want to map read events to
215  // write events and vice-versa.
216  //--------------------------------------------------------------------------
217  type = pSocket->MapEvent( type );
218 
219  //--------------------------------------------------------------------------
220  // Handle any read or write events. If any of the handlers indicate an error
221  // we will have been disconnected. A disconnection may cause the current
222  // object to be asynchronously reused or deleted, so we return immediately.
223  //--------------------------------------------------------------------------
224  if( !EventRead( type ) )
225  return;
226 
227  if( !EventWrite( type ) )
228  return;
229  }
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

References EventRead(), EventWrite(), XrdCl::Socket::MapEvent(), and pSocket.

+ Here is the call graph for this function:

◆ EventRead()

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

Definition at line 234 of file XrdClAsyncSocketHandler.cc.

235  {
236  //--------------------------------------------------------------------------
237  // Read event
238  //--------------------------------------------------------------------------
239  if( type & ReadyToRead )
240  {
241  pLastActivity = time(0);
243  return OnTLSHandShake();
244 
245  if( likely( pHandShakeDone ) )
246  return OnRead();
247 
248  return OnReadWhileHandshaking();
249  }
250 
251  //--------------------------------------------------------------------------
252  // Read timeout
253  //--------------------------------------------------------------------------
254  else if( type & ReadTimeOut )
255  {
256  if( pHSWaitSeconds )
257  {
258  if( !CheckHSWait() )
259  return false;
260  }
261 
262  if( likely( pHandShakeDone ) )
263  return OnReadTimeout();
264 
265  return OnTimeoutWhileHandshaking();
266  }
267 
268  return true;
269  }
#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:42
@ ReadyToRead
New data has arrived.
Definition: XrdClPoller.hh:41

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 274 of file XrdClAsyncSocketHandler.cc.

275  {
276  //--------------------------------------------------------------------------
277  // Write event
278  //--------------------------------------------------------------------------
279  if( type & ReadyToWrite )
280  {
281  pLastActivity = time(0);
283  return OnConnectionReturn();
284 
285  //------------------------------------------------------------------------
286  // Make sure we are not writing anything if we have been told to wait.
287  //------------------------------------------------------------------------
288  if( pHSWaitSeconds != 0 )
289  return true;
290 
292  return OnTLSHandShake();
293 
294  if( likely( pHandShakeDone ) )
295  return OnWrite();
296 
297  return OnWriteWhileHandshaking();
298  }
299 
300  //--------------------------------------------------------------------------
301  // Write timeout
302  //--------------------------------------------------------------------------
303  else if( type & WriteTimeOut )
304  {
305  if( likely( pHandShakeDone ) )
306  return OnWriteTimeout();
307 
308  return OnTimeoutWhileHandshaking();
309  }
310 
311  return true;
312  }
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:43
@ WriteTimeOut
Write timeout.
Definition: XrdClPoller.hh:44
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 72 of file XrdClAsyncSocketHandler.hh.

73  {
74  return pSockAddr;
75  }

References pSockAddr.

◆ GetHostName()

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

Get hostname.

Definition at line 904 of file XrdClAsyncSocketHandler.cc.

905  {
906  const char *cstr = pSockAddr.Name();
907  if( !cstr )
908  return std::string();
909  return cstr;
910  }
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 894 of file XrdClAsyncSocketHandler.cc.

895  {
896  char nameBuff[256];
897  pSockAddr.Format( nameBuff, sizeof(nameBuff), XrdNetAddrInfo::fmtAddr, XrdNetAddrInfo::noPort );
898  return nameBuff;
899  }
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 884 of file XrdClAsyncSocketHandler.cc.

885  {
886  std::string ipstack( ( pSockAddr.isIPType( XrdNetAddr::IPType::IPv6 ) &&
887  !pSockAddr.isMapped() ) ? "IPv6" : "IPv4" );
888  return ipstack;
889  }
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 123 of file XrdClAsyncSocketHandler.hh.

124  {
125  return pLastActivity;
126  }

References pLastActivity.

◆ GetStreamName()

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

Get stream name.

Definition at line 115 of file XrdClAsyncSocketHandler.hh.

116  {
117  return pStreamName;
118  }

References pStreamName.

◆ HandleHandShake()

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

Definition at line 577 of file XrdClAsyncSocketHandler.cc.

578  {
579  //--------------------------------------------------------------------------
580  // OK, we have a new message, let's deal with it;
581  //--------------------------------------------------------------------------
582  pHandShakeData->in = msg.release();
583  XRootDStatus st = pTransport->HandShake( pHandShakeData.get(), *pChannelData );
584 
585  //--------------------------------------------------------------------------
586  // Deal with wait responses
587  //--------------------------------------------------------------------------
588  kXR_int32 waitSeconds = HandleWaitRsp( pHandShakeData->in );
589 
590  delete pHandShakeData->in;
591  pHandShakeData->in = 0;
592 
593  if( !st.IsOK() )
594  {
596  return false;
597  }
598 
599  if( st.code == suRetry )
600  {
601  //------------------------------------------------------------------------
602  // We are handling a wait response and the transport handler told
603  // as to retry the request
604  //------------------------------------------------------------------------
605  if( waitSeconds >=0 )
606  {
607  time_t resendTime = ::time( 0 ) + waitSeconds;
608  if( resendTime > pConnectionStarted + pConnectionTimeout )
609  {
610  Log *log = DefaultEnv::GetLog();
611  log->Error( AsyncSockMsg,
612  "[%s] Won't retry kXR_endsess request because would"
613  "reach connection timeout.",
614  pStreamName.c_str() );
615 
617  return false;
618  }
619  else
620  {
621  //--------------------------------------------------------------------
622  // We need to wait before replaying the request
623  //--------------------------------------------------------------------
624  Log *log = DefaultEnv::GetLog();
625  log->Debug( AsyncSockMsg, "[%s] Received a wait response to endsess request, "
626  "will wait for %d seconds before replaying the endsess request",
627  pStreamName.c_str(), waitSeconds );
628  pHSWaitStarted = time( 0 );
629  pHSWaitSeconds = waitSeconds;
630  }
631  return true;
632  }
633  //------------------------------------------------------------------------
634  // We are re-sending a protocol request
635  //------------------------------------------------------------------------
636  else if( pHandShakeData->out )
637  {
638  return SendHSMsg();
639  }
640  }
641 
642  //--------------------------------------------------------------------------
643  // If now is the time to enable encryption
644  //--------------------------------------------------------------------------
645  if( !pSocket->IsEncrypted() &&
647  {
648  XRootDStatus st = DoTlsHandShake();
649  if( !st.IsOK() )
650  return false;
651  if ( st.code == suRetry )
652  return true;
653  }
654 
655  //--------------------------------------------------------------------------
656  // Now prepare the next step of the hand-shake procedure
657  //--------------------------------------------------------------------------
658  return HandShakeNextStep( st.IsOK() && st.code == suDone );
659  }
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 848 of file XrdClAsyncSocketHandler.cc.

849  {
850  // It would be more coherent if this could be done in the
851  // transport layer, unfortunately the API does not allow it.
852  kXR_int32 waitSeconds = -1;
853  ServerResponse *rsp = (ServerResponse*)msg->GetBuffer();
854  if( rsp->hdr.status == kXR_wait )
855  waitSeconds = rsp->body.wait.seconds;
856  return waitSeconds;
857  }
union ServerResponse::@0 body
@ kXR_wait
Definition: XProtocol.hh:905
ServerResponseHeader hdr
Definition: XProtocol.hh:1287

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 664 of file XrdClAsyncSocketHandler.cc.

665  {
666  //--------------------------------------------------------------------------
667  // We successfully proceeded to the next step
668  //--------------------------------------------------------------------------
669  ++pHandShakeData->step;
670 
671  //--------------------------------------------------------------------------
672  // The hand shake process is done
673  //--------------------------------------------------------------------------
674  if( done )
675  {
676  pHandShakeData.reset();
677  hswriter.reset();
678  hsreader.reset();
679  //------------------------------------------------------------------------
680  // Initialize the request writer & reader
681  //------------------------------------------------------------------------
682  reqwriter.reset( new AsyncMsgWriter( *pTransport, *pSocket, pStreamName, *pStream, pSubStreamNum, *pChannelData ) );
683  rspreader.reset( new AsyncMsgReader( *pTransport, *pSocket, pStreamName, *pStream, pSubStreamNum ) );
684  XRootDStatus st;
685  if( !(st = EnableUplink()).IsOK() )
686  {
688  return false;
689  }
690  pHandShakeDone = true;
692  }
693  //--------------------------------------------------------------------------
694  // The transport handler gave us something to write
695  //--------------------------------------------------------------------------
696  else if( pHandShakeData->out )
697  {
698  return SendHSMsg();
699  }
700  return true;
701  }
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:610

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 317 of file XrdClAsyncSocketHandler.cc.

318  {
319  //--------------------------------------------------------------------------
320  // Check whether we were able to connect
321  //--------------------------------------------------------------------------
322  Log *log = DefaultEnv::GetLog();
323  log->Debug( AsyncSockMsg, "[%s] Async connection call returned",
324  pStreamName.c_str() );
325 
326  int errorCode = 0;
327  socklen_t optSize = sizeof( errorCode );
328  XRootDStatus st = pSocket->GetSockOpt( SOL_SOCKET, SO_ERROR, &errorCode,
329  &optSize );
330 
331  //--------------------------------------------------------------------------
332  // This is an internal error really (either logic or system fault),
333  // so we call it a day and don't retry
334  //--------------------------------------------------------------------------
335  if( !st.IsOK() )
336  {
337  log->Error( AsyncSockMsg, "[%s] Unable to get the status of the "
338  "connect operation: %s", pStreamName.c_str(),
339  XrdSysE2T( errno ) );
341  XRootDStatus( stFatal, errSocketOptError, errno ) );
342  return false;
343  }
344 
345  //--------------------------------------------------------------------------
346  // We were unable to connect
347  //--------------------------------------------------------------------------
348  if( errorCode )
349  {
350  log->Error( AsyncSockMsg, "[%s] Unable to connect: %s",
351  pStreamName.c_str(), XrdSysE2T( errorCode ) );
353  XRootDStatus( stError, errConnectionError ) );
354  return false;
355  }
357 
358  //--------------------------------------------------------------------------
359  // Cork the socket
360  //--------------------------------------------------------------------------
361  st = pSocket->Cork();
362  if( !st.IsOK() )
363  {
365  return false;
366  }
367 
368  //--------------------------------------------------------------------------
369  // Initialize the handshake
370  //--------------------------------------------------------------------------
371  pHandShakeData.reset( new HandShakeData( pStream->GetURL(),
372  pSubStreamNum ) );
373  pHandShakeData->serverAddr = pSocket->GetServerAddress();
374  pHandShakeData->clientName = pSocket->GetSockName();
375  pHandShakeData->streamName = pStreamName;
376 
378  if( !st.IsOK() )
379  {
380  log->Error( AsyncSockMsg, "[%s] Connection negotiation failed",
381  pStreamName.c_str() );
383  return false;
384  }
385 
386  if( st.code != suRetry )
387  ++pHandShakeData->step;
388 
389  //--------------------------------------------------------------------------
390  // Initialize the hand-shake reader and writer
391  //--------------------------------------------------------------------------
392  hswriter.reset( new AsyncHSWriter( *pSocket, pStreamName ) );
393  hsreader.reset( new AsyncHSReader( *pTransport, *pSocket, pStreamName, *pStream, pSubStreamNum ) );
394 
395  //--------------------------------------------------------------------------
396  // Transport has given us something to send
397  //--------------------------------------------------------------------------
398  if( pHandShakeData->out )
399  {
400  hswriter->Reset( pHandShakeData->out );
401  pHandShakeData->out = nullptr;
402  }
403 
404  //--------------------------------------------------------------------------
405  // Listen to what the server has to say
406  //--------------------------------------------------------------------------
408  {
410  XRootDStatus( stFatal, errPollerError ) );
411  return false;
412  }
413  return true;
414  }
const char * XrdSysE2T(int errcode)
Definition: XrdSysE2T.cc:104
virtual bool EnableReadNotification(Socket *socket, bool notify, uint16_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:709
const URL * GetURL() const
Get the URL.
Definition: XrdClStream.hh:157
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 706 of file XrdClAsyncSocketHandler.cc.

707  {
708  Log *log = DefaultEnv::GetLog();
709  log->Error( AsyncSockMsg, "[%s] Socket error encountered: %s",
710  pStreamName.c_str(), st.ToString().c_str() );
711 
712  pStream->OnError( pSubStreamNum, st );
713  }
void OnError(uint16_t subStream, XRootDStatus status)
On error.
Definition: XrdClStream.cc:809

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

Referenced by 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 718 of file XrdClAsyncSocketHandler.cc.

719  {
720  Log *log = DefaultEnv::GetLog();
721  log->Error( AsyncSockMsg, "[%s] Socket error while handshaking: %s",
722  pStreamName.c_str(), st.ToString().c_str() );
723 
725  }

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 760 of file XrdClAsyncSocketHandler.cc.

761  {
762  //--------------------------------------------------------------------------
763  // We need to force a socket error so this is handled in a similar way as
764  // a stream t/o and all requests are retried
765  //--------------------------------------------------------------------------
766  pStream->ForceError( XRootDStatus( stError, errSocketError ) );
767  }
void ForceError(XRootDStatus status, bool hush=false)
Force error.
Definition: XrdClStream.cc:913
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 497 of file XrdClAsyncSocketHandler.cc.

498  {
499  //--------------------------------------------------------------------------
500  // Make sure the response reader object exists
501  //--------------------------------------------------------------------------
502  if( !rspreader )
503  {
504  OnFault( XRootDStatus( stError, errInternal, 0, "Response reader is null." ) );
505  return false;
506  }
507 
508  //--------------------------------------------------------------------------
509  // Readout the data from the socket
510  //--------------------------------------------------------------------------
511  XRootDStatus st = rspreader->Read();
512 
513  //--------------------------------------------------------------------------
514  // Handler header corruption
515  //--------------------------------------------------------------------------
516  if( !st.IsOK() && st.code == errCorruptedHeader )
517  {
519  return false;
520  }
521 
522  //--------------------------------------------------------------------------
523  // Handler other errors
524  //--------------------------------------------------------------------------
525  if( !st.IsOK() )
526  {
527  OnFault( st );
528  return false;
529  }
530 
531  //--------------------------------------------------------------------------
532  // We are not done yet
533  //--------------------------------------------------------------------------
534  if( st.code == suRetry ) return true;
535 
536  //--------------------------------------------------------------------------
537  // We are done, reset the response reader so we can read out next message
538  //--------------------------------------------------------------------------
539  rspreader->Reset();
540  return true;
541  }
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 738 of file XrdClAsyncSocketHandler.cc.

739  {
741  }
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 546 of file XrdClAsyncSocketHandler.cc.

547  {
548  //--------------------------------------------------------------------------
549  // Make sure the response reader object exists
550  //--------------------------------------------------------------------------
551  if( !hsreader )
552  {
553  OnFault( XRootDStatus( stError, errInternal, 0, "Hand-shake reader is null." ) );
554  return false;
555  }
556 
557  //--------------------------------------------------------------------------
558  // Read the message and let the transport handler look at it when
559  // reading has finished
560  //--------------------------------------------------------------------------
561  XRootDStatus st = hsreader->Read();
562  if( !st.IsOK() )
563  {
565  return false;
566  }
567 
568  if( st.code != suDone )
569  return true;
570 
571  return HandleHandShake( hsreader->ReleaseMsg() );
572  }
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 746 of file XrdClAsyncSocketHandler.cc.

747  {
748  time_t now = time(0);
750  {
752  return false;
753  }
754  return true;
755  }

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 800 of file XrdClAsyncSocketHandler.cc.

801  {
802  XRootDStatus st = DoTlsHandShake();
803  if( !st.IsOK() )
804  return false;
805  if ( st.code == suRetry )
806  return true;
807 
809  *pChannelData ) );
810  }
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 419 of file XrdClAsyncSocketHandler.cc.

420  {
421  if( !reqwriter )
422  {
423  OnFault( XRootDStatus( stError, errInternal, 0, "Request writer is null." ) );
424  return false;
425  }
426  //--------------------------------------------------------------------------
427  // Let's do the writing ...
428  //--------------------------------------------------------------------------
429  XRootDStatus st = reqwriter->Write();
430  if( !st.IsOK() )
431  {
432  //------------------------------------------------------------------------
433  // We failed
434  //------------------------------------------------------------------------
435  OnFault( st );
436  return false;
437  }
438  //--------------------------------------------------------------------------
439  // We are not done yet
440  //--------------------------------------------------------------------------
441  if( st.code == suRetry) return true;
442  //--------------------------------------------------------------------------
443  // Disable the respective substream if empty
444  //--------------------------------------------------------------------------
445  reqwriter->Reset();
447  return true;
448  }
void DisableIfEmpty(uint16_t subStream)
Disables respective uplink if empty.
Definition: XrdClStream.cc:568

References XrdCl::Status::code, XrdCl::Stream::DisableIfEmpty(), XrdCl::errInternal, XrdCl::Status::IsOK(), OnFault(), pStream, pSubStreamNum, reqwriter, XrdCl::stError, 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 730 of file XrdClAsyncSocketHandler.cc.

731  {
733  }
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 453 of file XrdClAsyncSocketHandler.cc.

454  {
455  XRootDStatus st;
456  if( !hswriter || !hswriter->HasMsg() )
457  {
458  if( !(st = DisableUplink()).IsOK() )
459  {
461  return false;
462  }
463  return true;
464  }
465  //--------------------------------------------------------------------------
466  // Let's do the writing ...
467  //--------------------------------------------------------------------------
468  st = hswriter->Write();
469  if( !st.IsOK() )
470  {
471  //------------------------------------------------------------------------
472  // We failed
473  //------------------------------------------------------------------------
475  return false;
476  }
477  //--------------------------------------------------------------------------
478  // We are not done yet
479  //--------------------------------------------------------------------------
480  if( st.code == suRetry ) return true;
481  //--------------------------------------------------------------------------
482  // Disable the uplink
483  // Note: at this point we don't deallocate the HS message as we might need
484  // to re-send it in case of a kXR_wait response
485  //--------------------------------------------------------------------------
486  if( !(st = DisableUplink()).IsOK() )
487  {
489  return false;
490  }
491  return true;
492  }
XRootDStatus DisableUplink()
Disable uplink.

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:

◆ SendHSMsg()

bool XrdCl::AsyncSocketHandler::SendHSMsg ( )
protected

Definition at line 815 of file XrdClAsyncSocketHandler.cc.

816  {
817  if( !hswriter )
818  {
819  OnFaultWhileHandshaking( XRootDStatus( stError, errInternal, 0,
820  "HS writer object missing!" ) );
821  return false;
822  }
823  //--------------------------------------------------------------------------
824  // We only set a new HS message if this is not a replay due to kXR_wait
825  //--------------------------------------------------------------------------
826  if( !pHSWaitSeconds )
827  {
828  hswriter->Reset( pHandShakeData->out );
829  pHandShakeData->out = nullptr;
830  }
831  //--------------------------------------------------------------------------
832  // otherwise we replay the kXR_endsess request
833  //--------------------------------------------------------------------------
834  else
835  hswriter->Replay();
836  //--------------------------------------------------------------------------
837  // Enable writing so we can replay the HS message
838  //--------------------------------------------------------------------------
839  XRootDStatus st;
840  if( !(st = EnableUplink()).IsOK() )
841  {
843  return false;
844  }
845  return true;
846  }

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 64 of file XrdClAsyncSocketHandler.hh.

65  {
66  pSockAddr = address;
67  }

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 199 of file XrdClAsyncSocketHandler.cc.

200  {
201  std::ostringstream o;
202  o << url.GetHostId();
203  o << "." << strmnb;
204  return o.str();
205  }

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 279 of file XrdClAsyncSocketHandler.hh.

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

◆ pConnectionTimeout

time_t XrdCl::AsyncSocketHandler::pConnectionTimeout
protected

Definition at line 280 of file XrdClAsyncSocketHandler.hh.

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

◆ pHandShakeData

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

◆ pHandShakeDone

bool XrdCl::AsyncSocketHandler::pHandShakeDone
protected

Definition at line 277 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 282 of file XrdClAsyncSocketHandler.hh.

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

◆ pLastActivity

time_t XrdCl::AsyncSocketHandler::pLastActivity
protected

◆ pPoller

Poller* XrdCl::AsyncSocketHandler::pPoller
protected

◆ pSockAddr

XrdNetAddr XrdCl::AsyncSocketHandler::pSockAddr
protected

◆ pSocket

◆ pStream

Stream* XrdCl::AsyncSocketHandler::pStream
protected

◆ pStreamName

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

◆ pSubStreamNum

uint16_t XrdCl::AsyncSocketHandler::pSubStreamNum
protected

◆ pTimeoutResolution

uint16_t XrdCl::AsyncSocketHandler::pTimeoutResolution
protected

◆ pTlsHandShakeOngoing

bool XrdCl::AsyncSocketHandler::pTlsHandShakeOngoing
protected

Definition at line 285 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 284 of file XrdClAsyncSocketHandler.hh.

Referenced by DoTlsHandShake().

◆ reqwriter

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

Definition at line 290 of file XrdClAsyncSocketHandler.hh.

Referenced by HandShakeNextStep(), and OnWrite().

◆ rspreader

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

Definition at line 288 of file XrdClAsyncSocketHandler.hh.

Referenced by HandShakeNextStep(), and OnRead().


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