XRootD
XrdCl::AsyncHSReader Class Reference

Utility class encapsulating reading hand-shake response logic. More...

#include <XrdClAsyncHSReader.hh>

+ Collaboration diagram for XrdCl::AsyncHSReader:

Public Member Functions

 AsyncHSReader (TransportHandler &xrdTransport, Socket &socket, const std::string &strmname, Stream &strm, uint16_t substrmnb)
 
XRootDStatus Read ()
 Read out the response from the socket. More...
 
std::unique_ptr< MessageReleaseMsg ()
 Transfer the received message ownership. More...
 
void Reset ()
 Reset the state of the object (makes it ready to read out next msg) More...
 

Detailed Description

Utility class encapsulating reading hand-shake response logic.

Definition at line 36 of file XrdClAsyncHSReader.hh.

Constructor & Destructor Documentation

◆ AsyncHSReader()

XrdCl::AsyncHSReader::AsyncHSReader ( TransportHandler xrdTransport,
Socket socket,
const std::string &  strmname,
Stream strm,
uint16_t  substrmnb 
)
inline

Constructor

Parameters
xrdTransport: the (xrootd) transport layer
socket: the socket with the message to be read out
strmname: stream name
strm: the stream encapsulating the connection
substrmnb: the substream number

Definition at line 48 of file XrdClAsyncHSReader.hh.

52  : readstage( ReadStart ),
53  xrdTransport( xrdTransport ),
54  socket( socket ),
55  strmname( strmname ),
56  strm( strm ),
57  substrmnb( substrmnb )
58  {
59  }

Member Function Documentation

◆ Read()

XRootDStatus XrdCl::AsyncHSReader::Read ( )
inline

Read out the response from the socket.

Definition at line 64 of file XrdClAsyncHSReader.hh.

65  {
66  Log *log = DefaultEnv::GetLog();
67 
68  while( true )
69  {
70  switch( readstage )
71  {
72  //------------------------------------------------------------------
73  // There is no incoming message currently being processed so we
74  // create a new one
75  //------------------------------------------------------------------
76  case ReadStart:
77  {
78  inmsg.reset( new Message() );
79  //----------------------------------------------------------------
80  // The next step is to read the header
81  //----------------------------------------------------------------
82  readstage = ReadHeader;
83  continue;
84  }
85  //------------------------------------------------------------------
86  // We need to read the header
87  //------------------------------------------------------------------
88  case ReadHeader:
89  {
90  XRootDStatus st = xrdTransport.GetHeader( *inmsg, &socket );
91  if( !st.IsOK() || st.code == suRetry ) return st;
92  log->Dump( AsyncSockMsg,
93  "[%s] Received message header, size: %d",
94  strmname.c_str(), inmsg->GetCursor() );
95  //----------------------------------------------------------------
96  // The next step is to read the message body
97  //----------------------------------------------------------------
98  readstage = ReadMsgBody;
99  continue;
100  }
101  //------------------------------------------------------------------
102  // We read the message to the buffer
103  //------------------------------------------------------------------
104  case ReadMsgBody:
105  {
106  XRootDStatus st = xrdTransport.GetBody( *inmsg, &socket );
107  if( !st.IsOK() || st.code == suRetry ) return st;
108  log->Dump( AsyncSockMsg, "[%s] Received a message of %d bytes",
109  strmname.c_str(), inmsg->GetSize() );
110  readstage = ReadDone;
111  return st;
112  }
113 
114  case ReadDone: return XRootDStatus();
115  }
116  // just in case ...
117  break;
118  }
119  //----------------------------------------------------------------------
120  // We are done
121  //----------------------------------------------------------------------
122  return XRootDStatus();
123  }
static Log * GetLog()
Get default log.
virtual XRootDStatus GetBody(Message &message, Socket *socket)=0
virtual XRootDStatus GetHeader(Message &message, Socket *socket)=0
const uint16_t suRetry
Definition: XrdClStatus.hh:40
const uint64_t AsyncSockMsg
XrdSysError Log
Definition: XrdConfig.cc:112

References XrdCl::AsyncSockMsg, XrdCl::Status::code, XrdCl::Log::Dump(), XrdCl::TransportHandler::GetBody(), XrdCl::TransportHandler::GetHeader(), XrdCl::DefaultEnv::GetLog(), XrdCl::Status::IsOK(), and XrdCl::suRetry.

+ Here is the call graph for this function:

◆ ReleaseMsg()

std::unique_ptr<Message> XrdCl::AsyncHSReader::ReleaseMsg ( )
inline

Transfer the received message ownership.

Definition at line 128 of file XrdClAsyncHSReader.hh.

129  {
130  readstage = ReadStart;
131  return std::move( inmsg );
132  }

◆ Reset()

void XrdCl::AsyncHSReader::Reset ( )
inline

Reset the state of the object (makes it ready to read out next msg)

Definition at line 137 of file XrdClAsyncHSReader.hh.

138  {
139  readstage = ReadStart;
140  inmsg.reset();
141  }

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