xrootd
Loading...
Searching...
No Matches
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 <string>
24
25namespace XrdCl
26{
27 class Socket;
28 class Poller;
29
30 //----------------------------------------------------------------------------
32 //----------------------------------------------------------------------------
34 {
35 public:
36 //------------------------------------------------------------------------
38 //------------------------------------------------------------------------
40 {
41 ReadyToRead = 0x01,
42 ReadTimeOut = 0x02,
43 ReadyToWrite = 0x04,
44 WriteTimeOut = 0x08
45 };
46
47 //------------------------------------------------------------------------
48 // Destructor
49 //------------------------------------------------------------------------
50 virtual ~SocketHandler() {}
51
52 //------------------------------------------------------------------------
54 //------------------------------------------------------------------------
55 virtual void Initialize( Poller * ) {}
56
57 //------------------------------------------------------------------------
59 //------------------------------------------------------------------------
60 virtual void Finalize() {};
61
62 //------------------------------------------------------------------------
64 //------------------------------------------------------------------------
65 virtual void Event( uint8_t type,
66 Socket *socket ) = 0;
67
68 //------------------------------------------------------------------------
70 //------------------------------------------------------------------------
71 static std::string EventTypeToString( uint8_t event )
72 {
73 std::string ev;
74 if( event & ReadyToRead ) ev += "ReadyToRead|";
75 if( event & ReadTimeOut ) ev += "ReadTimeOut|";
76 if( event & ReadyToWrite ) ev += "ReadyToWrite|";
77 if( event & WriteTimeOut ) ev += "WriteTimeOut|";
78 ev.erase( ev.length()-1, 1) ;
79 return ev;
80 }
81 };
82
83 //----------------------------------------------------------------------------
85 //----------------------------------------------------------------------------
86 class Poller
87 {
88 public:
89 //------------------------------------------------------------------------
91 //------------------------------------------------------------------------
92 virtual ~Poller() {}
93
94 //------------------------------------------------------------------------
96 //------------------------------------------------------------------------
97 virtual bool Initialize() = 0;
98
99 //------------------------------------------------------------------------
101 //------------------------------------------------------------------------
102 virtual bool Finalize() = 0;
103
104 //------------------------------------------------------------------------
106 //------------------------------------------------------------------------
107 virtual bool Start() = 0;
108
109 //------------------------------------------------------------------------
111 //------------------------------------------------------------------------
112 virtual bool Stop() = 0;
113
114 //------------------------------------------------------------------------
119 //------------------------------------------------------------------------
120 virtual bool AddSocket( Socket *socket,
121 SocketHandler *handler ) = 0;
122
123 //------------------------------------------------------------------------
125 //------------------------------------------------------------------------
126 virtual bool RemoveSocket( Socket *socket ) = 0;
127
128 //------------------------------------------------------------------------
135 //------------------------------------------------------------------------
136 virtual bool EnableReadNotification( Socket *socket,
137 bool notify,
138 uint16_t timeout = 60 ) = 0;
139
140 //------------------------------------------------------------------------
146 //------------------------------------------------------------------------
147 virtual bool EnableWriteNotification( Socket *socket,
148 bool notify,
149 uint16_t timeout = 60 ) = 0;
150
151 //------------------------------------------------------------------------
153 //------------------------------------------------------------------------
154 virtual bool IsRegistered( Socket *socket ) = 0;
155
156 //------------------------------------------------------------------------
158 //------------------------------------------------------------------------
159 virtual bool IsRunning() const = 0;
160 };
161}
162
163#endif // __XRD_CL_POLLER_HH__
Interface for socket pollers.
Definition XrdClPoller.hh:87
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:92
virtual bool EnableReadNotification(Socket *socket, bool notify, uint16_t timeout=60)=0
virtual bool EnableWriteNotification(Socket *socket, bool notify, uint16_t timeout=60)=0
virtual bool AddSocket(Socket *socket, SocketHandler *handler)=0
virtual bool RemoveSocket(Socket *socket)=0
Remove the socket.
virtual bool Initialize()=0
Initialize the poller.
virtual bool IsRegistered(Socket *socket)=0
Check whether the socket is registered with the poller.
virtual bool Stop()=0
Stop polling.
Interface.
Definition XrdClPoller.hh:34
virtual ~SocketHandler()
Definition XrdClPoller.hh:50
virtual void Finalize()
Finalizer.
Definition XrdClPoller.hh:60
virtual void Event(uint8_t type, Socket *socket)=0
Called when an event occurred on a given socket.
EventType
Event type.
Definition XrdClPoller.hh:40
@ ReadTimeOut
Read timeout.
Definition XrdClPoller.hh:42
@ ReadyToWrite
Writing won't block.
Definition XrdClPoller.hh:43
@ WriteTimeOut
Write timeout.
Definition XrdClPoller.hh:44
@ ReadyToRead
New data has arrived.
Definition XrdClPoller.hh:41
static std::string EventTypeToString(uint8_t event)
Translate the event type to a string.
Definition XrdClPoller.hh:71
virtual void Initialize(Poller *)
Initializer.
Definition XrdClPoller.hh:55
A network socket.
Definition XrdClSocket.hh:43
Definition XrdClAction.hh:34