xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
XrdClAsyncSocketHandler.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
3 // Author: Lukasz Janyst <ljanyst@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 __XRD_CL_ASYNC_SOCKET_HANDLER_HH__
20 #define __XRD_CL_ASYNC_SOCKET_HANDLER_HH__
21 
22 #include "XrdCl/XrdClSocket.hh"
23 #include "XrdCl/XrdClDefaultEnv.hh"
24 #include "XrdCl/XrdClPoller.hh"
28 #include "XrdCl/XrdClURL.hh"
33 
34 namespace XrdCl
35 {
36  class Stream;
37 
38  //----------------------------------------------------------------------------
41  //----------------------------------------------------------------------------
43  {
44  public:
45  //------------------------------------------------------------------------
47  //------------------------------------------------------------------------
48  AsyncSocketHandler( const URL &url,
49  Poller *poller,
50  TransportHandler *transport,
51  AnyObject *channelData,
52  uint16_t subStreamNum,
53  Stream *strm );
54 
55  //------------------------------------------------------------------------
57  //------------------------------------------------------------------------
59 
60  //------------------------------------------------------------------------
62  //------------------------------------------------------------------------
63  void SetAddress( const XrdNetAddr &address )
64  {
65  pSockAddr = address;
66  }
67 
68  //------------------------------------------------------------------------
70  //------------------------------------------------------------------------
71  const XrdNetAddr &GetAddress() const
72  {
73  return pSockAddr;
74  }
75 
76  //------------------------------------------------------------------------
78  //------------------------------------------------------------------------
79  XRootDStatus Connect( time_t timeout );
80 
81  //------------------------------------------------------------------------
83  //------------------------------------------------------------------------
85 
86  //------------------------------------------------------------------------
88  //------------------------------------------------------------------------
89  virtual void Event( uint8_t type, XrdCl::Socket */*socket*/ );
90 
91  //------------------------------------------------------------------------
93  //------------------------------------------------------------------------
95  {
98  return XRootDStatus();
99  }
100 
101  //------------------------------------------------------------------------
103  //------------------------------------------------------------------------
105  {
106  if( !pPoller->EnableWriteNotification( pSocket, false ) )
108  return XRootDStatus();
109  }
110 
111  //------------------------------------------------------------------------
113  //------------------------------------------------------------------------
114  const std::string &GetStreamName()
115  {
116  return pStreamName;
117  }
118 
119  //------------------------------------------------------------------------
121  //------------------------------------------------------------------------
123  {
124  return pLastActivity;
125  }
126 
127  protected:
128 
129  //------------------------------------------------------------------------
131  //------------------------------------------------------------------------
132  static std::string ToStreamName( const URL &url, uint16_t strmnb );
133 
134  //------------------------------------------------------------------------
135  // Connect returned
136  //------------------------------------------------------------------------
137  virtual void OnConnectionReturn();
138 
139  //------------------------------------------------------------------------
140  // Got a write readiness event
141  //------------------------------------------------------------------------
142  void OnWrite();
143 
144  //------------------------------------------------------------------------
145  // Got a write readiness event while handshaking
146  //------------------------------------------------------------------------
148 
149  //------------------------------------------------------------------------
150  // Got a read readiness event
151  //------------------------------------------------------------------------
152  void OnRead();
153 
154  //------------------------------------------------------------------------
155  // Got a read readiness event while handshaking
156  //------------------------------------------------------------------------
157  void OnReadWhileHandshaking();
158 
159  //------------------------------------------------------------------------
160  // Handle the handshake message
161  //------------------------------------------------------------------------
162  void HandleHandShake( std::unique_ptr<Message> msg );
163 
164  //------------------------------------------------------------------------
165  // Prepare the next step of the hand-shake procedure
166  //------------------------------------------------------------------------
167  void HandShakeNextStep( bool done );
168 
169  //------------------------------------------------------------------------
170  // Handle fault
171  //------------------------------------------------------------------------
172  void OnFault( XRootDStatus st );
173 
174  //------------------------------------------------------------------------
175  // Handle fault while handshaking
176  //------------------------------------------------------------------------
178 
179  //------------------------------------------------------------------------
180  // Handle write timeout event
181  //------------------------------------------------------------------------
182  void OnWriteTimeout();
183 
184  //------------------------------------------------------------------------
185  // Handle read timeout event
186  //------------------------------------------------------------------------
187  void OnReadTimeout();
188 
189  //------------------------------------------------------------------------
190  // Handle timeout event while handshaking
191  //------------------------------------------------------------------------
193 
194  //------------------------------------------------------------------------
195  // Handle header corruption in case of kXR_status response
196  //------------------------------------------------------------------------
197  void OnHeaderCorruption();
198 
199  //------------------------------------------------------------------------
200  // Carry out the TLS hand-shake
201  //
202  // The TLS hand-shake is being initiated in HandleHandShake() by calling
203  // Socket::TlsHandShake(), however it returns suRetry the TLS hand-shake
204  // needs to be followed up by OnTlsHandShake().
205  //
206  // However, once the TLS connection has been established the server may
207  // decide to redo the TLS hand-shake at any time, this operation is handled
208  // under the hood by read and write requests and facilitated by
209  // Socket::MapEvent()
210  //------------------------------------------------------------------------
212 
213  //------------------------------------------------------------------------
214  // Handle read/write event if we are in the middle of a TLS hand-shake
215  //------------------------------------------------------------------------
216  // Handle read/write event if we are in the middle of a TLS hand-shake
217  void OnTLSHandShake();
218 
219  //------------------------------------------------------------------------
220  // Prepare a HS writer for sending and enable uplink
221  //------------------------------------------------------------------------
222  void SendHSMsg();
223 
224  //------------------------------------------------------------------------
225  // Extract the value of a wait response
226  //
227  // @param rsp : the server response
228  // @return : if rsp is a wait response then its value
229  // otherwise -1
230  //------------------------------------------------------------------------
231  inline kXR_int32 HandleWaitRsp( Message *rsp );
232 
233  //------------------------------------------------------------------------
234  // Check if HS wait time elapsed
235  //------------------------------------------------------------------------
236  void CheckHSWait();
237 
238  //------------------------------------------------------------------------
239  // Data members
240  //------------------------------------------------------------------------
244  uint16_t pSubStreamNum;
246  std::string pStreamName;
249  std::unique_ptr<HandShakeData> pHandShakeData;
259 
260  std::unique_ptr<AsyncHSWriter> hswriter;
261  std::unique_ptr<AsyncMsgReader> rspreader;
262  std::unique_ptr<AsyncHSReader> hsreader;
263  std::unique_ptr<AsyncMsgWriter> reqwriter;
264  };
265 }
266 
267 #endif // __XRD_CL_ASYNC_SOCKET_HANDLER_HH__
Definition: XrdClAnyObject.hh:32
static std::string ToStreamName(const URL &url, uint16_t strmnb)
Convert Stream object and sub-stream number to stream name.
Interface.
Definition: XrdClPoller.hh:33
AsyncSocketHandler(const URL &url, Poller *poller, TransportHandler *transport, AnyObject *channelData, uint16_t subStreamNum, Stream *strm)
Constructor.
Interface for socket pollers.
Definition: XrdClPoller.hh:86
virtual void Event(uint8_t type, XrdCl::Socket *)
Handle a socket event.
bool pHandShakeDone
Definition: XrdClAsyncSocketHandler.hh:250
The message representation used throughout the system.
Definition: XrdClMessage.hh:29
time_t GetLastActivity()
Get timestamp of last registered socket activity.
Definition: XrdClAsyncSocketHandler.hh:122
std::unique_ptr< AsyncMsgReader > rspreader
Definition: XrdClAsyncSocketHandler.hh:261
bool pTlsHandShakeOngoing
Definition: XrdClAsyncSocketHandler.hh:258
XRootDStatus Close()
Close the connection.
AnyObject * pChannelData
Definition: XrdClAsyncSocketHandler.hh:243
virtual void OnConnectionReturn()
uint16_t pSubStreamNum
Definition: XrdClAsyncSocketHandler.hh:244
const XrdNetAddr & GetAddress() const
Get the address that the socket is connected to.
Definition: XrdClAsyncSocketHandler.hh:71
time_t pConnectionStarted
Definition: XrdClAsyncSocketHandler.hh:252
URL pUrl
Definition: XrdClAsyncSocketHandler.hh:257
Definition: XrdNetAddr.hh:41
std::unique_ptr< HandShakeData > pHandShakeData
Definition: XrdClAsyncSocketHandler.hh:249
XRootDStatus DisableUplink()
Disable uplink.
Definition: XrdClAsyncSocketHandler.hh:104
void OnFault(XRootDStatus st)
time_t pHSWaitSeconds
Definition: XrdClAsyncSocketHandler.hh:256
void OnFaultWhileHandshaking(XRootDStatus st)
Perform the handshake and the authentication for each physical stream.
Definition: XrdClPostMasterInterfaces.hh:289
const uint16_t stFatal
Fatal error, it&#39;s still an error.
Definition: XrdClStatus.hh:33
time_t pHSWaitStarted
Definition: XrdClAsyncSocketHandler.hh:255
Request status.
Definition: XrdClXRootDResponses.hh:218
Socket * pSocket
Definition: XrdClAsyncSocketHandler.hh:247
Poller * pPoller
Definition: XrdClAsyncSocketHandler.hh:241
const std::string & GetStreamName()
Get stream name.
Definition: XrdClAsyncSocketHandler.hh:114
TransportHandler * pTransport
Definition: XrdClAsyncSocketHandler.hh:242
XrdNetAddr pSockAddr
Definition: XrdClAsyncSocketHandler.hh:248
const uint16_t errPollerError
Definition: XrdClStatus.hh:75
URL representation.
Definition: XrdClURL.hh:30
XRootDStatus DoTlsHandShake()
void HandleHandShake(std::unique_ptr< Message > msg)
std::unique_ptr< AsyncHSWriter > hswriter
Definition: XrdClAsyncSocketHandler.hh:260
std::unique_ptr< AsyncMsgWriter > reqwriter
Definition: XrdClAsyncSocketHandler.hh:263
std::unique_ptr< AsyncHSReader > hsreader
Definition: XrdClAsyncSocketHandler.hh:262
~AsyncSocketHandler()
Destructor.
time_t pLastActivity
Definition: XrdClAsyncSocketHandler.hh:254
time_t pConnectionTimeout
Definition: XrdClAsyncSocketHandler.hh:253
int kXR_int32
Definition: XPtypes.hh:89
XRootDStatus Connect(time_t timeout)
Connect to the currently set address.
Stream.
Definition: XrdClStream.hh:49
std::string pStreamName
Definition: XrdClAsyncSocketHandler.hh:246
kXR_int32 HandleWaitRsp(Message *rsp)
void HandShakeNextStep(bool done)
A network socket.
Definition: XrdClSocket.hh:42
Definition: XrdClAsyncSocketHandler.hh:42
virtual bool EnableWriteNotification(Socket *socket, bool notify, uint16_t timeout=60)=0
uint16_t pTimeoutResolution
Definition: XrdClAsyncSocketHandler.hh:251
void SetAddress(const XrdNetAddr &address)
Set address.
Definition: XrdClAsyncSocketHandler.hh:63
Stream * pStream
Definition: XrdClAsyncSocketHandler.hh:245
XRootDStatus EnableUplink()
Enable uplink.
Definition: XrdClAsyncSocketHandler.hh:94