21#ifndef INCLUDE_OLA_IO_SELECTSERVER_H_
22#define INCLUDE_OLA_IO_SELECTSERVER_H_
28#include <ola/io/SelectServerInterface.h>
29#include <ola/network/Socket.h>
30#include <ola/thread/Thread.h>
36class 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;
Export variables on the http server.
The base class for all 0 argument callbacks.
Definition Callback.h:119
A 0 argument callback which can be called multiple times.
Definition Callback.h:129
Used to get the current time.
Definition Clock.h:230
A container for the exported variables.
Definition ExportMap.h:324
A 0 argument callback which deletes itself after it's run.
Definition Callback.h:141
A BidirectionalFileDescriptor that also generates notifications when closed.
Definition Descriptor.h:283
A loopback descriptor.
Definition Descriptor.h:399
Represents a file descriptor that supports reading data.
Definition Descriptor.h:140
A single threaded I/O event management system.
Definition SelectServer.h:63
void SetDefaultInterval(const TimeInterval &block_interval)
Set the duration to block for.
Definition SelectServer.cpp:122
bool IsRunning() const
Checks if the SelectServer is running.
Definition SelectServer.h:115
ola::thread::timeout_id RegisterSingleTimeout(unsigned int ms, ola::SingleUseCallback0< void > *callback)
Execute a callback after a certain time interval.
Definition SelectServer.cpp:231
SelectServer(ola::ExportMap *export_map=NULL, Clock *clock=NULL)
Create a new SelectServer.
Definition SelectServer.cpp:77
ola::thread::timeout_id RegisterRepeatingTimeout(unsigned int ms, ola::Callback0< bool > *callback)
Execute a callback periodically.
Definition SelectServer.cpp:217
void RemoveTimeout(ola::thread::timeout_id id)
Cancel an existing timeout.
Definition SelectServer.cpp:245
void DrainCallbacks()
Run all callbacks until there are none left.
Definition SelectServer.cpp:268
const TimeStamp * WakeUpTime() const
The time when this SelectServer was woken up.
Definition SelectServer.cpp:108
void RunInLoop(ola::Callback0< void > *callback)
Execute a callback on every event loop.
Definition SelectServer.cpp:249
void Execute(ola::BaseCallback0< void > *callback)
Execute the supplied callback at some point in the future.
Definition SelectServer.cpp:253
void Terminate()
Exit from the Run() loop.
Definition SelectServer.cpp:116
void RunOnce()
Do a single pass through the event loop. Does not block.
Definition SelectServer.cpp:143
bool AddWriteDescriptor(WriteFileDescriptor *descriptor)
Register a WriteFileDescriptor for write-events.
Definition SelectServer.cpp:197
void RemoveReadDescriptor(ReadFileDescriptor *descriptor)
Remove a ReadFileDescriptor for read-events.
Definition SelectServer.cpp:171
void Run()
Enter the event loop.
Definition SelectServer.cpp:126
~SelectServer()
Clean up.
Definition SelectServer.cpp:99
void RemoveWriteDescriptor(WriteFileDescriptor *descriptor)
Remove a WriteFileDescriptor for write-events.
Definition SelectServer.cpp:205
bool AddReadDescriptor(ReadFileDescriptor *descriptor)
Register a ReadFileDescriptor for read-events.
Definition SelectServer.cpp:153
The interface for the SelectServer.
Definition SelectServerInterface.h:42
Represents a file descriptor that supports writing data.
Definition Descriptor.h:170
void * timeout_id
A timeout handle which can later be used to cancel a timeout.
Definition SchedulerInterface.h:34
The namespace containing all OLA symbols.
Definition Credentials.cpp:44
Definition SelectServer.h:65
Clock * clock
The Clock to use.
Definition SelectServer.h:87
bool force_select
Fall back to the select() implementation even if the flags are set for kqueue/epoll.
Definition SelectServer.h:77
ola::ExportMap * export_map
The export map to use.
Definition SelectServer.h:82