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"
33
34namespace XrdCl
35{
36 class Stream;
37
38 //----------------------------------------------------------------------------
41 //----------------------------------------------------------------------------
43 {
44 public:
45 //------------------------------------------------------------------------
47 //------------------------------------------------------------------------
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 //------------------------------------------------------------------------
129 //------------------------------------------------------------------------
130 std::string GetIpStack() const;
131
132 //------------------------------------------------------------------------
134 //------------------------------------------------------------------------
135 std::string GetIpAddr();
136
137 //------------------------------------------------------------------------
139 //------------------------------------------------------------------------
140 std::string GetHostName();
141
142 protected:
143
144 //------------------------------------------------------------------------
146 //------------------------------------------------------------------------
147 static std::string ToStreamName( const URL &url, uint16_t strmnb );
148
149 //------------------------------------------------------------------------
150 // Connect returned
151 //------------------------------------------------------------------------
152 virtual void OnConnectionReturn();
153
154 //------------------------------------------------------------------------
155 // Got a write readiness event
156 //------------------------------------------------------------------------
157 void OnWrite();
158
159 //------------------------------------------------------------------------
160 // Got a write readiness event while handshaking
161 //------------------------------------------------------------------------
163
164 //------------------------------------------------------------------------
165 // Got a read readiness event
166 //------------------------------------------------------------------------
167 void OnRead();
168
169 //------------------------------------------------------------------------
170 // Got a read readiness event while handshaking
171 //------------------------------------------------------------------------
173
174 //------------------------------------------------------------------------
175 // Handle the handshake message
176 //------------------------------------------------------------------------
177 void HandleHandShake( std::unique_ptr<Message> msg );
178
179 //------------------------------------------------------------------------
180 // Prepare the next step of the hand-shake procedure
181 //------------------------------------------------------------------------
182 void HandShakeNextStep( bool done );
183
184 //------------------------------------------------------------------------
185 // Handle fault
186 //------------------------------------------------------------------------
188
189 //------------------------------------------------------------------------
190 // Handle fault while handshaking
191 //------------------------------------------------------------------------
193
194 //------------------------------------------------------------------------
195 // Handle write timeout event
196 //------------------------------------------------------------------------
198
199 //------------------------------------------------------------------------
200 // Handle read timeout event
201 //------------------------------------------------------------------------
203
204 //------------------------------------------------------------------------
205 // Handle timeout event while handshaking
206 //------------------------------------------------------------------------
208
209 //------------------------------------------------------------------------
210 // Handle header corruption in case of kXR_status response
211 //------------------------------------------------------------------------
213
214 //------------------------------------------------------------------------
215 // Carry out the TLS hand-shake
216 //
217 // The TLS hand-shake is being initiated in HandleHandShake() by calling
218 // Socket::TlsHandShake(), however it returns suRetry the TLS hand-shake
219 // needs to be followed up by OnTlsHandShake().
220 //
221 // However, once the TLS connection has been established the server may
222 // decide to redo the TLS hand-shake at any time, this operation is handled
223 // under the hood by read and write requests and facilitated by
224 // Socket::MapEvent()
225 //------------------------------------------------------------------------
227
228 //------------------------------------------------------------------------
229 // Handle read/write event if we are in the middle of a TLS hand-shake
230 //------------------------------------------------------------------------
231 // Handle read/write event if we are in the middle of a TLS hand-shake
233
234 //------------------------------------------------------------------------
235 // Prepare a HS writer for sending and enable uplink
236 //------------------------------------------------------------------------
237 void SendHSMsg();
238
239 //------------------------------------------------------------------------
240 // Extract the value of a wait response
241 //
242 // @param rsp : the server response
243 // @return : if rsp is a wait response then its value
244 // otherwise -1
245 //------------------------------------------------------------------------
247
248 //------------------------------------------------------------------------
249 // Check if HS wait time elapsed
250 //------------------------------------------------------------------------
252
253 //------------------------------------------------------------------------
254 // Data members
255 //------------------------------------------------------------------------
261 std::string pStreamName;
264 std::unique_ptr<HandShakeData> pHandShakeData;
274
275 std::unique_ptr<AsyncHSWriter> hswriter;
276 std::unique_ptr<AsyncMsgReader> rspreader;
277 std::unique_ptr<AsyncHSReader> hsreader;
278 std::unique_ptr<AsyncMsgWriter> reqwriter;
279 };
280}
281
282#endif // __XRD_CL_ASYNC_SOCKET_HANDLER_HH__
int kXR_int32
Definition: XPtypes.hh:89
Definition: XrdClAnyObject.hh:33
Definition: XrdClAsyncSocketHandler.hh:43
virtual void Event(uint8_t type, XrdCl::Socket *)
Handle a socket event.
XrdNetAddr pSockAddr
Definition: XrdClAsyncSocketHandler.hh:263
~AsyncSocketHandler()
Destructor.
void HandShakeNextStep(bool done)
time_t GetLastActivity()
Get timestamp of last registered socket activity.
Definition: XrdClAsyncSocketHandler.hh:122
Poller * pPoller
Definition: XrdClAsyncSocketHandler.hh:256
std::unique_ptr< AsyncHSWriter > hswriter
Definition: XrdClAsyncSocketHandler.hh:275
TransportHandler * pTransport
Definition: XrdClAsyncSocketHandler.hh:257
uint16_t pTimeoutResolution
Definition: XrdClAsyncSocketHandler.hh:266
std::unique_ptr< AsyncHSReader > hsreader
Definition: XrdClAsyncSocketHandler.hh:277
XRootDStatus DoTlsHandShake()
void OnFault(XRootDStatus st)
void HandleHandShake(std::unique_ptr< Message > msg)
bool pHandShakeDone
Definition: XrdClAsyncSocketHandler.hh:265
Stream * pStream
Definition: XrdClAsyncSocketHandler.hh:260
Socket * pSocket
Definition: XrdClAsyncSocketHandler.hh:262
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:268
virtual void OnConnectionReturn()
time_t pHSWaitStarted
Definition: XrdClAsyncSocketHandler.hh:270
time_t pHSWaitSeconds
Definition: XrdClAsyncSocketHandler.hh:271
void OnFaultWhileHandshaking(XRootDStatus st)
const XrdNetAddr & GetAddress() const
Get the address that the socket is connected to.
Definition: XrdClAsyncSocketHandler.hh:71
kXR_int32 HandleWaitRsp(Message *rsp)
URL pUrl
Definition: XrdClAsyncSocketHandler.hh:272
std::unique_ptr< AsyncMsgWriter > reqwriter
Definition: XrdClAsyncSocketHandler.hh:278
XRootDStatus EnableUplink()
Enable uplink.
Definition: XrdClAsyncSocketHandler.hh:94
time_t pLastActivity
Definition: XrdClAsyncSocketHandler.hh:269
std::string GetIpStack() const
Get the IP stack.
const std::string & GetStreamName()
Get stream name.
Definition: XrdClAsyncSocketHandler.hh:114
std::string GetHostName()
Get hostname.
std::unique_ptr< AsyncMsgReader > rspreader
Definition: XrdClAsyncSocketHandler.hh:276
XRootDStatus DisableUplink()
Disable uplink.
Definition: XrdClAsyncSocketHandler.hh:104
std::unique_ptr< HandShakeData > pHandShakeData
Definition: XrdClAsyncSocketHandler.hh:264
std::string pStreamName
Definition: XrdClAsyncSocketHandler.hh:261
XRootDStatus Connect(time_t timeout)
Connect to the currently set address.
bool pTlsHandShakeOngoing
Definition: XrdClAsyncSocketHandler.hh:273
AsyncSocketHandler(const URL &url, Poller *poller, TransportHandler *transport, AnyObject *channelData, uint16_t subStreamNum, Stream *strm)
Constructor.
uint16_t pSubStreamNum
Definition: XrdClAsyncSocketHandler.hh:259
time_t pConnectionStarted
Definition: XrdClAsyncSocketHandler.hh:267
void SetAddress(const XrdNetAddr &address)
Set address.
Definition: XrdClAsyncSocketHandler.hh:63
AnyObject * pChannelData
Definition: XrdClAsyncSocketHandler.hh:258
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:50
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