AioServiceInterface Class Reference

#include <network_ioservice.h>

Detailed Description

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< IntRegisterReader (SocketT sockfd, const AioReaderRef &reader)
MAXON_METHOD void UnregisterReader (Int id)
MAXON_METHOD Result< IntRegisterWriter (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


Private Member Functions

 MAXON_INTERFACE_NONVIRTUAL (AioServiceInterface, MAXON_REFERENCE_NORMAL, "net.maxon.interface.aioservice")

Member Function Documentation



◆ Alloc()

◆ RegisterReader()

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.


[in]sockfdThe socket handle selected for reading.
[in]readerThe reader to be notified when data is available.
A unique registration ID, or error if registration failed.

◆ UnregisterReader()

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.


[in]idA registration ID previously returned by RegisterReader.

◆ RegisterWriter()

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.


◆ UnregisterWriter()

MAXON_METHOD void UnregisterWriter ( Int  id)

Analogously defined to UnregisterReader, but for writer sockets instead of readers.


◆ Start()

MAXON_METHOD Result<void> Start ( )

Starts this service. This will usually start at least one background thread to service I/O requests through notifications.

OK, or error if the service was already started or an internal error occurred.

◆ Stop()

MAXON_METHOD void Stop ( )

Stops the service. If the service was already stopped, the function has no effect.

◆ StopAndWait()

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.