xrootd
XrdClStream.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_STREAM_HH__
20 #define __XRD_CL_STREAM_HH__
21 
22 #include "XrdCl/XrdClPoller.hh"
23 #include "XrdCl/XrdClStatus.hh"
24 #include "XrdCl/XrdClURL.hh"
27 
28 #include "XrdSys/XrdSysPthread.hh"
29 #include <list>
30 #include <vector>
31 #include <netinet/in.h>
32 
33 namespace XrdCl
34 {
35  class Message;
36  class Channel;
37  class TransportHandler;
38  class InQueue;
39  class TaskManager;
40  struct SubStreamData;
41 
42  //----------------------------------------------------------------------------
44  //----------------------------------------------------------------------------
45  class Stream
46  {
47  public:
48  //------------------------------------------------------------------------
50  //------------------------------------------------------------------------
52  {
54  Connected = 1,
55  Connecting = 2,
56  Error = 3
57  };
58 
59  //------------------------------------------------------------------------
61  //------------------------------------------------------------------------
62  Stream( const URL *url, uint16_t streamNum );
63 
64  //------------------------------------------------------------------------
66  //------------------------------------------------------------------------
67  ~Stream();
68 
69  //------------------------------------------------------------------------
71  //------------------------------------------------------------------------
73 
74  //------------------------------------------------------------------------
76  //------------------------------------------------------------------------
77  Status Send( Message *msg,
78  OutgoingMsgHandler *handler,
79  bool stateful,
80  time_t expires );
81 
82  //------------------------------------------------------------------------
84  //------------------------------------------------------------------------
85  void SetTransport( TransportHandler *transport )
86  {
87  pTransport = transport;
88  }
89 
90  //------------------------------------------------------------------------
92  //------------------------------------------------------------------------
93  void SetPoller( Poller *poller )
94  {
95  pPoller = poller;
96  }
97 
98  //------------------------------------------------------------------------
100  //------------------------------------------------------------------------
101  void SetIncomingQueue( InQueue *incomingQueue )
102  {
103  pIncomingQueue = incomingQueue;
104  }
105 
106  //------------------------------------------------------------------------
108  //------------------------------------------------------------------------
109  void SetChannelData( AnyObject *channelData )
110  {
111  pChannelData = channelData;
112  }
113 
114  //------------------------------------------------------------------------
116  //------------------------------------------------------------------------
117  void SetTaskManager( TaskManager *taskManager )
118  {
119  pTaskManager = taskManager;
120  }
121 
122  //------------------------------------------------------------------------
126  //------------------------------------------------------------------------
127  Status EnableLink( PathID &path );
128 
129  //------------------------------------------------------------------------
131  //------------------------------------------------------------------------
132  void Disconnect( bool force = false );
133 
134  //------------------------------------------------------------------------
137  //------------------------------------------------------------------------
138  void Tick( time_t now );
139 
140  //------------------------------------------------------------------------
142  //------------------------------------------------------------------------
143  const URL *GetURL() const
144  {
145  return pUrl;
146  }
147 
148  //------------------------------------------------------------------------
150  //------------------------------------------------------------------------
151  uint16_t GetStreamNumber() const
152  {
153  return pStreamNum;
154  }
155 
156  //------------------------------------------------------------------------
158  //------------------------------------------------------------------------
159  void ForceConnect();
160 
161  //------------------------------------------------------------------------
163  //------------------------------------------------------------------------
164  const std::string &GetName() const
165  {
166  return pStreamName;
167  }
168 
169  //------------------------------------------------------------------------
171  //------------------------------------------------------------------------
172  void OnIncoming( uint16_t subStream, Message *msg );
173 
174  //------------------------------------------------------------------------
175  // Call when one of the sockets is ready to accept a new message
176  //------------------------------------------------------------------------
177  Message *OnReadyToWrite( uint16_t subStream );
178 
179  //------------------------------------------------------------------------
180  // Call when a message is written to the socket
181  //------------------------------------------------------------------------
182  void OnMessageSent( uint16_t subStream, Message *msg );
183 
184  //------------------------------------------------------------------------
186  //------------------------------------------------------------------------
187  void OnConnect( uint16_t subStream );
188 
189  //------------------------------------------------------------------------
191  //------------------------------------------------------------------------
192  void OnConnectError( uint16_t subStream, Status status );
193 
194  //------------------------------------------------------------------------
196  //------------------------------------------------------------------------
197  void OnError( uint16_t subStream, Status status );
198 
199  //------------------------------------------------------------------------
201  //------------------------------------------------------------------------
202  void OnReadTimeout( uint16_t subStream );
203 
204  //------------------------------------------------------------------------
206  //------------------------------------------------------------------------
207  void OnWriteTimeout( uint16_t subStream );
208 
209  //------------------------------------------------------------------------
211  //------------------------------------------------------------------------
212  void RegisterEventHandler( ChannelEventHandler *handler );
213 
214  //------------------------------------------------------------------------
216  //------------------------------------------------------------------------
217  void RemoveEventHandler( ChannelEventHandler *handler );
218 
219  private:
220  //------------------------------------------------------------------------
222  //------------------------------------------------------------------------
223  void OnFatalError( uint16_t subStream,
224  Status status,
225  XrdSysMutexHelper &lock );
226 
227  //------------------------------------------------------------------------
229  //------------------------------------------------------------------------
230  void MonitorDisconnection( Status status );
231 
232  typedef std::vector<SubStreamData*> SubStreamList;
233 
234  //------------------------------------------------------------------------
235  // Data members
236  //------------------------------------------------------------------------
237  const URL *pUrl;
238  uint16_t pStreamNum;
239  std::string pStreamName;
253  std::vector<sockaddr_in> pAddresses;
255  uint64_t pSessionId;
256 
257  //------------------------------------------------------------------------
258  // Monitoring info
259  //------------------------------------------------------------------------
262  uint64_t pBytesSent;
263  uint64_t pBytesReceived;
264  };
265 }
266 
267 #endif // __XRD_CL_STREAM_HH__