uvw 2.12.1
|
#include <loop.h>
Public Member Functions | |
template<typename... Args> | |
void | configure (Configure flag, Args &&...args) |
Sets additional loop options. | |
template<typename R , typename... Args> | |
std::shared_ptr< R > | resource (Args &&...args) |
Creates resources of any type. | |
void | close () |
Releases all internal loop resources. | |
template<Mode mode = Mode::DEFAULT> | |
bool | run () noexcept |
Runs the event loop. | |
bool | alive () const noexcept |
Checks if there are active resources. | |
void | stop () noexcept |
Stops the event loop. | |
int | descriptor () const noexcept |
Get backend file descriptor. | |
std::pair< bool, Time > | timeout () const noexcept |
Gets the poll timeout. | |
Time | idleTime () const noexcept |
Returns the amount of time the event loop has been idle. The call is thread safe. | |
Time | now () const noexcept |
Returns the current timestamp in milliseconds. | |
void | update () const noexcept |
Updates the event loop’s concept of now. | |
template<typename Func > | |
void | walk (Func callback) |
Walks the list of handles. | |
void | fork () noexcept |
Reinitialize any kernel state necessary in the child process after a fork(2) system call. | |
template<typename R = void> | |
std::shared_ptr< R > | data () const |
Gets user-defined data. uvw won't use this field in any case. | |
void | data (std::shared_ptr< void > uData) |
Sets arbitrary data. uvw won't use this field in any case. | |
const uv_loop_t * | raw () const noexcept |
Gets the underlying raw data structure. | |
uv_loop_t * | raw () noexcept |
Gets the underlying raw data structure. | |
![]() | |
Connection< E > | on (Listener< E > f) |
Registers a long-lived listener with the event emitter. | |
Connection< E > | once (Listener< E > f) |
Registers a short-lived listener with the event emitter. | |
void | erase (Connection< E > conn) noexcept |
Disconnects a listener from the event emitter. | |
void | clear () noexcept |
Disconnects all the listeners for the given event type. | |
void | clear () noexcept |
Disconnects all the listeners. | |
bool | empty () const noexcept |
Checks if there are listeners registered for the specific event. | |
bool | empty () const noexcept |
Checks if there are listeners registered with the event emitter. | |
Static Public Member Functions | |
static std::shared_ptr< Loop > | create () |
Initializes a new Loop instance. | |
static std::shared_ptr< Loop > | create (uv_loop_t *loop) |
Initializes a new Loop instance from an existing resource. | |
static std::shared_ptr< Loop > | getDefault () |
Gets the initialized default loop. | |
The Loop class.
The event loop is the central part of uvw
's functionalities, as well as libuv
's ones.
It takes care of polling for I/O and scheduling callbacks to be run based on different sources of events.
|
noexcept |
Checks if there are active resources.
void uvw::Loop::close | ( | ) |
Releases all internal loop resources.
Call this function only when the loop has finished executing and all open handles and requests have been closed, or the loop will emit an error.
An ErrorEvent will be emitted in case of errors.
|
inline |
Sets additional loop options.
You should normally call this before the first call to uv_run() unless mentioned otherwise.
Supported options:
Loop::Configure::BLOCK_SIGNAL
: Block a signal when polling for new events. A second argument is required and it is the signal number.Loop::Configure::IDLE_TIME
: Accumulate the amount of idle time the event loop spends in the event provider. This option is necessary to use idleTime()
.An ErrorEvent will be emitted in case of errors.
See the official documentation for further details.
|
static |
Initializes a new Loop instance.
|
static |
Initializes a new Loop instance from an existing resource.
The lifetime of the resource must exceed that of the instance to which it's associated. Management of the memory associated with the resource is in charge of the user.
loop | A valid pointer to a correctly initialized resource. |
|
inline |
void uvw::Loop::data | ( | std::shared_ptr< void > | uData | ) |
Sets arbitrary data. uvw
won't use this field in any case.
uData | User-defined arbitrary data. |
|
noexcept |
Get backend file descriptor.
Only kqueue, epoll and event ports are supported.
This can be used in conjunction with run<Loop::Mode::NOWAIT>()
to poll in one thread and run the event loop’s callbacks in another.
|
noexcept |
Reinitialize any kernel state necessary in the child process after a fork(2) system call.
Previously started watchers will continue to be started in the child process.
It is necessary to explicitly call this function on every event loop created in the parent process that you plan to continue to use in the child, including the default loop (even if you don’t continue to use it in the parent). This function must be called before calling any API function using the loop in the child. Failure to do so will result in undefined behaviour, possibly including duplicate events delivered to both parent and child or aborting the child process.
When possible, it is preferred to create a new loop in the child process instead of reusing a loop created in the parent. New loops created in the child process after the fork should not use this function.
Note that this function is not implemented on Windows.
Note also that this function is experimental in libuv
. It may contain bugs, and is subject to change or removal. API and ABI stability is not guaranteed.
An ErrorEvent will be emitted in case of errors.
See the official documentation for further details.
|
static |
Gets the initialized default loop.
It may return an empty pointer in case of failure.
This function is just a convenient way for having a global loop throughout an application, the default loop is in no way different than the ones initialized with create()
.
As such, the default loop can be closed with close()
so the resources associated with it are freed (even if it is not strictly necessary).
|
noexcept |
Returns the amount of time the event loop has been idle. The call is thread safe.
|
noexcept |
Returns the current timestamp in milliseconds.
The timestamp is cached at the start of the event loop tick.
The timestamp increases monotonically from some arbitrary point in time.
Don’t make assumptions about the starting point, you will only get disappointed.
std::chrono::duration<uint64_t, std::milli>
).
|
noexcept |
Gets the underlying raw data structure.
This function should not be used, unless you know exactly what you are doing and what are the risks.
Going raw is dangerous, mainly because the lifetime management of a loop, a handle or a request is in charge to the library itself and users should not work around it.
|
noexcept |
Gets the underlying raw data structure.
This function should not be used, unless you know exactly what you are doing and what are the risks.
Going raw is dangerous, mainly because the lifetime management of a loop, a handle or a request is in charge to the library itself and users should not work around it.
|
inline |
Creates resources of any type.
This should be used as a default method to create resources.
The arguments are the ones required for the specific resource.
Use it as loop->resource<uvw::TimerHandle>()
.
|
noexcept |
Runs the event loop.
Available modes are:
Loop::Mode::DEFAULT
: Runs the event loop until there are no more active and referenced handles or requests.Loop::Mode::ONCE
: Poll for i/o once. Note that this function blocks if there are no pending callbacks.Loop::Mode::NOWAIT
: Poll for i/o once but don’t block if there are no pending callbacks.See the official documentation for further details.
|
noexcept |
Stops the event loop.
It causes run()
to end as soon as possible.
This will happen not sooner than the next loop iteration.
If this function was called before blocking for I/O, the loop won’t block for I/O on this iteration.
|
noexcept |
Gets the poll timeout.
std::pair
composed as it follows:std::chrono::duration<uint64_t, std::milli>
).
|
noexcept |
Updates the event loop’s concept of now.
The current time is cached at the start of the event loop tick in order to reduce the number of time-related system calls.
You won’t normally need to call this function unless you have callbacks that block the event loop for longer periods of time, where longer is somewhat subjective but probably on the order of a millisecond or more.
|
inline |