21 #ifndef INCLUDE_OLA_IO_SELECTSERVER_H_
22 #define INCLUDE_OLA_IO_SELECTSERVER_H_
25 #include <ola/Clock.h>
28 #include <ola/io/SelectServerInterface.h>
29 #include <ola/network/Socket.h>
30 #include <ola/thread/Thread.h>
36 class SelectServerTest;
156 bool delete_on_close =
false);
195 typedef std::vector<ola::BaseCallback0<void>*> Callbacks;
196 typedef std::set<ola::Callback0<void>*> LoopClosureSet;
199 bool m_terminate, m_is_running;
201 std::auto_ptr<class TimeoutManager> m_timeout_manager;
202 std::auto_ptr<class PollerInterface> m_poller;
206 LoopClosureSet m_loop_callbacks;
207 Callbacks m_incoming_callbacks;
211 void Init(
const Options &options);
213 void DrainAndExecute();
214 void RunCallbacks(Callbacks *callbacks);
215 void SetTerminate() { m_terminate =
true; }
218 static const unsigned int POLL_INTERVAL_SECOND = 10;
219 static const unsigned int POLL_INTERVAL_USECOND = 0;
223 friend class ::SelectServerTest;
229 #endif // INCLUDE_OLA_IO_SELECTSERVER_H_
Clock * clock
The Clock to use.
Definition: SelectServer.h:87
~SelectServer()
Clean up.
Definition: SelectServer.cpp:99
Definition: SelectServer.h:65
A 0 arg, single use callback that returns void.
Definition: Callback.h:157
void SetDefaultInterval(const TimeInterval &block_interval)
Set the duration to block for.
Definition: SelectServer.cpp:122
A container for the exported variables.
Definition: ExportMap.h:324
A BidirectionalFileDescriptor that also generates notifications when closed.
Definition: Descriptor.h:282
A 0 argument callback which can be called multiple times.
Definition: Callback.h:129
void RemoveReadDescriptor(ReadFileDescriptor *descriptor)
Remove a ReadFileDescriptor for read-events.
Definition: SelectServer.cpp:171
void RemoveTimeout(ola::thread::timeout_id id)
Cancel an existing timeout.
Definition: SelectServer.cpp:245
void Terminate()
Exit from the Run() loop.
Definition: SelectServer.cpp:116
Export variables on the http server.
void Run()
Enter the event loop.
Definition: SelectServer.cpp:126
void * timeout_id
A timeout handle which can later be used to cancel a timeout.
Definition: SchedulerInterface.h:34
ola::thread::timeout_id RegisterRepeatingTimeout(unsigned int ms, ola::Callback0< bool > *callback)
Execute a callback periodically.
Definition: SelectServer.cpp:217
ola::thread::timeout_id RegisterSingleTimeout(unsigned int ms, ola::SingleUseCallback0< void > *callback)
Execute a callback after a certain time interval.
Definition: SelectServer.cpp:231
The interface for the SelectServer.
Definition: SelectServerInterface.h:42
void Execute(ola::BaseCallback0< void > *callback)
Execute the supplied callback at some point in the future.
Definition: SelectServer.cpp:253
Used to get the current time.
Definition: Clock.h:221
bool IsRunning() const
Checks if the SelectServer is running.
Definition: SelectServer.h:115
A single threaded I/O event management system.
Definition: SelectServer.h:63
A loopback descriptor.
Definition: Descriptor.h:398
Represents a file descriptor that supports reading data.
Definition: Descriptor.h:140
void RunInLoop(ola::Callback0< void > *callback)
Execute a callback on every event loop.
Definition: SelectServer.cpp:249
void DrainCallbacks()
Run all callbacks until there are none left.
Definition: SelectServer.cpp:268
bool AddReadDescriptor(ReadFileDescriptor *descriptor)
Register a ReadFileDescriptor for read-events.
Definition: SelectServer.cpp:153
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
ola::ExportMap * export_map
The export map to use.
Definition: SelectServer.h:82
bool AddWriteDescriptor(WriteFileDescriptor *descriptor)
Register a WriteFileDescriptor for write-events.
Definition: SelectServer.cpp:197
void RemoveWriteDescriptor(WriteFileDescriptor *descriptor)
Remove a WriteFileDescriptor for write-events.
Definition: SelectServer.cpp:205
bool force_select
Fall back to the select() implementation even if the flags are set for kqueue/epoll.
Definition: SelectServer.h:77
SelectServer(ola::ExportMap *export_map=NULL, Clock *clock=NULL)
Create a new SelectServer.
Definition: SelectServer.cpp:77
const TimeStamp * WakeUpTime() const
The time when this SelectServer was woken up.
Definition: SelectServer.cpp:108
void RunOnce()
Do a single pass through the event loop. Does not block.
Definition: SelectServer.cpp:143
Represents a file descriptor that supports writing data.
Definition: Descriptor.h:170