xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
XrdClPollerBuiltIn.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_BUILT_IN_HH__
20 #define __XRD_CL_POLLER_BUILT_IN_HH__
21 
22 #include "XrdSys/XrdSysPthread.hh"
23 #include "XrdCl/XrdClPoller.hh"
24 #include <map>
25 #include <vector>
26 
27 
28 namespace XrdSys { namespace IOEvents
29 {
30  class Poller;
31 }; };
32 
33 namespace XrdCl
34 {
35  class AnyObject;
36 
37  //----------------------------------------------------------------------------
39  //----------------------------------------------------------------------------
40  class PollerBuiltIn: public Poller
41  {
42  public:
43  //------------------------------------------------------------------------
45  //------------------------------------------------------------------------
47 
49 
50  //------------------------------------------------------------------------
52  //------------------------------------------------------------------------
53  virtual bool Initialize();
54 
55  //------------------------------------------------------------------------
57  //------------------------------------------------------------------------
58  virtual bool Finalize();
59 
60  //------------------------------------------------------------------------
62  //------------------------------------------------------------------------
63  virtual bool Start();
64 
65  //------------------------------------------------------------------------
67  //------------------------------------------------------------------------
68  virtual bool Stop();
69 
70  //------------------------------------------------------------------------
75  //------------------------------------------------------------------------
76  virtual bool AddSocket( Socket *socket,
77  SocketHandler *handler );
78 
79 
80  //------------------------------------------------------------------------
82  //------------------------------------------------------------------------
83  virtual bool RemoveSocket( Socket *socket );
84 
85  //------------------------------------------------------------------------
92  //------------------------------------------------------------------------
93  virtual bool EnableReadNotification( Socket *socket,
94  bool notify,
95  uint16_t timeout = 60 );
96 
97  //------------------------------------------------------------------------
104  //------------------------------------------------------------------------
105  virtual bool EnableWriteNotification( Socket *socket,
106  bool notify,
107  uint16_t timeout = 60);
108 
109  //------------------------------------------------------------------------
111  //------------------------------------------------------------------------
112  virtual bool IsRegistered( Socket *socket );
113 
114  //------------------------------------------------------------------------
116  //------------------------------------------------------------------------
117  virtual bool IsRunning() const
118  {
119  return !pPollerPool.empty();
120  }
121 
122  private:
123 
124  //------------------------------------------------------------------------
126  //------------------------------------------------------------------------
128 
129  //------------------------------------------------------------------------
131  //------------------------------------------------------------------------
133 
134  //------------------------------------------------------------------------
136  //------------------------------------------------------------------------
137  void UnregisterFromPoller( const Socket *socket);
138 
139  //------------------------------------------------------------------------
141  //------------------------------------------------------------------------
142  XrdSys::IOEvents::Poller* GetPoller(const Socket *socket);
143 
144  //------------------------------------------------------------------------
146  //------------------------------------------------------------------------
147  static int GetNbPollerInit();
148 
149  // associates channel ID to a pair: poller and count (how many sockets where mapped to this poller)
150  typedef std::map<const AnyObject *, std::pair<XrdSys::IOEvents::Poller *, size_t> > PollerMap;
151 
152  typedef std::map<Socket *, void *> SocketMap;
153  typedef std::vector<XrdSys::IOEvents::Poller *> PollerPool;
154 
158  PollerPool::iterator pNext;
159  const int pNbPoller;
161  };
162 }
163 
164 #endif // __XRD_CL_POLLER_BUILT_IN_HH__
std::map< Socket *, void * > SocketMap
Definition: XrdClPollerBuiltIn.hh:152
const int pNbPoller
Definition: XrdClPollerBuiltIn.hh:159
A poller implementation using the build-in XRootD poller.
Definition: XrdClPollerBuiltIn.hh:40
Interface.
Definition: XrdClPoller.hh:33
Interface for socket pollers.
Definition: XrdClPoller.hh:86
std::map< const AnyObject *, std::pair< XrdSys::IOEvents::Poller *, size_t > > PollerMap
Definition: XrdClPollerBuiltIn.hh:150
~PollerBuiltIn()
Definition: XrdClPollerBuiltIn.hh:48
virtual bool EnableReadNotification(Socket *socket, bool notify, uint16_t timeout=60)
virtual bool Initialize()
Initialize the poller.
PollerBuiltIn()
Constructor.
Definition: XrdClPollerBuiltIn.hh:46
std::vector< XrdSys::IOEvents::Poller * > PollerPool
Definition: XrdClPollerBuiltIn.hh:153
PollerPool::iterator pNext
Definition: XrdClPollerBuiltIn.hh:158
XrdSys::IOEvents::Poller * GetNextPoller()
Goes over poller threads in round robin fashion.
virtual bool AddSocket(Socket *socket, SocketHandler *handler)
XrdSysMutex pMutex
Definition: XrdClPollerBuiltIn.hh:160
virtual bool IsRegistered(Socket *socket)
Check whether the socket is registered with the poller.
virtual bool IsRunning() const
Is the event loop running?
Definition: XrdClPollerBuiltIn.hh:117
Definition: XrdSysPthread.hh:164
virtual bool EnableWriteNotification(Socket *socket, bool notify, uint16_t timeout=60)
XrdSys::IOEvents::Poller * RegisterAndGetPoller(const Socket *socket)
Registers given socket as a poller user and returns the poller object.
PollerPool pPollerPool
Definition: XrdClPollerBuiltIn.hh:157
Definition: XrdSysIOEvents.hh:371
PollerMap pPollerMap
Definition: XrdClPollerBuiltIn.hh:156
static int GetNbPollerInit()
Gets the initial value for &#39;pNbPoller&#39;.
virtual bool Start()
Start polling.
virtual bool RemoveSocket(Socket *socket)
Remove the socket.
XrdSys::IOEvents::Poller * GetPoller(const Socket *socket)
Returns the poller object associated with the given socket.
virtual bool Stop()
Stop polling.
SocketMap pSocketMap
Definition: XrdClPollerBuiltIn.hh:155
void UnregisterFromPoller(const Socket *socket)
Unregisters given socket from poller object.
virtual bool Finalize()
Finalize the poller.
A network socket.
Definition: XrdClSocket.hh:42