xrootd
Main Page
Namespaces
Classes
Files
File List
File Members
src
XrdCl
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/XrdClConstants.hh
"
24
#include "
XrdCl/XrdClDefaultEnv.hh
"
25
#include "
XrdCl/XrdClPoller.hh
"
26
#include "
XrdCl/XrdClPostMasterInterfaces.hh
"
27
28
#include <sys/types.h>
29
#include <sys/socket.h>
30
31
namespace
XrdCl
32
{
33
class
Stream;
34
35
//----------------------------------------------------------------------------
38
//----------------------------------------------------------------------------
39
class
AsyncSocketHandler
:
public
SocketHandler
40
{
41
public
:
42
//------------------------------------------------------------------------
44
//------------------------------------------------------------------------
45
AsyncSocketHandler
(
Poller
*poller,
46
TransportHandler
*transport,
47
AnyObject
*channelData,
48
uint16_t subStreamNum );
49
50
//------------------------------------------------------------------------
52
//------------------------------------------------------------------------
53
~AsyncSocketHandler
();
54
55
//------------------------------------------------------------------------
57
//------------------------------------------------------------------------
58
void
SetAddress
(
const
sockaddr_in &address )
59
{
60
memcpy( &
pSockAddr
, &address,
sizeof
( sockaddr_in ) );
61
}
62
63
//------------------------------------------------------------------------
65
//------------------------------------------------------------------------
66
const
sockaddr_in &
GetAddress
()
const
67
{
68
return
pSockAddr
;
69
}
70
71
//------------------------------------------------------------------------
73
//------------------------------------------------------------------------
74
Status
Connect
( time_t timeout );
75
76
//------------------------------------------------------------------------
78
//------------------------------------------------------------------------
79
Status
Close
();
80
81
//------------------------------------------------------------------------
83
//------------------------------------------------------------------------
84
void
SetStream
(
Stream
*
stream
);
85
86
//------------------------------------------------------------------------
88
//------------------------------------------------------------------------
89
virtual
void
Event
( uint8_t type,
XrdCl::Socket
*
/*socket*/
);
90
91
//------------------------------------------------------------------------
93
//------------------------------------------------------------------------
94
Status
EnableUplink
()
95
{
96
if
( !
pPoller
->
EnableWriteNotification
(
pSocket
,
true
,
pTimeoutResolution
) )
97
return
Status
(
stFatal
,
errPollerError
);
98
return
Status
();
99
}
100
101
//------------------------------------------------------------------------
103
//------------------------------------------------------------------------
104
Status
DisableUplink
()
105
{
106
if
( !
pPoller
->
EnableWriteNotification
(
pSocket
,
false
) )
107
return
Status
(
stFatal
,
errPollerError
);
108
return
Status
();
109
}
110
111
//------------------------------------------------------------------------
113
//------------------------------------------------------------------------
114
const
std::string &
GetStreamName
()
115
{
116
return
pStreamName
;
117
}
118
119
private
:
120
121
//------------------------------------------------------------------------
122
// Connect returned
123
//------------------------------------------------------------------------
124
void
OnConnectionReturn
();
125
126
//------------------------------------------------------------------------
127
// Got a write readiness event
128
//------------------------------------------------------------------------
129
void
OnWrite
();
130
131
//------------------------------------------------------------------------
132
// Got a write readiness event while handshaking
133
//------------------------------------------------------------------------
134
void
OnWriteWhileHandshaking
();
135
136
//------------------------------------------------------------------------
137
// Write the current message
138
//------------------------------------------------------------------------
139
Status
WriteCurrentMessage
();
140
141
//------------------------------------------------------------------------
142
// Got a read readiness event
143
//------------------------------------------------------------------------
144
void
OnRead
();
145
146
//------------------------------------------------------------------------
147
// Got a read readiness event while handshaking
148
//------------------------------------------------------------------------
149
void
OnReadWhileHandshaking
();
150
151
//------------------------------------------------------------------------
152
// Read a message
153
//------------------------------------------------------------------------
154
Status
ReadMessage
();
155
156
//------------------------------------------------------------------------
157
// Handle fault
158
//------------------------------------------------------------------------
159
void
OnFault
(
Status
st );
160
161
//------------------------------------------------------------------------
162
// Handle fault while handshaking
163
//------------------------------------------------------------------------
164
void
OnFaultWhileHandshaking
(
Status
st );
165
166
//------------------------------------------------------------------------
167
// Handle write timeout event
168
//------------------------------------------------------------------------
169
void
OnWriteTimeout
();
170
171
//------------------------------------------------------------------------
172
// Handle read timeout event
173
//------------------------------------------------------------------------
174
void
OnReadTimeout
();
175
176
//------------------------------------------------------------------------
177
// Handle timeout event while handshaking
178
//------------------------------------------------------------------------
179
void
OnTimeoutWhileHandshaking
();
180
181
//------------------------------------------------------------------------
182
// Data members
183
//------------------------------------------------------------------------
184
Poller
*
pPoller
;
185
TransportHandler
*
pTransport
;
186
AnyObject
*
pChannelData
;
187
uint16_t
pSubStreamNum
;
188
Stream
*
pStream
;
189
std::string
pStreamName
;
190
Socket
*
pSocket
;
191
Message
*
pIncoming
;
192
Message
*
pOutgoing
;
193
sockaddr_in
pSockAddr
;
194
HandShakeData
*
pHandShakeData
;
195
bool
pHandShakeDone
;
196
uint16_t
pTimeoutResolution
;
197
time_t
pConnectionStarted
;
198
time_t
pConnectionTimeout
;
199
bool
pHeaderDone
;
200
std::pair<IncomingMsgHandler*, bool>
pIncHandler
;
201
bool
pOutMsgDone
;
202
OutgoingMsgHandler
*
pOutHandler
;
203
uint32_t
pIncMsgSize
;
204
uint32_t
pOutMsgSize
;
205
};
206
}
207
208
#endif // __XRD_CL_ASYNC_SOCKET_HANDLER_HH__
Generated by
1.8.3.1