xrootd
XrdClPollerLibEvent.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_LIBEVENT_HH__
20 #define __XRD_CL_POLLER_LIBEVENT_HH__
21 
22 #include "XrdSys/XrdSysPthread.hh"
23 
24 #include "XrdCl/XrdClPoller.hh"
25 #include <pthread.h>
26 #include <map>
27 
28 struct event_base;
29 struct event;
30 
31 namespace XrdCl
32 {
33 
34  //----------------------------------------------------------------------------
36  //----------------------------------------------------------------------------
37  class PollerLibEvent: public Poller
38  {
39  public:
40  //------------------------------------------------------------------------
42  //------------------------------------------------------------------------
44 
45  //------------------------------------------------------------------------
47  //------------------------------------------------------------------------
48  virtual bool Initialize();
49 
50  //------------------------------------------------------------------------
52  //------------------------------------------------------------------------
53  virtual bool Finalize();
54 
55  //------------------------------------------------------------------------
57  //------------------------------------------------------------------------
58  virtual bool Start();
59 
60  //------------------------------------------------------------------------
62  //------------------------------------------------------------------------
63  virtual bool Stop();
64 
65  //------------------------------------------------------------------------
70  //------------------------------------------------------------------------
71  virtual bool AddSocket( Socket *socket,
72  SocketHandler *handler );
73 
74 
75  //------------------------------------------------------------------------
77  //------------------------------------------------------------------------
78  virtual bool RemoveSocket( Socket *socket );
79 
80  //------------------------------------------------------------------------
87  //------------------------------------------------------------------------
88  virtual bool EnableReadNotification( Socket *socket,
89  bool notify,
90  uint16_t timeout = 60 );
91 
92  //------------------------------------------------------------------------
99  //------------------------------------------------------------------------
100  virtual bool EnableWriteNotification( Socket *socket,
101  bool notify,
102  uint16_t timeout = 60);
103 
104  //------------------------------------------------------------------------
106  //------------------------------------------------------------------------
107  virtual bool IsRegistered( Socket *socket );
108 
109  //------------------------------------------------------------------------
111  //------------------------------------------------------------------------
112  virtual bool IsRunning() const
113  {
114  return pPollerThreadRunning;
115  }
116 
117  //------------------------------------------------------------------------
119  //------------------------------------------------------------------------
120  int RunEventLoop();
121 
122  private:
123  typedef std::map<const Socket *, void *> SocketMap;
126  event_base *pEventBase;
127  pthread_t pPollerThread;
129  };
130 }
131 
132 #endif // __XRD_CL_POLLER_LIBEVENT_HH__