xrootd
Loading...
Searching...
No Matches
XrdClAsyncRawReaderIntfc.hh
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
3// Author: Michal Simon <michal.simon@cern.ch>
4//------------------------------------------------------------------------------
5// XRootD is free software: you can redistribute it and/or modify
6// it under the terms of the GNU Lesser General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// XRootD is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
17//------------------------------------------------------------------------------
18
19#ifndef SRC_XRDCL_XRDCLASYNCRAWREADERINTFC_HH_
20#define SRC_XRDCL_XRDCLASYNCRAWREADERINTFC_HH_
21
23#include "XrdCl/XrdClSocket.hh"
25#include "XrdCl/XrdClLog.hh"
27
28namespace XrdCl
29{
30
31 //----------------------------------------------------------------------------
33 //----------------------------------------------------------------------------
35 {
36 public:
37
40 url( url ),
42 chunks( nullptr ),
43 dlen( 0 ),
44 msgbtsrd( 0 ),
45 rawbtsrd( 0 ),
46 chidx( 0 ),
47 choff( 0 ),
48 chlen( 0 ),
49 dataerr( false )
50 {
51 }
52
53 //------------------------------------------------------------------------
55 //------------------------------------------------------------------------
57 {
58 }
59
60 //------------------------------------------------------------------------
62 //------------------------------------------------------------------------
63 void SetDataLength( int dlen )
64 {
65 this->dlen = dlen;
66 this->readstage = ReadStart;
67 }
68
69 //------------------------------------------------------------------------
71 //------------------------------------------------------------------------
73 {
74 this->chunks = chunks;
75 if( chunks )
76 this->chstatus.resize( chunks->size() );
77 }
78
79 //------------------------------------------------------------------------
85 //------------------------------------------------------------------------
86 virtual XRootDStatus Read( Socket &socket, uint32_t &btsret ) = 0;
87
88 //------------------------------------------------------------------------
90 //------------------------------------------------------------------------
91 virtual XRootDStatus GetResponse( AnyObject *&response ) = 0;
92
93 protected:
94
95 //--------------------------------------------------------------------------
96 // Read a buffer asynchronously
97 //--------------------------------------------------------------------------
99 char *buffer,
100 uint32_t toBeRead,
101 uint32_t &bytesRead )
102 {
103 size_t shift = 0;
104 while( toBeRead > 0 )
105 {
106 int btsRead = 0;
107 Status status = socket.Read( buffer + shift, toBeRead, btsRead );
108
109 if( !status.IsOK() || status.code == suRetry )
110 return status;
111
112 bytesRead += btsRead;
113 toBeRead -= btsRead;
114 shift += btsRead;
115 }
116 return XRootDStatus( stOK, suDone );
117 }
118
119 //------------------------------------------------------------------------
120 // Helper struct for async reading of chunks
121 //------------------------------------------------------------------------
123 {
124 ChunkStatus(): sizeerr( false ), done( false ) {}
126 bool done;
127 };
128
129 //------------------------------------------------------------------------
130 // internal buffer type
131 //------------------------------------------------------------------------
132 using buffer_t = std::vector<char>;
133
134 //------------------------------------------------------------------------
136 //------------------------------------------------------------------------
137 enum Stage
138 {
139 ReadStart, //< the next step is to initialize the read
140 ReadRdLst, //< the next step is to read the read_list
141 ReadRaw, //< the next step is to read the raw data
142 ReadDiscard, //< there was an error, we are in discard mode
143 ReadDone //< the next step is to finalize the read
144 };
145
146 //------------------------------------------------------------------------
147 // Current read stage
148 //------------------------------------------------------------------------
150
151 //------------------------------------------------------------------------
152 // The context of the read operation
153 //------------------------------------------------------------------------
154 const URL &url; //< for logging purposes
155 const Message &request; //< client request
156
157 ChunkList *chunks; //< list of data chunks to be filled with user data
158 std::vector<ChunkStatus> chstatus; //< status per chunk
159 uint32_t dlen; //< size of the data in the message
160 uint32_t msgbtsrd; //< number of bytes read out from the socket for the current message
161 uint32_t rawbtsrd; //< total number of bytes read out from the socket (raw data only)
162
163 size_t chidx; //< index of the current data buffer
164 size_t choff; //< offset within the current buffer
165 size_t chlen; //< bytes left to be readout into the current chunk
166
167 buffer_t discardbuff; //< buffer for discarding data in case of an error
168 bool dataerr; //< true if the server send us too much data, false otherwise
169 };
170
171}
172
173#endif /* SRC_XRDCL_XRDCLASYNCRAWREADERINTFC_HH_ */
Definition XrdClAnyObject.hh:33
Base class for any message's body reader.
Definition XrdClAsyncRawReaderIntfc.hh:35
size_t chidx
Definition XrdClAsyncRawReaderIntfc.hh:163
bool dataerr
Definition XrdClAsyncRawReaderIntfc.hh:168
size_t chlen
Definition XrdClAsyncRawReaderIntfc.hh:165
buffer_t discardbuff
Definition XrdClAsyncRawReaderIntfc.hh:167
Stage readstage
Definition XrdClAsyncRawReaderIntfc.hh:149
virtual XRootDStatus GetResponse(AnyObject *&response)=0
Get the response.
std::vector< ChunkStatus > chstatus
Definition XrdClAsyncRawReaderIntfc.hh:158
XRootDStatus ReadBytesAsync(Socket &socket, char *buffer, uint32_t toBeRead, uint32_t &bytesRead)
Definition XrdClAsyncRawReaderIntfc.hh:98
void SetDataLength(int dlen)
Sets response data length.
Definition XrdClAsyncRawReaderIntfc.hh:63
const Message & request
Definition XrdClAsyncRawReaderIntfc.hh:155
virtual XRootDStatus Read(Socket &socket, uint32_t &btsret)=0
size_t choff
Definition XrdClAsyncRawReaderIntfc.hh:164
const URL & url
Definition XrdClAsyncRawReaderIntfc.hh:154
AsyncRawReaderIntfc(const URL &url, const Message &request)
Definition XrdClAsyncRawReaderIntfc.hh:38
uint32_t dlen
Definition XrdClAsyncRawReaderIntfc.hh:159
uint32_t rawbtsrd
Definition XrdClAsyncRawReaderIntfc.hh:161
uint32_t msgbtsrd
Definition XrdClAsyncRawReaderIntfc.hh:160
ChunkList * chunks
Definition XrdClAsyncRawReaderIntfc.hh:157
Stage
Stages of reading out a response from the socket.
Definition XrdClAsyncRawReaderIntfc.hh:138
@ ReadDiscard
Definition XrdClAsyncRawReaderIntfc.hh:142
@ ReadStart
Definition XrdClAsyncRawReaderIntfc.hh:139
@ ReadDone
Definition XrdClAsyncRawReaderIntfc.hh:143
@ ReadRdLst
Definition XrdClAsyncRawReaderIntfc.hh:140
@ ReadRaw
Definition XrdClAsyncRawReaderIntfc.hh:141
std::vector< char > buffer_t
Definition XrdClAsyncRawReaderIntfc.hh:132
virtual ~AsyncRawReaderIntfc()
Destructor.
Definition XrdClAsyncRawReaderIntfc.hh:56
void SetChunkList(ChunkList *chunks)
Sets the chunk list with user buffers.
Definition XrdClAsyncRawReaderIntfc.hh:72
The message representation used throughout the system.
Definition XrdClMessage.hh:30
A network socket.
Definition XrdClSocket.hh:43
virtual XRootDStatus Read(char *buffer, size_t size, int &bytesRead)
URL representation.
Definition XrdClURL.hh:31
Request status.
Definition XrdClXRootDResponses.hh:219
Definition XrdClAction.hh:34
const uint16_t suRetry
Definition XrdClStatus.hh:40
const uint16_t stOK
Everything went OK.
Definition XrdClStatus.hh:31
std::vector< ChunkInfo > ChunkList
List of chunks.
Definition XrdClXRootDResponses.hh:1055
const uint16_t suDone
Definition XrdClStatus.hh:38
Definition XrdClAsyncRawReaderIntfc.hh:123
ChunkStatus()
Definition XrdClAsyncRawReaderIntfc.hh:124
bool sizeerr
Definition XrdClAsyncRawReaderIntfc.hh:125
bool done
Definition XrdClAsyncRawReaderIntfc.hh:126
Procedure execution status.
Definition XrdClStatus.hh:115
uint16_t code
Error type, or additional hints on what to do.
Definition XrdClStatus.hh:147
bool IsOK() const
We're fine.
Definition XrdClStatus.hh:124