diff --git a/src/uvw/async.hpp b/src/uvw/async.hpp index 89ffeae1..b855cf10 100644 --- a/src/uvw/async.hpp +++ b/src/uvw/async.hpp @@ -12,6 +12,9 @@ namespace uvw { +struct AsyncEvent: Event { }; + + class Async final: public Handle { static void sendCallback(uv_async_t *handle) { Async &async = *(static_cast(handle->data)); diff --git a/src/uvw/check.hpp b/src/uvw/check.hpp index 6ec4477f..694a145d 100644 --- a/src/uvw/check.hpp +++ b/src/uvw/check.hpp @@ -12,6 +12,9 @@ namespace uvw { +struct CheckEvent: Event { }; + + class Check final: public Handle { static void startCallback(uv_check_t *handle) { Check &check = *(static_cast(handle->data)); diff --git a/src/uvw/event.hpp b/src/uvw/event.hpp index df003f2d..52b7b278 100644 --- a/src/uvw/event.hpp +++ b/src/uvw/event.hpp @@ -21,6 +21,7 @@ struct BaseEvent { BaseEvent::~BaseEvent() noexcept { } + template struct Event: BaseEvent { static std::size_t type() noexcept { @@ -30,29 +31,6 @@ struct Event: BaseEvent { }; -struct AsyncEvent: Event { }; -struct CheckEvent: Event { }; -struct CloseEvent: Event { }; -struct ConnectEvent: Event { }; - - -struct DataEvent: Event { - explicit DataEvent(std::unique_ptr ptr, ssize_t l) noexcept - : dt{std::move(ptr)}, len{l} - { } - - const char * data() const noexcept { return dt.get(); } - ssize_t length() const noexcept { return len; } - -private: - std::unique_ptr dt; - const ssize_t len; -}; - - -struct EndEvent: Event { }; - - struct ErrorEvent: Event { explicit ErrorEvent(int code = 0) noexcept: ec(code) { } @@ -75,61 +53,4 @@ private: }; -struct FsPollEvent: Event { - explicit FsPollEvent(const Stat &p, const Stat &c) noexcept - : prev(p), curr(c) - { } - - const Stat & previous() const noexcept { return prev; } - const Stat & current() const noexcept { return curr; } - -private: - Stat prev; - Stat curr; -}; - - -struct IdleEvent: Event { }; -struct ListenEvent: Event { }; -struct PrepareEvent: Event { }; -struct SendEvent: Event { }; -struct ShutdownEvent: Event { }; - - -struct SignalEvent: Event { - explicit SignalEvent(int sig) noexcept: signum(sig) { } - - int signal() const noexcept { return signum; } - -private: - const int signum; -}; - - -struct TimerEvent: Event { }; - - -struct UDPDataEvent: Event { - explicit UDPDataEvent(Addr addr, std::unique_ptr ptr, ssize_t l, bool trunc) noexcept - : dt{std::move(ptr)}, len{l}, sndr{addr}, part{trunc} - { } - - const char * data() const noexcept { return dt.get(); } - ssize_t length() const noexcept { return len; } - Addr sender() const noexcept { return sndr; } - bool partial() const noexcept { return part; } - -private: - std::unique_ptr dt; - const ssize_t len; - Addr sndr; - const bool part; -}; - - -struct UninitializedEvent: Event { }; -struct WorkEvent: Event { }; -struct WriteEvent: Event { }; - - } diff --git a/src/uvw/fs_poll.hpp b/src/uvw/fs_poll.hpp index c34cad9b..130f12e0 100644 --- a/src/uvw/fs_poll.hpp +++ b/src/uvw/fs_poll.hpp @@ -13,6 +13,20 @@ namespace uvw { +struct FsPollEvent: Event { + explicit FsPollEvent(const Stat &p, const Stat &c) noexcept + : prev(p), curr(c) + { } + + const Stat & previous() const noexcept { return prev; } + const Stat & current() const noexcept { return curr; } + +private: + Stat prev; + Stat curr; +}; + + class FsPoll final: public Handle { static void startCallback(uv_fs_poll_t *handle, int status, const uv_stat_t *prev, const uv_stat_t *curr) { FsPoll &fsPoll = *(static_cast(handle->data)); diff --git a/src/uvw/handle.hpp b/src/uvw/handle.hpp index 17d563c6..2e54f226 100644 --- a/src/uvw/handle.hpp +++ b/src/uvw/handle.hpp @@ -11,6 +11,9 @@ namespace uvw { +struct CloseEvent: Event { }; + + template class Handle: public BaseHandle, public Resource { diff --git a/src/uvw/idle.hpp b/src/uvw/idle.hpp index 11d60cd8..aab33281 100644 --- a/src/uvw/idle.hpp +++ b/src/uvw/idle.hpp @@ -12,6 +12,9 @@ namespace uvw { +struct IdleEvent: Event { }; + + class Idle final: public Handle { static void startCallback(uv_idle_t *handle) { Idle &idle = *(static_cast(handle->data)); diff --git a/src/uvw/poll.hpp b/src/uvw/poll.hpp index 4f7a1170..bca57df7 100644 --- a/src/uvw/poll.hpp +++ b/src/uvw/poll.hpp @@ -13,21 +13,33 @@ namespace uvw { +namespace details { + + +enum class Event: std::underlying_type_t { + READABLE = UV_READABLE, + WRITABLE = UV_WRITABLE, + DISCONNECT = UV_DISCONNECT +}; + + +} + + +using PollEvent = FlagsEvent; + + class Poll final: public Handle { static void startCallback(uv_poll_t *handle, int status, int events) { Poll &poll = *(static_cast(handle->data)); if(status) { poll.publish(ErrorEvent{status}); } - else { poll.publish(FlagsEvent{static_cast>(events)}); } + else { poll.publish(PollEvent{static_cast>(events)}); } } using Handle::Handle; public: - enum class Event: std::underlying_type_t { - READABLE = UV_READABLE, - WRITABLE = UV_WRITABLE, - DISCONNECT = UV_DISCONNECT - }; + using Event = details::Event; template static std::shared_ptr create(Args&&... args) { diff --git a/src/uvw/prepare.hpp b/src/uvw/prepare.hpp index 05509bfa..3a50fb8a 100644 --- a/src/uvw/prepare.hpp +++ b/src/uvw/prepare.hpp @@ -12,6 +12,9 @@ namespace uvw { +struct PrepareEvent: Event { }; + + class Prepare final: public Handle { static void startCallback(uv_prepare_t *handle) { Prepare &prepare = *(static_cast(handle->data)); diff --git a/src/uvw/signal.hpp b/src/uvw/signal.hpp index 787c961f..b4f736ee 100644 --- a/src/uvw/signal.hpp +++ b/src/uvw/signal.hpp @@ -12,6 +12,16 @@ namespace uvw { +struct SignalEvent: Event { + explicit SignalEvent(int sig) noexcept: signum(sig) { } + + int signal() const noexcept { return signum; } + +private: + const int signum; +}; + + class Signal final: public Handle { static void startCallback(uv_signal_t *handle, int signum) { Signal &signal = *(static_cast(handle->data)); diff --git a/src/uvw/stream.hpp b/src/uvw/stream.hpp index 149ff743..8522b710 100644 --- a/src/uvw/stream.hpp +++ b/src/uvw/stream.hpp @@ -15,6 +15,27 @@ namespace uvw { +struct ConnectEvent: Event { }; +struct EndEvent: Event { }; +struct ListenEvent: Event { }; +struct ShutdownEvent: Event { }; +struct WriteEvent: Event { }; + + +struct DataEvent: Event { + explicit DataEvent(std::unique_ptr ptr, ssize_t l) noexcept + : dt{std::move(ptr)}, len{l} + { } + + const char * data() const noexcept { return dt.get(); } + ssize_t length() const noexcept { return len; } + +private: + std::unique_ptr dt; + const ssize_t len; +}; + + namespace details { diff --git a/src/uvw/timer.hpp b/src/uvw/timer.hpp index ecb8ddd5..21b72074 100644 --- a/src/uvw/timer.hpp +++ b/src/uvw/timer.hpp @@ -13,6 +13,9 @@ namespace uvw { +struct TimerEvent: Event { }; + + class Timer final: public Handle { static void startCallback(uv_timer_t *handle) { Timer &timer = *(static_cast(handle->data)); diff --git a/src/uvw/udp.hpp b/src/uvw/udp.hpp index f8b52964..88f4cdbd 100644 --- a/src/uvw/udp.hpp +++ b/src/uvw/udp.hpp @@ -15,6 +15,27 @@ namespace uvw { +struct SendEvent: Event { }; + + +struct UDPDataEvent: Event { + explicit UDPDataEvent(Addr addr, std::unique_ptr ptr, ssize_t l, bool trunc) noexcept + : dt{std::move(ptr)}, len{l}, sndr{addr}, part{trunc} + { } + + const char * data() const noexcept { return dt.get(); } + ssize_t length() const noexcept { return len; } + Addr sender() const noexcept { return sndr; } + bool partial() const noexcept { return part; } + +private: + std::unique_ptr dt; + const ssize_t len; + Addr sndr; + const bool part; +}; + + namespace details { diff --git a/src/uvw/work.hpp b/src/uvw/work.hpp index 372377c9..93324682 100644 --- a/src/uvw/work.hpp +++ b/src/uvw/work.hpp @@ -13,6 +13,9 @@ namespace uvw { +struct WorkEvent: Event { }; + + class Work final: public Request { static void workCallback(uv_work_t *req) { static_cast(req->data)->task();