XRootD
XrdClPoller.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_POLLER_HH__
20 #define __XRD_CL_POLLER_HH__
21 
22 #include <cstdint>
23 #include <ctime>
24 #include <string>
25 
26 namespace XrdCl
27 {
28  class Socket;
29  class Poller;
30 
31  //----------------------------------------------------------------------------
33  //----------------------------------------------------------------------------
35  {
36  public:
37  //------------------------------------------------------------------------
39  //------------------------------------------------------------------------
40  enum EventType
41  {
42  ReadyToRead = 0x01,
43  ReadTimeOut = 0x02,
44  ReadyToWrite = 0x04,
45  WriteTimeOut = 0x08
46  };
47 
48  //------------------------------------------------------------------------
49  // Destructor
50  //------------------------------------------------------------------------
51  virtual ~SocketHandler() {}
52 
53  //------------------------------------------------------------------------
55  //------------------------------------------------------------------------
56  virtual void Initialize( Poller * ) {}
57 
58  //------------------------------------------------------------------------
60  //------------------------------------------------------------------------
61  virtual void Finalize() {};
62 
63  //------------------------------------------------------------------------
65  //------------------------------------------------------------------------
66  virtual void Event( uint8_t type,
67  Socket *socket ) = 0;
68 
69  //------------------------------------------------------------------------
71  //------------------------------------------------------------------------
72  static std::string EventTypeToString( uint8_t event )
73  {
74  std::string ev;
75  if( event & ReadyToRead ) ev += "ReadyToRead|";
76  if( event & ReadTimeOut ) ev += "ReadTimeOut|";
77  if( event & ReadyToWrite ) ev += "ReadyToWrite|";
78  if( event & WriteTimeOut ) ev += "WriteTimeOut|";
79  ev.erase( ev.length()-1, 1) ;
80  return ev;
81  }
82  };
83 
84  //----------------------------------------------------------------------------
86  //----------------------------------------------------------------------------
87  class Poller
88  {
89  public:
90  //------------------------------------------------------------------------
92  //------------------------------------------------------------------------
93  virtual ~Poller() {}
94 
95  //------------------------------------------------------------------------
97  //------------------------------------------------------------------------
98  virtual bool Initialize() = 0;
99 
100  //------------------------------------------------------------------------
102  //------------------------------------------------------------------------
103  virtual bool Finalize() = 0;
104 
105  //------------------------------------------------------------------------
107  //------------------------------------------------------------------------
108  virtual bool Start() = 0;
109 
110  //------------------------------------------------------------------------
112  //------------------------------------------------------------------------
113  virtual bool Stop() = 0;
114 
115  //------------------------------------------------------------------------
120  //------------------------------------------------------------------------
121  virtual bool AddSocket( Socket *socket,
122  SocketHandler *handler ) = 0;
123 
124  //------------------------------------------------------------------------
130  //------------------------------------------------------------------------
131  virtual bool RemoveSocket( Socket *socket ) = 0;
132 
133  //------------------------------------------------------------------------
136  //------------------------------------------------------------------------
137  virtual void ShutdownEvents( Socket *socket ) = 0;
138 
139  //------------------------------------------------------------------------
146  //------------------------------------------------------------------------
147  virtual bool EnableReadNotification( Socket *socket,
148  bool notify,
149  time_t timeout = 60 ) = 0;
150 
151  //------------------------------------------------------------------------
157  //------------------------------------------------------------------------
158  virtual bool EnableWriteNotification( Socket *socket,
159  bool notify,
160  time_t timeout = 60 ) = 0;
161 
162  //------------------------------------------------------------------------
164  //------------------------------------------------------------------------
165  virtual bool IsRegistered( Socket *socket ) = 0;
166 
167  //------------------------------------------------------------------------
169  //------------------------------------------------------------------------
170  virtual bool IsRunning() const = 0;
171  };
172 }
173 
174 #endif // __XRD_CL_POLLER_HH__
Interface for socket pollers.
Definition: XrdClPoller.hh:88
virtual void ShutdownEvents(Socket *socket)=0
virtual bool Start()=0
Start polling.
virtual bool IsRunning() const =0
Is the event loop running?
virtual bool Finalize()=0
Finalize the poller.
virtual ~Poller()
Destructor.
Definition: XrdClPoller.hh:93
virtual bool AddSocket(Socket *socket, SocketHandler *handler)=0
virtual bool RemoveSocket(Socket *socket)=0
virtual bool Initialize()=0
Initialize the poller.
virtual bool IsRegistered(Socket *socket)=0
Check whether the socket is registered with the poller.
virtual bool EnableWriteNotification(Socket *socket, bool notify, time_t timeout=60)=0
virtual bool Stop()=0
Stop polling.
virtual bool EnableReadNotification(Socket *socket, bool notify, time_t timeout=60)=0
virtual ~SocketHandler()
Definition: XrdClPoller.hh:51
virtual void Finalize()
Finalizer.
Definition: XrdClPoller.hh:61
virtual void Event(uint8_t type, Socket *socket)=0
Called when an event occurred on a given socket.
EventType
Event type.
Definition: XrdClPoller.hh:41
@ ReadTimeOut
Read timeout.
Definition: XrdClPoller.hh:43
@ ReadyToWrite
Writing won't block.
Definition: XrdClPoller.hh:44
@ WriteTimeOut
Write timeout.
Definition: XrdClPoller.hh:45
@ ReadyToRead
New data has arrived.
Definition: XrdClPoller.hh:42
static std::string EventTypeToString(uint8_t event)
Translate the event type to a string.
Definition: XrdClPoller.hh:72
virtual void Initialize(Poller *)
Initializer.
Definition: XrdClPoller.hh:56
A network socket.
Definition: XrdClSocket.hh:43