Commit e53a25cb authored by Max Kellermann's avatar Max Kellermann

event: add API documentation

parent 41e71459
......@@ -45,6 +45,15 @@ class SocketMonitor;
#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
#ifdef USE_EPOLL
: private SocketMonitor
......@@ -107,10 +116,18 @@ public:
EventLoop(Default dummy=Default());
~EventLoop();
/**
* A caching wrapper for MonotonicClockMS().
*/
unsigned GetTimeMS() const {
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();
bool AddFD(int _fd, unsigned flags, SocketMonitor &m) {
......@@ -138,6 +155,10 @@ public:
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();
private:
......
......@@ -47,7 +47,10 @@
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
#ifdef USE_EPOLL
......
......@@ -36,6 +36,9 @@ typedef void (*server_socket_callback_t)(int fd,
class OneServerSocket;
/**
* A socket that accepts incoming stream connections (e.g. TCP).
*/
class ServerSocket {
friend class OneServerSocket;
......
......@@ -43,6 +43,12 @@
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 {
#ifdef USE_EPOLL
#else
......
......@@ -28,6 +28,10 @@
class EventLoop;
/**
* This class monitors a timeout. Use Schedule() to begin the timeout
* or Cancel() to cancel it.
*/
class TimeoutMonitor {
#ifdef USE_EPOLL
friend class EventLoop;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment