5#ifndef WPINET_UV_LOOP_H_
6#define WPINET_UV_LOOP_H_
37class Loop final :
public std::enable_shared_from_this<Loop> {
38 struct private_init {};
41 using Time = std::chrono::duration<uint64_t, std::milli>;
49 explicit Loop(
const private_init&)
noexcept;
112 m_tid = std::this_thread::get_id();
114 m_tid = std::thread::id{};
155 return std::make_pair(to == -1,
Time{to});
231 template <
typename T =
void>
233 return std::static_pointer_cast<T>(m_data);
260 std::shared_ptr<void> m_data;
263 std::atomic<std::thread::id> m_tid;
264 bool m_closing =
false;
An efficient, type-erasing, non-owning reference to a callable.
Definition: function_ref.h:31
SignalBase is an implementation of the observer pattern, through the use of an emitting object and sl...
Definition: Signal.h:495
Error code.
Definition: Error.h:15
Handle.
Definition: Handle.h:30
Event loop.
Definition: Loop.h:37
Mode
Definition: Loop.h:43
@ kDefault
Definition: Loop.h:44
@ kOnce
Definition: Loop.h:45
@ kNoWait
Definition: Loop.h:46
void ReportError(int err)
Reports error.
Definition: Loop.h:257
std::thread::id GetThreadId() const
Get the thread id of the loop thread.
Definition: Loop.h:246
void Fork()
Reinitialize any kernel state necessary in the child process after a fork(2) system call.
std::chrono::duration< uint64_t, std::milli > Time
Definition: Loop.h:41
void SetClosing()
Set the loop closing flag.
Definition: Loop.h:78
static std::shared_ptr< Loop > Create()
Create a new event loop.
std::shared_ptr< T > GetData() const
Gets user-defined data.
Definition: Loop.h:232
int GetDescriptor() const noexcept
Get backend file descriptor.
Definition: Loop.h:144
Loop(const Loop &)=delete
void Close()
Release all internal loop resources.
uv_loop_t * GetRaw() const noexcept
Get the underlying event loop data structure.
Definition: Loop.h:225
Time Now() const noexcept
Return the current timestamp in milliseconds.
Definition: Loop.h:170
bool IsAlive() const noexcept
Check if there are active resources.
Definition: Loop.h:123
static std::shared_ptr< Loop > GetDefault()
Create the default event loop.
void UpdateTime() noexcept
Update the event loop’s concept of now.
Definition: Loop.h:181
void SetData(std::shared_ptr< void > data)
Sets user-defined data.
Definition: Loop.h:240
Loop & operator=(Loop &&oth)=delete
Loop(const private_init &) noexcept
bool Run(Mode mode=kDefault)
Run the event loop.
Definition: Loop.h:111
void Stop() noexcept
Stop the event loop.
Definition: Loop.h:133
void Walk(function_ref< void(Handle &)> callback)
Walk the list of handles.
bool IsClosing() const
Return the loop closed flag.
Definition: Loop.h:85
sig::Signal< Error > error
Error signal.
Definition: Loop.h:251
Loop & operator=(const Loop &)=delete
std::pair< bool, Time > GetTimeout() const noexcept
Get the poll timeout.
Definition: Loop.h:153
Definition: StdDeque.h:50
Definition: ParallelTcpConnector.h:22
Definition: format.h:1544
UV_EXTERN void uv_stop(uv_loop_t *)
uv_run_mode
Definition: uv.h:251
@ UV_RUN_NOWAIT
Definition: uv.h:254
@ UV_RUN_ONCE
Definition: uv.h:253
@ UV_RUN_DEFAULT
Definition: uv.h:252
UV_EXTERN int uv_backend_timeout(const uv_loop_t *)
UV_EXTERN int uv_backend_fd(const uv_loop_t *)
UV_EXTERN int uv_run(uv_loop_t *, uv_run_mode mode)
UV_EXTERN uint64_t uv_now(const uv_loop_t *)
UV_EXTERN int uv_loop_alive(const uv_loop_t *loop)
UV_EXTERN void uv_update_time(uv_loop_t *)