event: add API documentation

This commit is contained in:
Max Kellermann 2013-11-24 19:28:04 +01:00
parent 41e7145973
commit e53a25cbae
5 changed files with 38 additions and 1 deletions

View File

@ -45,6 +45,15 @@ class SocketMonitor;
#include <assert.h> #include <assert.h>
/**
* An event loop that polls for events on file/socket descriptors.
*
* This class is not thread-safe, all methods must be called from the
* thread that runs it, except where explicitly documented as
* thread-safe.
*
* @see SocketMonitor, MultiSocketMonitor, TimeoutMonitor, IdleMonitor
*/
class EventLoop final class EventLoop final
#ifdef USE_EPOLL #ifdef USE_EPOLL
: private SocketMonitor : private SocketMonitor
@ -107,10 +116,18 @@ public:
EventLoop(Default dummy=Default()); EventLoop(Default dummy=Default());
~EventLoop(); ~EventLoop();
/**
* A caching wrapper for MonotonicClockMS().
*/
unsigned GetTimeMS() const { unsigned GetTimeMS() const {
return now_ms; return now_ms;
} }
/**
* Stop execution of this #EventLoop at the next chance. This
* method is thread-safe and non-blocking: after returning, it
* is not guaranteed that the EventLoop has really stopped.
*/
void Break(); void Break();
bool AddFD(int _fd, unsigned flags, SocketMonitor &m) { bool AddFD(int _fd, unsigned flags, SocketMonitor &m) {
@ -138,6 +155,10 @@ public:
void AddCall(std::function<void()> &&f); void AddCall(std::function<void()> &&f);
/**
* The main function of this class. It will loop until
* Break() gets called. Can be called only once.
*/
void Run(); void Run();
private: private:

View File

@ -47,7 +47,10 @@
class EventLoop; class EventLoop;
/** /**
* Monitor multiple sockets. * Similar to #SocketMonitor, but monitors multiple sockets. To use
* it, implement the methods PrepareSockets() and DispatchSockets().
* In PrepareSockets(), use UpdateSocketList() and AddSocket().
* DispatchSockets() will be called if at least one socket is ready.
*/ */
class MultiSocketMonitor class MultiSocketMonitor
#ifdef USE_EPOLL #ifdef USE_EPOLL

View File

@ -36,6 +36,9 @@ typedef void (*server_socket_callback_t)(int fd,
class OneServerSocket; class OneServerSocket;
/**
* A socket that accepts incoming stream connections (e.g. TCP).
*/
class ServerSocket { class ServerSocket {
friend class OneServerSocket; friend class OneServerSocket;

View File

@ -43,6 +43,12 @@
class EventLoop; class EventLoop;
/**
* Monitor events on a socket. Call Schedule() to announce events
* you're interested in, or Cancel() to cancel your subscription. The
* #EventLoop will invoke virtual method OnSocketReady() as soon as
* any of the subscribed events are ready.
*/
class SocketMonitor { class SocketMonitor {
#ifdef USE_EPOLL #ifdef USE_EPOLL
#else #else

View File

@ -28,6 +28,10 @@
class EventLoop; class EventLoop;
/**
* This class monitors a timeout. Use Schedule() to begin the timeout
* or Cancel() to cancel it.
*/
class TimeoutMonitor { class TimeoutMonitor {
#ifdef USE_EPOLL #ifdef USE_EPOLL
friend class EventLoop; friend class EventLoop;