xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
XrdClAsyncHSReader.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_XRDCLASYNCHSREADER_HH_
20 #define SRC_XRDCL_XRDCLASYNCHSREADER_HH_
21 
22 #include "XrdCl/XrdClMessage.hh"
25 #include "XrdCl/XrdClSocket.hh"
26 #include "XrdCl/XrdClConstants.hh"
27 #include "XrdCl/XrdClStream.hh"
28 
29 #include <memory>
30 
31 namespace XrdCl
32 {
33  //----------------------------------------------------------------------------
35  //----------------------------------------------------------------------------
37  {
38  public:
39  //------------------------------------------------------------------------
47  //------------------------------------------------------------------------
49  Socket &socket,
50  const std::string &strmname,
51  Stream &strm,
52  uint16_t substrmnb) : readstage( ReadStart ),
53  xrdTransport( xrdTransport ),
54  socket( socket ),
55  strmname( strmname ),
56  strm( strm ),
57  substrmnb( substrmnb )
58  {
59  }
60 
61  //------------------------------------------------------------------------
63  //------------------------------------------------------------------------
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  //----------------------------------------------------------------
83  continue;
84  }
85  //------------------------------------------------------------------
86  // We need to read the header
87  //------------------------------------------------------------------
88  case ReadHeader:
89  {
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  //----------------------------------------------------------------
99  continue;
100  }
101  //------------------------------------------------------------------
102  // We read the message to the buffer
103  //------------------------------------------------------------------
104  case ReadMsgBody:
105  {
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() );
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  }
124 
125  //------------------------------------------------------------------------
127  //------------------------------------------------------------------------
128  std::unique_ptr<Message> ReleaseMsg()
129  {
131  return std::move( inmsg );
132  }
133 
134  //------------------------------------------------------------------------
136  //------------------------------------------------------------------------
137  inline void Reset()
138  {
140  inmsg.reset();
141  }
142 
143  private:
144 
145  //------------------------------------------------------------------------
147  //------------------------------------------------------------------------
148  enum Stage
149  {
150  ReadStart, //< the next step is to initialize the read
151  ReadHeader, //< the next step is to read the header
152  ReadMsgBody, //< the next step is to read the body
153  ReadDone //< we are done
154  };
155 
156  //------------------------------------------------------------------------
157  // Current read stage
158  //------------------------------------------------------------------------
160 
161  //------------------------------------------------------------------------
162  // The context of the read operation
163  //------------------------------------------------------------------------
166  const std::string &strmname;
168  uint16_t substrmnb;
169 
170  //------------------------------------------------------------------------
171  // The internal state of the the reader
172  //------------------------------------------------------------------------
173  std::unique_ptr<Message> inmsg;
174  };
175 }
176 
177 #endif /* SRC_XRDCL_XRDCLASYNCHSREADER_HH_ */
Utility class encapsulating reading hand-shake response logic.
Definition: XrdClAsyncHSReader.hh:36
The message representation used throughout the system.
Definition: XrdClMessage.hh:29
Definition: XrdClAsyncHSReader.hh:151
const uint64_t AsyncSockMsg
Definition: XrdClConstants.hh:41
Definition: XrdClAsyncHSReader.hh:150
uint16_t substrmnb
Definition: XrdClAsyncHSReader.hh:168
uint16_t code
Error type, or additional hints on what to do.
Definition: XrdClStatus.hh:146
std::unique_ptr< Message > ReleaseMsg()
Transfer the received message ownership.
Definition: XrdClAsyncHSReader.hh:128
Stage readstage
Definition: XrdClAsyncHSReader.hh:159
void Dump(uint64_t topic, const char *format,...)
Print a dump message.
const std::string & strmname
Definition: XrdClAsyncHSReader.hh:166
static Log * GetLog()
Get default log.
TransportHandler & xrdTransport
Definition: XrdClAsyncHSReader.hh:164
Perform the handshake and the authentication for each physical stream.
Definition: XrdClPostMasterInterfaces.hh:289
void Reset()
Reset the state of the object (makes it ready to read out next msg)
Definition: XrdClAsyncHSReader.hh:137
Request status.
Definition: XrdClXRootDResponses.hh:218
Stream & strm
Definition: XrdClAsyncHSReader.hh:167
XRootDStatus Read()
Read out the response from the socket.
Definition: XrdClAsyncHSReader.hh:64
AsyncHSReader(TransportHandler &xrdTransport, Socket &socket, const std::string &strmname, Stream &strm, uint16_t substrmnb)
Definition: XrdClAsyncHSReader.hh:48
Stage
Stages of reading out a response from the socket.
Definition: XrdClAsyncHSReader.hh:148
std::unique_ptr< Message > inmsg
Definition: XrdClAsyncHSReader.hh:173
const uint16_t suRetry
Definition: XrdClStatus.hh:40
Stream.
Definition: XrdClStream.hh:49
Definition: XrdClAsyncHSReader.hh:152
Socket & socket
Definition: XrdClAsyncHSReader.hh:165
bool IsOK() const
We&#39;re fine.
Definition: XrdClStatus.hh:123
virtual XRootDStatus GetBody(Message &message, Socket *socket)=0
virtual XRootDStatus GetHeader(Message &message, Socket *socket)=0
A network socket.
Definition: XrdClSocket.hh:42
Handle diagnostics.
Definition: XrdClLog.hh:100
Definition: XrdClAsyncHSReader.hh:153