XRootD
Loading...
Searching...
No Matches
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
23#include "XrdCl/XrdClPoller.hh"
24#include <map>
25#include <vector>
26
27
28namespace XrdSys { namespace IOEvents
29{
30 class Poller;
31}; };
32
33namespace 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 //------------------------------------------------------------------------
88 //------------------------------------------------------------------------
89 virtual void ShutdownEvents( Socket *socket );
90
91 //------------------------------------------------------------------------
98 //------------------------------------------------------------------------
99 virtual bool EnableReadNotification( Socket *socket,
100 bool notify,
101 time_t timeout = 60 );
102
103 //------------------------------------------------------------------------
110 //------------------------------------------------------------------------
111 virtual bool EnableWriteNotification( Socket *socket,
112 bool notify,
113 time_t timeout = 60);
114
115 //------------------------------------------------------------------------
117 //------------------------------------------------------------------------
118 virtual bool IsRegistered( Socket *socket );
119
120 //------------------------------------------------------------------------
122 //------------------------------------------------------------------------
123 virtual bool IsRunning() const
124 {
125 return !pPollerPool.empty();
126 }
127
128 private:
129
130 //------------------------------------------------------------------------
132 //------------------------------------------------------------------------
133 XrdSys::IOEvents::Poller* GetNextPoller();
134
135 //------------------------------------------------------------------------
137 //------------------------------------------------------------------------
138 XrdSys::IOEvents::Poller* RegisterAndGetPoller(const Socket *socket);
139
140 //------------------------------------------------------------------------
142 //------------------------------------------------------------------------
143 void UnregisterFromPoller( const Socket *socket);
144
145 //------------------------------------------------------------------------
147 //------------------------------------------------------------------------
148 XrdSys::IOEvents::Poller* GetPoller(const Socket *socket);
149
150 //------------------------------------------------------------------------
152 //------------------------------------------------------------------------
153 static int GetNbPollerInit();
154
155 // associates socket file descriptor to a poller
156 typedef std::map<int, XrdSys::IOEvents::Poller *> PollerMap;
157
158 typedef std::map<Socket *, void *> SocketMap;
159 typedef std::vector<XrdSys::IOEvents::Poller *> PollerPool;
160
161 SocketMap pSocketMap;
162 PollerMap pPollerMap;
163 PollerPool pPollerPool;
164 PollerPool::iterator pNext;
165 const int pNbPoller;
166 XrdSysMutex pMutex;
167 };
168}
169
170#endif // __XRD_CL_POLLER_BUILT_IN_HH__
virtual bool AddSocket(Socket *socket, SocketHandler *handler)
virtual bool EnableReadNotification(Socket *socket, bool notify, time_t timeout=60)
virtual bool RemoveSocket(Socket *socket)
Remove the socket.
virtual bool Stop()
Stop polling.
virtual void ShutdownEvents(Socket *socket)
virtual bool EnableWriteNotification(Socket *socket, bool notify, time_t timeout=60)
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.
A network socket.