#include <network_ioservice.h>
An AioService instance enables asynchronous network I/O for multiple writers/readers. Its purpose is to wait on potentially blocking I/O operations in a separate worker thread. Writers/readers can register at the AioService with a specific socket handle. They will receive notifications when I/O on these sockets is ready. Notifications happen through calls of the respective notification functions from the worker thread. The actual I/O work is implemented in these notification functions.
AioService can demultiplex multiple I/O requests from a single-thread. The advantage of this scheme is that it's not necessary to spin up one thread for every blocking operation.
Public Member Functions | |
MAXON_METHOD Result< Int > | RegisterReader (SocketT sockfd, const AioReaderRef &reader) |
MAXON_METHOD void | UnregisterReader (Int id) |
MAXON_METHOD Result< Int > | RegisterWriter (SocketT sockfd, const AioWriterRef &writer) |
MAXON_METHOD void | UnregisterWriter (Int id) |
MAXON_METHOD Result< void > | Start () |
MAXON_METHOD void | Stop () |
MAXON_METHOD void | StopAndWait () |
Static Public Member Functions | |
static MAXON_METHOD AioServiceInterface * | Alloc (MAXON_SOURCE_LOCATION_DECLARATION) |
Private Member Functions | |
MAXON_INTERFACE_NONVIRTUAL (AioServiceInterface, MAXON_REFERENCE_NORMAL, "net.maxon.interface.aioservice") | |
|
private |
|
static |
MAXON_METHOD Result<Int> RegisterReader | ( | SocketT | sockfd, |
const AioReaderRef & | reader | ||
) |
Registers a socket for reading. The given reader will be notified through its NotifyForRead function as soon as there's data available. This AioService instance will take shared ownership of the reader while it is registered. The socket is expected to remain valid until the reader is unregistered. If the registration succeeded, a unique registration ID is returned. It can be passed to UnregisterReader to remove the registration.
THREADSAFE.
[in] | sockfd | The socket handle selected for reading. |
[in] | reader | The reader to be notified when data is available. |
MAXON_METHOD void UnregisterReader | ( | Int | id | ) |
Unregisters a previously registered socket for reading, identified by the registration ID previously returned by the corresponding call to RegisterReader. If no reader with the given ID was found, the function has no effect.
THREADSAFE.
[in] | id | A registration ID previously returned by RegisterReader. |
MAXON_METHOD Result<Int> RegisterWriter | ( | SocketT | sockfd, |
const AioWriterRef & | writer | ||
) |
Analogously defined to RegisterReader, but for writer sockets instead of readers. The notification function is NotifyForWrite.
THREADSAFE.
MAXON_METHOD void UnregisterWriter | ( | Int | id | ) |
Analogously defined to UnregisterReader, but for writer sockets instead of readers.
THREADSAFE.
MAXON_METHOD Result<void> Start | ( | ) |
Starts this service. This will usually start at least one background thread to service I/O requests through notifications.
MAXON_METHOD void Stop | ( | ) |
Stops the service. If the service was already stopped, the function has no effect.
MAXON_METHOD void StopAndWait | ( | ) |
Stops the service and waits until the underlying I/O threads are shut down. If the service was already stopped, the function has no effect and returns immediately.