XRootD
XrdCl::AsyncMsgWriter Class Reference

Utility class encapsulating writing request logic. More...

#include <XrdClAsyncMsgWriter.hh>

+ Collaboration diagram for XrdCl::AsyncMsgWriter:

Public Member Functions

 AsyncMsgWriter (TransportHandler &xrdTransport, Socket &socket, const std::string &strmname, Stream &strm, uint16_t substrmnb, AnyObject &chdata)
 
void Reset ()
 Reset the state of the object (makes it ready to read out next msg) More...
 
XRootDStatus Write ()
 Write the request into the socket. More...
 

Detailed Description

Utility class encapsulating writing request logic.

Definition at line 37 of file XrdClAsyncMsgWriter.hh.

Constructor & Destructor Documentation

◆ AsyncMsgWriter()

XrdCl::AsyncMsgWriter::AsyncMsgWriter ( TransportHandler xrdTransport,
Socket socket,
const std::string &  strmname,
Stream strm,
uint16_t  substrmnb,
AnyObject chdata 
)
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 49 of file XrdClAsyncMsgWriter.hh.

54  : writestage( WriteStart ),
55  xrdTransport( xrdTransport ),
56  socket( socket ),
57  strmname( strmname ),
58  strm( strm ),
59  substrmnb( substrmnb ),
60  chdata( chdata ),
61  outmsg( nullptr ),
62  outmsgsize( 0 ),
63  outhandler( nullptr )
64  {
65  }

Member Function Documentation

◆ Reset()

void XrdCl::AsyncMsgWriter::Reset ( )
inline

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

Definition at line 70 of file XrdClAsyncMsgWriter.hh.

71  {
72  writestage = WriteStart;
73  outmsg = nullptr;
74  outmsgsize = 0;;
75  outhandler = nullptr;
76  outsign.reset();
77  }

◆ Write()

XRootDStatus XrdCl::AsyncMsgWriter::Write ( )
inline

Write the request into the socket.

Definition at line 82 of file XrdClAsyncMsgWriter.hh.

