XRootD
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  //------------------------------------------------------------------------
46  PollerBuiltIn() : pNbPoller( GetNbPollerInit() ){}
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  //------------------------------------------------------------------------
127  XrdSys::IOEvents::Poller* GetNextPoller();
128 
129  //------------------------------------------------------------------------
131  //------------------------------------------------------------------------
132  XrdSys::IOEvents::Poller* RegisterAndGetPoller(const Socket *socket);
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 
155  SocketMap pSocketMap;
156  PollerMap pPollerMap;
157  PollerPool pPollerPool;
158  PollerPool::iterator pNext;
159  const int pNbPoller;
160  XrdSysMutex pMutex;
161  };
162 }
163 
164 #endif // __XRD_CL_POLLER_BUILT_IN_HH__
A poller implementation using the build-in XRootD poller.
virtual bool EnableWriteNotification(Socket *socket, bool notify, uint16_t timeout=60)
virtual bool AddSocket(Socket *socket, SocketHandler *handler)
virtual bool RemoveSocket(Socket *socket)
Remove the socket.
virtual bool EnableReadNotification(Socket *socket, bool notify, uint16_t timeout=60)
virtual bool Stop()
Stop polling.
virtual bool IsRegistered(Socket *socket)
Check whether the socket is registered with the poller.
virtual bool Finalize()
Finalize the poller.
virtual bool Initialize()
Initialize the poller.
virtual bool IsRunning() const
Is the event loop running?
virtual bool Start()
Start polling.
Interface for socket pollers.
Definition: XrdClPoller.hh:87
A network socket.
Definition: XrdClSocket.hh:43