XRootD
XrdCl::AsyncRawReader Class Reference

Object for reading out data from the kXR_read response. More...

#include <XrdClAsyncRawReader.hh>

+ Inheritance diagram for XrdCl::AsyncRawReader:
+ Collaboration diagram for XrdCl::AsyncRawReader:

Public Member Functions

 AsyncRawReader (const URL &url, const Message &request)
 
XRootDStatus GetResponse (AnyObject *&response)
 Get the response. More...
 
XRootDStatus Read (Socket &socket, uint32_t &btsret)
 
- Public Member Functions inherited from XrdCl::AsyncRawReaderIntfc
 AsyncRawReaderIntfc (const URL &url, const Message &request)
 
virtual ~AsyncRawReaderIntfc ()
 Destructor. More...
 
void SetChunkList (ChunkList *chunks)
 Sets the chunk list with user buffers. More...
 
void SetDataLength (int dlen)
 Sets response data length. More...
 

Additional Inherited Members

- Protected Types inherited from XrdCl::AsyncRawReaderIntfc
using buffer_t = std::vector< char >
 
enum  Stage {
  ReadStart ,
  ReadRdLst ,
  ReadRaw ,
  ReadDiscard ,
  ReadDone
}
 Stages of reading out a response from the socket. More...
 
- Protected Member Functions inherited from XrdCl::AsyncRawReaderIntfc
XRootDStatus ReadBytesAsync (Socket &socket, char *buffer, uint32_t toBeRead, uint32_t &bytesRead)
 
- Protected Attributes inherited from XrdCl::AsyncRawReaderIntfc
size_t chidx
 
size_t chlen
 
size_t choff
 
std::vector< ChunkStatuschstatus
 
ChunkListchunks
 
bool dataerr
 
buffer_t discardbuff
 
uint32_t dlen
 
uint32_t msgbtsrd
 
uint32_t rawbtsrd
 
Stage readstage
 
const Messagerequest
 
const URLurl
 

Detailed Description

Object for reading out data from the kXR_read response.

Definition at line 34 of file XrdClAsyncRawReader.hh.

Constructor & Destructor Documentation

◆ AsyncRawReader()

XrdCl::AsyncRawReader::AsyncRawReader ( const URL url,
const Message request 
)
inline

Constructor

Parameters
url: channel URL
request: client request

Definition at line 43 of file XrdClAsyncRawReader.hh.

43  :
45  {
46  }
AsyncRawReaderIntfc(const URL &url, const Message &request)

Member Function Documentation

◆ GetResponse()

XRootDStatus XrdCl::AsyncRawReader::GetResponse ( AnyObject *&  response)
inlinevirtual

Get the response.

Implements XrdCl::AsyncRawReaderIntfc.

Definition at line 172 of file XrdClAsyncRawReader.hh.

173  {
174  if( dataerr )
175  return XRootDStatus( stError, errInvalidResponse );
176  std::unique_ptr<AnyObject> rsp( new AnyObject() );
178  rsp->Set( GetVectorReadInfo() );
179  else
180  rsp->Set( GetChunkInfo() );
181  response = rsp.release();
182  return XRootDStatus();
183  }
@ kXR_virtReadv
Definition: XProtocol.hh:150
uint16_t GetVirtReqID() const
Get virtual request ID for the message.
const uint16_t stError
An error occurred that could potentially be retried.
Definition: XrdClStatus.hh:32
const uint16_t errInvalidResponse
Definition: XrdClStatus.hh:99

References XrdCl::AsyncRawReaderIntfc::dataerr, XrdCl::errInvalidResponse, XrdCl::Message::GetVirtReqID(), kXR_virtReadv, XrdCl::AsyncRawReaderIntfc::request, and XrdCl::stError.

+ Here is the call graph for this function:

◆ Read()

XRootDStatus XrdCl::AsyncRawReader::Read ( Socket socket,
uint32_t &  btsret 
)
inlinevirtual

Readout raw data from socket

Parameters
socket: the socket
btsret: number of bytes read
Returns
: operation status

Implements XrdCl::AsyncRawReaderIntfc.

Definition at line 55 of file XrdClAsyncRawReader.hh.

