xrootd
Loading...
Searching...
No Matches
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"
24#include "XrdCl/XrdClPoller.hh"
28#include "XrdCl/XrdClURL.hh"
34
35namespace XrdCl
36{
37 class Stream;
38
39 //----------------------------------------------------------------------------
42 //----------------------------------------------------------------------------
44 {
45 public:
46 //------------------------------------------------------------------------
48 //------------------------------------------------------------------------
50 Poller *poller,
51 TransportHandler *transport,
52 AnyObject *channelData,
53 uint16_t subStreamNum,
54 Stream *strm );
55
56 //------------------------------------------------------------------------
58 //------------------------------------------------------------------------
60
61 //------------------------------------------------------------------------
63 //------------------------------------------------------------------------
64 void SetAddress( const XrdNetAddr &address )
65 {
66 pSockAddr = address;
67 }
68
69 //------------------------------------------------------------------------
71 //------------------------------------------------------------------------
72 const XrdNetAddr &GetAddress() const
73 {
74 return pSockAddr;
75 }
76
77 //------------------------------------------------------------------------
79 //------------------------------------------------------------------------
80 XRootDStatus Connect( time_t timeout );
81
82 //------------------------------------------------------------------------
84 //------------------------------------------------------------------------
86
87 //------------------------------------------------------------------------
89 //------------------------------------------------------------------------
90 virtual void Event( uint8_t type, XrdCl::Socket */*socket*/ );
91
92 //------------------------------------------------------------------------
94 //------------------------------------------------------------------------
101
102 //------------------------------------------------------------------------
104 //------------------------------------------------------------------------
106 {
107 if( !pPoller->EnableWriteNotification( pSocket, false ) )
109 return XRootDStatus();
110 }
111
112 //------------------------------------------------------------------------
114 //------------------------------------------------------------------------
115 const std::string &GetStreamName()
116 {
117 return pStreamName;
118 }
119
120 //------------------------------------------------------------------------
122 //------------------------------------------------------------------------
124 {
125 return pLastActivity;
126 }
127
128 //------------------------------------------------------------------------
130 //------------------------------------------------------------------------
131 std::string GetIpStack() const;
132
133 //------------------------------------------------------------------------
135 //------------------------------------------------------------------------
136 std::string GetIpAddr();
137
138 //------------------------------------------------------------------------
140 //------------------------------------------------------------------------
141 std::string GetHostName();
142
143 protected:
144
145 //------------------------------------------------------------------------
147 //------------------------------------------------------------------------
148 static std::string ToStreamName( const URL &url, uint16_t strmnb );
149
150 //------------------------------------------------------------------------
151 // Connect returned
152 //------------------------------------------------------------------------
154
155 //------------------------------------------------------------------------
156 // Got a write readiness event
157 //------------------------------------------------------------------------
159
160 //------------------------------------------------------------------------
161 // Got a write readiness event while handshaking
162 //------------------------------------------------------------------------
164
165 //------------------------------------------------------------------------
166 // Got a read readiness event
167 //------------------------------------------------------------------------
169
170 //------------------------------------------------------------------------
171 // Got a read readiness event while handshaking
172 //------------------------------------------------------------------------
174
175 //------------------------------------------------------------------------
176 // Handle the handshake message
177 //------------------------------------------------------------------------
178 bool HandleHandShake( std::unique_ptr<Message> msg )
180
181 //------------------------------------------------------------------------
182 // Prepare the next step of the hand-shake procedure
183 //------------------------------------------------------------------------
185
186 //------------------------------------------------------------------------
187 // Handle fault
188 //------------------------------------------------------------------------
190
191 //------------------------------------------------------------------------
192 // Handle fault while handshaking
193 //------------------------------------------------------------------------
195
196 //------------------------------------------------------------------------
197 // Handle write timeout event
198 //------------------------------------------------------------------------
200
201 //------------------------------------------------------------------------
202 // Handle read timeout event
203 //------------------------------------------------------------------------
205
206 //------------------------------------------------------------------------
207 // Handle timeout event while handshaking
208 //------------------------------------------------------------------------
210
211 //------------------------------------------------------------------------
212 // Handle header corruption in case of kXR_status response
213 //------------------------------------------------------------------------
215
216 //------------------------------------------------------------------------
217 // Carry out the TLS hand-shake
218 //
219 // The TLS hand-shake is being initiated in HandleHandShake() by calling
220 // Socket::TlsHandShake(), however it returns suRetry the TLS hand-shake
221 // needs to be followed up by OnTlsHandShake().
222 //
223 // However, once the TLS connection has been established the server may
224 // decide to redo the TLS hand-shake at any time, this operation is handled
225 // under the hood by read and write requests and facilitated by
226 // Socket::MapEvent()
227 //------------------------------------------------------------------------
229
230 //------------------------------------------------------------------------
231 // Handle read/write event if we are in the middle of a TLS hand-shake
232 //------------------------------------------------------------------------
233 // Handle read/write event if we are in the middle of a TLS hand-shake
235
236 //------------------------------------------------------------------------
237 // Prepare a HS writer for sending and enable uplink
238 //------------------------------------------------------------------------
240
241 //------------------------------------------------------------------------
242 // Extract the value of a wait response
243 //
244 // @param rsp : the server response
245 // @return : if rsp is a wait response then its value
246 // otherwise -1
247 //------------------------------------------------------------------------
249
250 //------------------------------------------------------------------------
251 // Check if HS wait time elapsed
252 //------------------------------------------------------------------------
254
255 //------------------------------------------------------------------------
256 // Handler for read related socket events
257 //------------------------------------------------------------------------
258 inline bool EventRead( uint8_t type ) XRD_WARN_UNUSED_RESULT;
259
260 //------------------------------------------------------------------------
261 // Handler for write related socket events
262 //------------------------------------------------------------------------
263 inline bool EventWrite( uint8_t type ) XRD_WARN_UNUSED_RESULT;
264
265 //------------------------------------------------------------------------
266 // Data members
267 //------------------------------------------------------------------------
286
291 };
292}
293
294#endif // __XRD_CL_ASYNC_SOCKET_HANDLER_HH__
int kXR_int32
Definition XPtypes.hh:89
#define XRD_WARN_UNUSED_RESULT
Definition XrdOucCompiler.hh:31
Definition XrdClAnyObject.hh:33
Utility class encapsulating reading hand-shake response logic.
Definition XrdClAsyncHSReader.hh:37
Utility class encapsulating writing hand-shake request logic.
Definition XrdClAsyncHSWriter.hh:39
Utility class encapsulating reading response message logic.
Definition XrdClAsyncMsgReader.hh:37
Utility class encapsulating writing request logic.
Definition XrdClAsyncMsgWriter.hh:38
Definition XrdClAsyncSocketHandler.hh:44
virtual void Event(uint8_t type, XrdCl::Socket *)
Handle a socket event.
XrdNetAddr pSockAddr
Definition XrdClAsyncSocketHandler.hh:275
~AsyncSocketHandler()
Destructor.
time_t GetLastActivity()
Get timestamp of last registered socket activity.
Definition XrdClAsyncSocketHandler.hh:123
bool OnReadTimeout() XRD_WARN_UNUSED_RESULT
Poller * pPoller
Definition XrdClAsyncSocketHandler.hh:268
std::unique_ptr< AsyncHSWriter > hswriter
Definition XrdClAsyncSocketHandler.hh:287
bool OnWriteTimeout() XRD_WARN_UNUSED_RESULT
TransportHandler * pTransport
Definition XrdClAsyncSocketHandler.hh:269
bool OnWrite() XRD_WARN_UNUSED_RESULT
bool OnTimeoutWhileHandshaking() XRD_WARN_UNUSED_RESULT
uint16_t pTimeoutResolution
Definition XrdClAsyncSocketHandler.hh:278
bool CheckHSWait() XRD_WARN_UNUSED_RESULT
bool EventRead(uint8_t type) XRD_WARN_UNUSED_RESULT
std::unique_ptr< AsyncHSReader > hsreader
Definition XrdClAsyncSocketHandler.hh:289
XRootDStatus DoTlsHandShake()
void OnFault(XRootDStatus st)
bool pHandShakeDone
Definition XrdClAsyncSocketHandler.hh:277
bool HandleHandShake(std::unique_ptr< Message > msg) XRD_WARN_UNUSED_RESULT
bool OnWriteWhileHandshaking() XRD_WARN_UNUSED_RESULT
Stream * pStream
Definition XrdClAsyncSocketHandler.hh:272
Socket * pSocket
Definition XrdClAsyncSocketHandler.hh:274
static std::string ToStreamName(const URL &url, uint16_t strmnb)
Convert Stream object and sub-stream number to stream name.
XRootDStatus Close()
Close the connection.
time_t pConnectionTimeout
Definition XrdClAsyncSocketHandler.hh:280
time_t pHSWaitStarted
Definition XrdClAsyncSocketHandler.hh:282
time_t pHSWaitSeconds
Definition XrdClAsyncSocketHandler.hh:283
void OnFaultWhileHandshaking(XRootDStatus st)
virtual bool OnConnectionReturn() XRD_WARN_UNUSED_RESULT
const XrdNetAddr & GetAddress() const
Get the address that the socket is connected to.
Definition XrdClAsyncSocketHandler.hh:72
kXR_int32 HandleWaitRsp(Message *rsp)
bool HandShakeNextStep(bool done) XRD_WARN_UNUSED_RESULT
URL pUrl
Definition XrdClAsyncSocketHandler.hh:284
bool OnReadWhileHandshaking() XRD_WARN_UNUSED_RESULT
std::unique_ptr< AsyncMsgWriter > reqwriter
Definition XrdClAsyncSocketHandler.hh:290
XRootDStatus EnableUplink()
Enable uplink.
Definition XrdClAsyncSocketHandler.hh:95
time_t pLastActivity
Definition XrdClAsyncSocketHandler.hh:281
std::string GetIpStack() const
Get the IP stack.
bool EventWrite(uint8_t type) XRD_WARN_UNUSED_RESULT
const std::string & GetStreamName()
Get stream name.
Definition XrdClAsyncSocketHandler.hh:115
std::string GetHostName()
Get hostname.
std::unique_ptr< AsyncMsgReader > rspreader
Definition XrdClAsyncSocketHandler.hh:288
XRootDStatus DisableUplink()
Disable uplink.
Definition XrdClAsyncSocketHandler.hh:105
std::unique_ptr< HandShakeData > pHandShakeData
Definition XrdClAsyncSocketHandler.hh:276
std::string pStreamName
Definition XrdClAsyncSocketHandler.hh:273
bool OnRead() XRD_WARN_UNUSED_RESULT
XRootDStatus Connect(time_t timeout)
Connect to the currently set address.
bool pTlsHandShakeOngoing
Definition XrdClAsyncSocketHandler.hh:285
AsyncSocketHandler(const URL &url, Poller *poller, TransportHandler *transport, AnyObject *channelData, uint16_t subStreamNum, Stream *strm)
Constructor.
bool OnTLSHandShake() XRD_WARN_UNUSED_RESULT
uint16_t pSubStreamNum
Definition XrdClAsyncSocketHandler.hh:271
time_t pConnectionStarted
Definition XrdClAsyncSocketHandler.hh:279
void SetAddress(const XrdNetAddr &address)
Set address.
Definition XrdClAsyncSocketHandler.hh:64
bool SendHSMsg() XRD_WARN_UNUSED_RESULT
AnyObject * pChannelData
Definition XrdClAsyncSocketHandler.hh:270
std::string GetIpAddr()
Get IP address.
The message representation used throughout the system.
Definition XrdClMessage.hh:30
Interface for socket pollers.
Definition XrdClPoller.hh:87
virtual bool EnableWriteNotification(Socket *socket, bool notify, uint16_t timeout=60)=0
Interface.
Definition XrdClPoller.hh:34
A network socket.
Definition XrdClSocket.hh:43
Stream.
Definition XrdClStream.hh:52
Perform the handshake and the authentication for each physical stream.
Definition XrdClPostMasterInterfaces.hh:310
URL representation.
Definition XrdClURL.hh:31
Request status.
Definition XrdClXRootDResponses.hh:219
Definition XrdNetAddr.hh:42
Definition XrdClAction.hh:34
const uint16_t stFatal
Fatal error, it's still an error.
Definition XrdClStatus.hh:33
const uint16_t errPollerError
Definition XrdClStatus.hh:75
Definition XrdOucJson.hh:4517
Data structure that carries the handshake information.
Definition XrdClPostMasterInterfaces.hh:244