83  {
84  Log *log = DefaultEnv::GetLog();
85  while( true )
86  {
87  switch( writestage )
88  {
89  //------------------------------------------------------------------
90  // Pick up a message if we're not in process of writing something
91  //------------------------------------------------------------------
92  case WriteStart:
93  {
94  std::pair<Message *, MsgHandler *> toBeSent;
95  toBeSent = strm.OnReadyToWrite( substrmnb );
96  outmsg = toBeSent.first;
97  outhandler = toBeSent.second;
98  if( !outmsg ) return XRootDStatus( stOK, suAlreadyDone );
99 
100  outmsg->SetCursor( 0 );
101  outmsgsize = outmsg->GetSize();
102 
103  //----------------------------------------------------------------
104  // Secure the message if necessary
105  //----------------------------------------------------------------
106  Message *signature = nullptr;
107  XRootDStatus st = xrdTransport.GetSignature( outmsg, signature, chdata );
108  if( !st.IsOK() ) return st;
109  outsign.reset( signature );
110 
111  if( outsign )
112  outmsgsize += outsign->GetSize();
113 
114  //----------------------------------------------------------------
115  // The next step is to write the signature
116  //----------------------------------------------------------------
117  writestage = WriteSign;
118  continue;
119  }
120  //------------------------------------------------------------------
121  // First write the signature (if there is one)
122  //------------------------------------------------------------------
123  case WriteSign:
124  {
125  //----------------------------------------------------------------
126  // If there is a signature for the request send it over the socket
127  //----------------------------------------------------------------
128  if( outsign )
129  {
130  XRootDStatus st = socket.Send( *outsign, strmname );
131  if( !st.IsOK() || st.code == suRetry ) return st;
132  }
133  //----------------------------------------------------------------
134  // The next step is to write the signature
135  //----------------------------------------------------------------
136  writestage = WriteRequest;
137  continue;
138  }
139  //------------------------------------------------------------------
140  // Then write the request itself
141  //------------------------------------------------------------------
142  case WriteRequest:
143  {
144  XRootDStatus st = socket.Send( *outmsg, strmname );
145  if( !st.IsOK() || st.code == suRetry ) return st;
146  //----------------------------------------------------------------
147  // The next step is to write the signature
148  //----------------------------------------------------------------
149  writestage = WriteRawData;
150  continue;
151  }
152  //------------------------------------------------------------------
153  // And then write the raw data (if any)
154  //------------------------------------------------------------------
155  case WriteRawData:
156  {
157  if( outhandler->IsRaw() )
158  {
159  uint32_t wrtcnt = 0;
160  XRootDStatus st = outhandler->WriteMessageBody( &socket, wrtcnt );
161  if( !st.IsOK() || st.code == suRetry ) return st;
162  outmsgsize += wrtcnt;
163  log->Dump( AsyncSockMsg, "[%s] Wrote %d bytes of raw data of message"
164  "(%p) body.", strmname.c_str(), wrtcnt, outmsg );
165  }
166  //----------------------------------------------------------------
167  // The next step is to finalize the write operation
168  //----------------------------------------------------------------
169  writestage = WriteDone;
170  continue;
171  }
172  //------------------------------------------------------------------
173  // Finally, finalize the write operation
174  //------------------------------------------------------------------
175  case WriteDone:
176  {
177  XRootDStatus st = socket.Flash();
178  if( !st.IsOK() )
179  {
180  log->Error( AsyncSockMsg, "[%s] Unable to flash the socket: %s",
181  strmname.c_str(), XrdSysE2T( st.errNo ) );
182  return st;
183  }
184 
185  log->Dump( AsyncSockMsg, "[%s] Successfully sent message: %s (%p).",
186  strmname.c_str(), outmsg->GetObfuscatedDescription().c_str(), outmsg );
187 
188  strm.OnMessageSent( substrmnb, outmsg, outmsgsize );
189  return XRootDStatus();
190  }
191  }
192  // just in case ...
193  break;
194  }
195  //----------------------------------------------------------------------
196  // We are done
197  //----------------------------------------------------------------------
198  return XRootDStatus();
199  }
const char * XrdSysE2T(int errcode)
Definition: XrdSysE2T.cc:104
void SetCursor(uint32_t cursor)
Set the cursor.
Definition: XrdClBuffer.hh:148
uint32_t GetSize() const
Get the size of the message.
Definition: XrdClBuffer.hh:132
static Log * GetLog()
Get default log.
const std::string & GetObfuscatedDescription() const
Get the description of the message with authz parameter obfuscated.
virtual XRootDStatus WriteMessageBody(Socket *socket, uint32_t &bytesWritten)
virtual bool IsRaw() const
virtual XRootDStatus Send(const char *buffer, size_t size, int &bytesWritten)
Definition: XrdClSocket.cc:461
XRootDStatus Flash()
Definition: XrdClSocket.cc:818
void OnMessageSent(uint16_t subStream, Message *msg, uint32_t bytesSent)
Definition: XrdClStream.cc:584
std::pair< Message *, MsgHandler * > OnReadyToWrite(uint16_t subStream)
Definition: XrdClStream.cc:545
virtual Status GetSignature(Message *toSign, Message *&sign, AnyObject &channelData)=0
Get signature for given message.
const uint16_t suRetry
Definition: XrdClStatus.hh:40
const uint16_t stOK
Everything went OK.
Definition: XrdClStatus.hh:31
const uint64_t AsyncSockMsg
const uint16_t suAlreadyDone
Definition: XrdClStatus.hh:42
XrdSysError Log
Definition: XrdConfig.cc:112

References XrdCl::AsyncSockMsg, XrdCl::Status::code, XrdCl::Log::Dump(), XrdCl::Status::errNo, XrdCl::Log::Error(), XrdCl::Socket::Flash(), XrdCl::DefaultEnv::GetLog(), XrdCl::Message::GetObfuscatedDescription(), XrdCl::TransportHandler::GetSignature(), XrdCl::Buffer::GetSize(), XrdCl::Status::IsOK(), XrdCl::MsgHandler::IsRaw(), XrdCl::Stream::OnMessageSent(), XrdCl::Stream::OnReadyToWrite(), XrdCl::Socket::Send(), XrdCl::Buffer::SetCursor(), XrdCl::stOK, XrdCl::suAlreadyDone, XrdCl::suRetry, XrdCl::MsgHandler::WriteMessageBody(), and XrdSysE2T().

+ Here is the call graph for this function:

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