56  {
57  while( true )
58  {
59  switch( readstage )
60  {
61  //------------------------------------------------------------------
62  // Prepare to readout a new response
63  //------------------------------------------------------------------
64  case ReadStart:
65  {
66  msgbtsrd = 0;
67  chlen = ( *chunks )[0].length;
69  continue;
70  }
71 
72  //------------------------------------------------------------------
73  // Readout the raw data
74  //------------------------------------------------------------------
75  case ReadRaw:
76  {
77  //----------------------------------------------------------------
78  // Make sure we are not reading past the end of the read response
79  //----------------------------------------------------------------
80  if( msgbtsrd + chlen > dlen )
81  chlen = dlen - msgbtsrd;
82 
83  //----------------------------------------------------------------
84  // Readout the raw data from the socket
85  //----------------------------------------------------------------
86  uint32_t btsrd = 0;
87  char *buff = static_cast<char*>( ( *chunks )[chidx].buffer );
88  Status st = ReadBytesAsync( socket, buff + choff, chlen, btsrd );
89  choff += btsrd;
90  chlen -= btsrd;
91  msgbtsrd += btsrd;
92  rawbtsrd += btsrd;
93  btsret += btsrd;
94 
95  if( !st.IsOK() || st.code == suRetry )
96  return st;
97 
98  //----------------------------------------------------------------
99  // If the chunk is full, move to the next buffer
100  //----------------------------------------------------------------
101  if( choff == ( *chunks )[chidx].length )
102  {
103  ++chidx;
104  choff = 0;
105  chlen = ( chidx < chunks->size() ? ( *chunks )[chidx].length : 0 );
106  }
107  //----------------------------------------------------------------
108  // Check if there are some data left in the response to be readout
109  // from the socket.
110  //----------------------------------------------------------------
111  if( msgbtsrd < dlen )
112  {
113  //--------------------------------------------------------------
114  // We run out of space, the server has send too much data
115  //--------------------------------------------------------------
116  if( chidx >= chunks->size() )
117  {
119  continue;
120  }
121  readstage = ReadRaw;
122  continue;
123  }
124  //----------------------------------------------------------------
125  // We are done
126  //----------------------------------------------------------------
128  continue;
129  }
130 
131  //------------------------------------------------------------------
132  // We've had an error and we are in the discarding mode
133  //------------------------------------------------------------------
134  case ReadDiscard:
135  {
136  DefaultEnv::GetLog()->Error( XRootDMsg, "[%s] RawReader: Handling "
137  "response to %s: user supplied buffer is "
138  "too small for the received data.",
139  url.GetHostId().c_str(),
140  request.GetObfuscatedDescription().c_str() );
141  // Just drop the connection, we don't know if the stream is sane
142  // anymore. Recover with a reconnect.
143  return XRootDStatus( stError, errCorruptedHeader );
144  }
145 
146  //------------------------------------------------------------------
147  // Finalize the read
148  //------------------------------------------------------------------
149  case ReadDone:
150  {
151  break;
152  }
153 
154  //------------------------------------------------------------------
155  // Others should not happen
156  //------------------------------------------------------------------
157  default : return XRootDStatus( stError, errInternal );
158  }
159 
160  // just in case
161  break;
162  }
163  //----------------------------------------------------------------------
164  // We are done
165  //----------------------------------------------------------------------
166  return XRootDStatus();
167  }
XRootDStatus ReadBytesAsync(Socket &socket, char *buffer, uint32_t toBeRead, uint32_t &bytesRead)
static Log * GetLog()
Get default log.
void Error(uint64_t topic, const char *format,...)
Report an error.
Definition: XrdClLog.cc:231
const std::string & GetObfuscatedDescription() const
Get the description of the message with authz parameter obfuscated.
std::string GetHostId() const
Get the host part of the URL (user:password@host:port)
Definition: XrdClURL.hh:99
const uint16_t suRetry
Definition: XrdClStatus.hh:40
const uint64_t XRootDMsg
const uint16_t errInternal
Internal error.
Definition: XrdClStatus.hh:56
const uint16_t errCorruptedHeader
Definition: XrdClStatus.hh:103

References XrdCl::AsyncRawReaderIntfc::chidx, XrdCl::AsyncRawReaderIntfc::chlen, XrdCl::AsyncRawReaderIntfc::choff, XrdCl::AsyncRawReaderIntfc::chunks, XrdCl::Status::code, XrdCl::AsyncRawReaderIntfc::dlen, XrdCl::errCorruptedHeader, XrdCl::errInternal, XrdCl::Log::Error(), XrdCl::URL::GetHostId(), XrdCl::DefaultEnv::GetLog(), XrdCl::Message::GetObfuscatedDescription(), XrdCl::Status::IsOK(), XrdCl::AsyncRawReaderIntfc::msgbtsrd, XrdCl::AsyncRawReaderIntfc::rawbtsrd, XrdCl::AsyncRawReaderIntfc::ReadBytesAsync(), XrdCl::AsyncRawReaderIntfc::ReadDiscard, XrdCl::AsyncRawReaderIntfc::ReadDone, XrdCl::AsyncRawReaderIntfc::ReadRaw, XrdCl::AsyncRawReaderIntfc::readstage, XrdCl::AsyncRawReaderIntfc::ReadStart, XrdCl::AsyncRawReaderIntfc::request, XrdCl::stError, XrdCl::suRetry, XrdCl::AsyncRawReaderIntfc::url, and XrdCl::XRootDMsg.

+ Here is the call graph for this function:

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