WPILibC++ 2024.3.2
|
#include <wpinet/uv/Loop.h>
Public Types | |
enum | Mode { kDefault = UV_RUN_DEFAULT , kOnce = UV_RUN_ONCE , kNoWait = UV_RUN_NOWAIT } |
using | Time = std::chrono::duration< uint64_t, std::milli > |
Public Member Functions | |
Loop (const private_init &) noexcept | |
Loop (const Loop &)=delete | |
Loop & | operator= (const Loop &)=delete |
Loop (Loop &&oth)=delete | |
Loop & | operator= (Loop &&oth)=delete |
~Loop () noexcept | |
void | SetClosing () |
Set the loop closing flag. More... | |
bool | IsClosing () const |
Return the loop closed flag. More... | |
void | Close () |
Release all internal loop resources. More... | |
bool | Run (Mode mode=kDefault) |
Run the event loop. More... | |
bool | IsAlive () const noexcept |
Check if there are active resources. More... | |
void | Stop () noexcept |
Stop the event loop. More... | |
int | GetDescriptor () const noexcept |
Get backend file descriptor. More... | |
std::pair< bool, Time > | GetTimeout () const noexcept |
Get the poll timeout. More... | |
Time | Now () const noexcept |
Return the current timestamp in milliseconds. More... | |
void | UpdateTime () noexcept |
Update the event loop’s concept of now. More... | |
void | Walk (function_ref< void(Handle &)> callback) |
Walk the list of handles. More... | |
void | Fork () |
Reinitialize any kernel state necessary in the child process after a fork(2) system call. More... | |
uv_loop_t * | GetRaw () const noexcept |
Get the underlying event loop data structure. More... | |
template<typename T = void> | |
std::shared_ptr< T > | GetData () const |
Gets user-defined data. More... | |
void | SetData (std::shared_ptr< void > data) |
Sets user-defined data. More... | |
std::thread::id | GetThreadId () const |
Get the thread id of the loop thread. More... | |
void | ReportError (int err) |
Reports error. More... | |
Static Public Member Functions | |
static std::shared_ptr< Loop > | Create () |
Create a new event loop. More... | |
static std::shared_ptr< Loop > | GetDefault () |
Create the default event loop. More... | |
Public Attributes | |
sig::Signal< Error > | error |
Error signal. More... | |
Event loop.
The event loop is the central part of uv functionality. It takes care of polling for I/O and scheduling signals to be generated based on different sources of events.
The event loop is not moveable, copyable, or directly constructible. Use Create() to create an event loop, or GetDefault() to get the default loop if you know your program will only have a single one.
using wpi::uv::Loop::Time = std::chrono::duration<uint64_t, std::milli> |
enum wpi::uv::Loop::Mode |
|
explicitnoexcept |
|
delete |
|
delete |
|
noexcept |
void wpi::uv::Loop::Close | ( | ) |
Release 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.
error() will be emitted in case of errors.
|
static |
Create a new event loop.
The created loop is not the default event loop.
void wpi::uv::Loop::Fork | ( | ) |
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.
error() will be emitted in case of errors.
|
inline |
Gets user-defined data.
|
static |
Create the default event loop.
Only use this event loop if a single loop is needed for the entire application.
|
inlinenoexcept |
Get backend file descriptor.
Only kqueue, epoll and event ports are supported. This can be used in conjunction with run(Loop::kNoWait)
to poll in one thread and run the event loop’s callbacks in another.
|
inlinenoexcept |
Get the underlying event loop data structure.
|
inline |
Get the thread id of the loop thread.
If the loop is not currently running, returns default-constructed thread id.
|
inlinenoexcept |
Get the poll timeout.
std::pair
composed of a boolean value that is true in case of valid timeout, false otherwise, and the timeout (std::chrono::duration<uint64_t, std::milli>
).
|
inlinenoexcept |
Check if there are active resources.
|
inline |
Return the loop closed flag.
|
inlinenoexcept |
Return 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>
).
|
inline |
Reports error.
err | Error code |
Run the event loop.
Available modes are:
Loop::kDefault
: Run the event loop until there are no active and referenced handles or requests.Loop::kOnce
: Run a single event loop iteration. Note that this function blocksif there are no pending callbacks.Loop::kNoWait
: Run a single event loop iteration, but don't block if there are no pending callbacks.
|
inline |
Set the loop closing flag.
This will prevent new handles from being created on the loop.
|
inline |
Sets user-defined data.
data | User-defined arbitrary data. |
|
inlinenoexcept |
Stop the event loop.
This will cause 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.
|
inlinenoexcept |
Update 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.
void wpi::uv::Loop::Walk | ( | function_ref< void(Handle &)> | callback | ) |
Walk the list of handles.
The callback will be executed once for each handle that is still active.
callback | A function to be invoked once for each active handle. |
sig::Signal<Error> wpi::uv::Loop::error |
Error signal.