diff --git a/src/uvw/async.h b/src/uvw/async.h index 84dcdeef..7d864ba4 100644 --- a/src/uvw/async.h +++ b/src/uvw/async.h @@ -30,7 +30,7 @@ public: * Unlike other handle initialization functions, it immediately starts the * handle. * - * @return Underlying code in case of errors, 0 otherwise. + * @return Underlying return value. */ int init() final; diff --git a/src/uvw/check.h b/src/uvw/check.h index 63a23cf5..09b0401c 100644 --- a/src/uvw/check.h +++ b/src/uvw/check.h @@ -26,7 +26,7 @@ public: /** * @brief Initializes the handle. - * @return Underlying code in case of errors, 0 otherwise. + * @return Underlying return value. */ int init() final; diff --git a/src/uvw/fs_event.h b/src/uvw/fs_event.h index e68714f9..6146d232 100644 --- a/src/uvw/fs_event.h +++ b/src/uvw/fs_event.h @@ -75,7 +75,7 @@ public: /** * @brief Initializes the handle. - * @return Underlying code in case of errors, 0 otherwise. + * @return Underlying return value. */ int init() final; diff --git a/src/uvw/fs_poll.h b/src/uvw/fs_poll.h index e86b6f2c..7536be16 100644 --- a/src/uvw/fs_poll.h +++ b/src/uvw/fs_poll.h @@ -38,7 +38,7 @@ public: /** * @brief Initializes the handle. - * @return Underlying code in case of errors, 0 otherwise. + * @return Underlying return value. */ int init() final; diff --git a/src/uvw/idle.cpp b/src/uvw/idle.cpp index 4456468a..03a0025b 100644 --- a/src/uvw/idle.cpp +++ b/src/uvw/idle.cpp @@ -15,16 +15,12 @@ UVW_INLINE int idle_handle::init() { return leak_if(uv_idle_init(parent().raw(), raw())); } -UVW_INLINE void idle_handle::start() { - if(auto err = uv_idle_start(raw(), &start_callback); err != 0) { - publish(error_event{err}); - } +UVW_INLINE int idle_handle::start() { + return uv_idle_start(raw(), &start_callback); } -UVW_INLINE void idle_handle::stop() { - if(auto err = uv_idle_stop(raw()); err != 0) { - publish(error_event{err}); - } +UVW_INLINE int idle_handle::stop() { + return uv_idle_stop(raw()); } } // namespace uvw diff --git a/src/uvw/idle.h b/src/uvw/idle.h index 2525b902..ff36ca18 100644 --- a/src/uvw/idle.h +++ b/src/uvw/idle.h @@ -34,7 +34,7 @@ public: /** * @brief Initializes the handle. - * @return Underlying code in case of errors, 0 otherwise. + * @return Underlying return value. */ int init() final; @@ -43,13 +43,17 @@ public: * * An idle event will be emitted once per loop iteration, right before * polling the prepare handles. + * + * @return Underlying return value. */ - void start(); + int start(); /** * @brief Stops the handle. + * + * @return Underlying return value. */ - void stop(); + int stop(); }; } // namespace uvw diff --git a/src/uvw/loop.cpp b/src/uvw/loop.cpp index 0e8e79c5..442594e9 100644 --- a/src/uvw/loop.cpp +++ b/src/uvw/loop.cpp @@ -63,8 +63,8 @@ UVW_INLINE int loop::close() { return ret; } -bool loop::run(run_mode mode) UVW_NOEXCEPT { - return (uv_run(uv_loop.get(), static_cast(mode)) == 0); +int loop::run(run_mode mode) UVW_NOEXCEPT { + return uv_run(uv_loop.get(), static_cast(mode)); } UVW_INLINE bool loop::alive() const UVW_NOEXCEPT { @@ -96,10 +96,8 @@ UVW_INLINE void loop::update() const UVW_NOEXCEPT { return uv_update_time(uv_loop.get()); } -UVW_INLINE void loop::fork() UVW_NOEXCEPT { - if(auto err = uv_loop_fork(uv_loop.get()); err) { - publish(error_event{err}); - } +UVW_INLINE int loop::fork() UVW_NOEXCEPT { + return uv_loop_fork(uv_loop.get()); } UVW_INLINE void loop::data(std::shared_ptr ud) { diff --git a/src/uvw/loop.h b/src/uvw/loop.h index 7305ffc4..a0452007 100644 --- a/src/uvw/loop.h +++ b/src/uvw/loop.h @@ -132,12 +132,12 @@ public: * See the official * [documentation](http://docs.libuv.org/en/v1.x/loop.html#c.uv_loop_configure) * for further details. + * + * @return Underlying return value. */ template - void configure(option flag, Args &&...args) { - if(auto err = uv_loop_configure(uv_loop.get(), static_cast(flag), std::forward(args)...); err) { - publish(error_event{err}); - } + int configure(option flag, Args &&...args) { + return uv_loop_configure(uv_loop.get(), static_cast(flag), std::forward(args)...); } /** @@ -172,7 +172,7 @@ public: * 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. * - * @return Underlying code in case of errors, 0 otherwise. + * @return Underlying return value. */ int close(); @@ -192,9 +192,9 @@ public: * [documentation](http://docs.libuv.org/en/v1.x/loop.html#c.uv_run) * for further details. * - * @return True when done, false in all other cases. + * @return Underlying return value. */ - bool run(run_mode mode = run_mode::DEFAULT) UVW_NOEXCEPT; + int run(run_mode mode = run_mode::DEFAULT) UVW_NOEXCEPT; /** * @brief Checks if there are active resources. @@ -358,8 +358,10 @@ public: * See the official * [documentation](http://docs.libuv.org/en/v1.x/loop.html#c.uv_loop_fork) * for further details. + * + * @return Underlying return value. */ - void fork() UVW_NOEXCEPT; + int fork() UVW_NOEXCEPT; /** * @brief Gets user-defined data. `uvw` won't use this field in any case. diff --git a/src/uvw/pipe.h b/src/uvw/pipe.h index f38e557a..f7505374 100644 --- a/src/uvw/pipe.h +++ b/src/uvw/pipe.h @@ -43,7 +43,7 @@ public: /** * @brief Initializes the handle. - * @return Underlying code in case of errors, 0 otherwise. + * @return Underlying return value. */ int init() final; diff --git a/src/uvw/poll.h b/src/uvw/poll.h index 667fdc9d..0f37fa26 100644 --- a/src/uvw/poll.h +++ b/src/uvw/poll.h @@ -67,7 +67,7 @@ public: /** * @brief Initializes the handle. - * @return Underlying code in case of errors, 0 otherwise. + * @return Underlying return value. */ int init() final; diff --git a/src/uvw/prepare.cpp b/src/uvw/prepare.cpp index 93bae205..dee7186e 100644 --- a/src/uvw/prepare.cpp +++ b/src/uvw/prepare.cpp @@ -15,16 +15,12 @@ UVW_INLINE int prepare_handle::init() { return leak_if(uv_prepare_init(parent().raw(), raw())); } -UVW_INLINE void prepare_handle::start() { - if(auto err = uv_prepare_start(raw(), &start_callback); err != 0) { - publish(error_event{err}); - } +UVW_INLINE int prepare_handle::start() { + return uv_prepare_start(raw(), &start_callback); } -UVW_INLINE void prepare_handle::stop() { - if(auto err = uv_prepare_stop(raw()); err != 0) { - publish(error_event{err}); - } +UVW_INLINE int prepare_handle::stop() { + return uv_prepare_stop(raw()); } } // namespace uvw diff --git a/src/uvw/prepare.h b/src/uvw/prepare.h index 06d0d813..891e1bc8 100644 --- a/src/uvw/prepare.h +++ b/src/uvw/prepare.h @@ -26,7 +26,7 @@ public: /** * @brief Initializes the handle. - * @return Underlying code in case of errors, 0 otherwise. + * @return Underlying return value. */ int init() final; @@ -37,13 +37,16 @@ public: * polling for I/O. * * The handle will start emitting prepare events when needed. + * + * @return Underlying return value. */ - void start(); + int start(); /** * @brief Stops the handle. + * @return Underlying return value. */ - void stop(); + int stop(); }; } // namespace uvw diff --git a/src/uvw/process.h b/src/uvw/process.h index 472da40c..1320b46b 100644 --- a/src/uvw/process.h +++ b/src/uvw/process.h @@ -90,7 +90,7 @@ public: /** * @brief Initializes the handle. - * @return Underlying code in case of errors, 0 otherwise. + * @return Underlying return value. */ int init() final; diff --git a/src/uvw/signal.h b/src/uvw/signal.h index 0a0bedb1..ec20a43a 100644 --- a/src/uvw/signal.h +++ b/src/uvw/signal.h @@ -36,7 +36,7 @@ public: /** * @brief Initializes the handle. - * @return Underlying code in case of errors, 0 otherwise. + * @return Underlying return value. */ int init() final; diff --git a/src/uvw/tcp.h b/src/uvw/tcp.h index da4466b3..694019a3 100644 --- a/src/uvw/tcp.h +++ b/src/uvw/tcp.h @@ -51,7 +51,7 @@ public: /** * @brief Initializes the handle. No socket is created as of yet. - * @return Underlying code in case of errors, 0 otherwise. + * @return Underlying return value. */ int init() final; diff --git a/src/uvw/timer.cpp b/src/uvw/timer.cpp index 1de0b02c..6db6dec6 100644 --- a/src/uvw/timer.cpp +++ b/src/uvw/timer.cpp @@ -15,22 +15,16 @@ UVW_INLINE int timer_handle::init() { return leak_if(uv_timer_init(parent().raw(), raw())); } -UVW_INLINE void timer_handle::start(timer_handle::time timeout, timer_handle::time repeat) { - if(auto err = uv_timer_start(raw(), &start_callback, timeout.count(), repeat.count()); err != 0) { - publish(error_event{err}); - } +UVW_INLINE int timer_handle::start(timer_handle::time timeout, timer_handle::time repeat) { + return uv_timer_start(raw(), &start_callback, timeout.count(), repeat.count()); } -UVW_INLINE void timer_handle::stop() { - if(auto err = uv_timer_stop(raw()); err != 0) { - publish(error_event{err}); - } +UVW_INLINE int timer_handle::stop() { + return uv_timer_stop(raw()); } -UVW_INLINE void timer_handle::again() { - if(auto err = uv_timer_again(raw()); err != 0) { - publish(error_event{err}); - } +UVW_INLINE int timer_handle::again() { + return uv_timer_again(raw()); } UVW_INLINE void timer_handle::repeat(timer_handle::time repeat) { diff --git a/src/uvw/timer.h b/src/uvw/timer.h index d120da6b..a7aef680 100644 --- a/src/uvw/timer.h +++ b/src/uvw/timer.h @@ -29,7 +29,7 @@ public: /** * @brief Initializes the handle. - * @return Underlying code in case of errors, 0 otherwise. + * @return Underlying return value. */ int init() final; @@ -44,13 +44,16 @@ public: * `std::chrono::duration`). * @param repeat Milliseconds between successive events (use * `std::chrono::duration`). + * + * @return Underlying return value. */ - void start(time timeout, time repeat); + int start(time timeout, time repeat); /** * @brief Stops the handle. + * @return Underlying return value. */ - void stop(); + int stop(); /** * @brief Stops the timer and restarts it if it was repeating. @@ -58,8 +61,10 @@ public: * Stop the timer, and if it is repeating restart it using the repeat value * as the timeout.
* If the timer has never been started before it emits an error event. + * + * @return Underlying return value. */ - void again(); + int again(); /** * @brief Sets the repeat interval value. diff --git a/src/uvw/tty.h b/src/uvw/tty.h index e07d1a5e..e7b10ebf 100644 --- a/src/uvw/tty.h +++ b/src/uvw/tty.h @@ -58,7 +58,7 @@ public: /** * @brief Initializes the handle. - * @return Underlying code in case of errors, 0 otherwise. + * @return Underlying return value. */ int init() final; diff --git a/src/uvw/udp.h b/src/uvw/udp.h index 7377c579..57243a19 100644 --- a/src/uvw/udp.h +++ b/src/uvw/udp.h @@ -92,7 +92,7 @@ public: /** * @brief Initializes the handle. The actual socket is created lazily. - * @return Underlying code in case of errors, 0 otherwise. + * @return Underlying return value. */ int init() final; diff --git a/src/uvw/uv_type.hpp b/src/uvw/uv_type.hpp index 94dae083..64d65e2c 100644 --- a/src/uvw/uv_type.hpp +++ b/src/uvw/uv_type.hpp @@ -27,7 +27,7 @@ struct uv_type { /** * @brief Initializes the handle. - * @return Underlying code in case of errors, 0 otherwise. + * @return Underlying return value. */ virtual int init() { return 0; diff --git a/src/uvw/work.cpp b/src/uvw/work.cpp index 2a27f467..f6fc68d0 100644 --- a/src/uvw/work.cpp +++ b/src/uvw/work.cpp @@ -23,10 +23,8 @@ UVW_INLINE void work_req::after_work_callback(uv_work_t* req, int status) { } } -UVW_INLINE void work_req::queue() { - if(auto err = this->leak_if(uv_queue_work(parent().raw(), raw(), &work_callback, &after_work_callback)); err != 0) { - publish(error_event{err}); - } +UVW_INLINE int work_req::queue() { + return this->leak_if(uv_queue_work(parent().raw(), raw(), &work_callback, &after_work_callback)); } } // namespace uvw diff --git a/src/uvw/work.h b/src/uvw/work.h index 3c100ca9..d6a4c1e2 100644 --- a/src/uvw/work.h +++ b/src/uvw/work.h @@ -41,8 +41,10 @@ public: * A work event will be emitted on the loop thread when the task is * finished.
* This request can be cancelled with `cancel()`. + * + * @return Underlying return value. */ - void queue(); + int queue(); private: task func{}; diff --git a/test/uvw/idle.cpp b/test/uvw/idle.cpp index bd600dc3..5d51cc60 100644 --- a/test/uvw/idle.cpp +++ b/test/uvw/idle.cpp @@ -11,14 +11,17 @@ TEST(Idle, StartAndStop) { handle->on([&checkIdleEvent](const auto &, auto &hndl) { ASSERT_FALSE(checkIdleEvent); + checkIdleEvent = true; - hndl.stop(); + + ASSERT_EQ(0, hndl.stop()); + hndl.close(); + ASSERT_TRUE(hndl.closing()); }); - handle->start(); - + ASSERT_EQ(0, handle->start()); ASSERT_TRUE(handle->active()); ASSERT_FALSE(handle->closing()); diff --git a/test/uvw/loop.cpp b/test/uvw/loop.cpp index 97d80859..a0b273be 100644 --- a/test/uvw/loop.cpp +++ b/test/uvw/loop.cpp @@ -32,7 +32,7 @@ TEST(Loop, Functionalities) { #ifndef _MSC_VER // fork isn't implemented on Windows in libuv and it returns an error by default - ASSERT_NO_THROW(loop->fork()); + ASSERT_EQ(0, loop->fork()); #endif ASSERT_FALSE(loop->alive()); @@ -50,12 +50,12 @@ TEST(Loop, Functionalities) { }); ASSERT_TRUE(loop->alive()); - ASSERT_NO_THROW(loop->run()); + ASSERT_EQ(0, loop->run()); loop->walk([](auto &) { FAIL(); }); - ASSERT_NO_THROW(loop->run(uvw::loop::run_mode::ONCE)); - ASSERT_NO_THROW(loop->run(uvw::loop::run_mode::NOWAIT)); + ASSERT_EQ(0, loop->run(uvw::loop::run_mode::ONCE)); + ASSERT_EQ(0, loop->run(uvw::loop::run_mode::NOWAIT)); ASSERT_FALSE(loop->alive()); } @@ -106,8 +106,8 @@ TEST(Loop, UserData) { TEST(Loop, Configure) { auto loop = uvw::loop::create(); - ASSERT_NO_THROW(loop->configure(uvw::loop::option::BLOCK_SIGNAL, 9)); - ASSERT_NO_THROW(loop->run()); + ASSERT_EQ(0, loop->configure(uvw::loop::option::IDLE_TIME)); + ASSERT_EQ(0, loop->run()); } TEST(Loop, IdleTime) { diff --git a/test/uvw/prepare.cpp b/test/uvw/prepare.cpp index 97f556e7..b66920bd 100644 --- a/test/uvw/prepare.cpp +++ b/test/uvw/prepare.cpp @@ -11,14 +11,17 @@ TEST(Prepare, StartAndStop) { handle->on([&checkPrepareEvent](const auto &, auto &hndl) { ASSERT_FALSE(checkPrepareEvent); + checkPrepareEvent = true; - hndl.stop(); + + ASSERT_EQ(0, hndl.stop()); + hndl.close(); + ASSERT_TRUE(hndl.closing()); }); - handle->start(); - + ASSERT_EQ(0, handle->start()); ASSERT_TRUE(handle->active()); ASSERT_FALSE(handle->closing()); diff --git a/test/uvw/timer.cpp b/test/uvw/timer.cpp index fc30245e..0ab1c4ff 100644 --- a/test/uvw/timer.cpp +++ b/test/uvw/timer.cpp @@ -14,16 +14,22 @@ TEST(Timer, StartAndStop) { handleNoRepeat->on([&checkTimerNoRepeatEvent](const auto &, auto &handle) { ASSERT_FALSE(checkTimerNoRepeatEvent); + checkTimerNoRepeatEvent = true; - handle.stop(); + + ASSERT_EQ(0, handle.stop()); + handle.close(); + ASSERT_TRUE(handle.closing()); }); handleRepeat->on([&checkTimerRepeatEvent](const auto &, auto &handle) { if(checkTimerRepeatEvent) { - handle.stop(); + ASSERT_EQ(0, handle.stop()); + handle.close(); + ASSERT_TRUE(handle.closing()); } else { checkTimerRepeatEvent = true; @@ -31,8 +37,8 @@ TEST(Timer, StartAndStop) { } }); - handleNoRepeat->start(uvw::timer_handle::time{0}, uvw::timer_handle::time{0}); - handleRepeat->start(uvw::timer_handle::time{0}, uvw::timer_handle::time{1}); + ASSERT_EQ(0, handleNoRepeat->start(uvw::timer_handle::time{0}, uvw::timer_handle::time{0})); + ASSERT_EQ(0, handleRepeat->start(uvw::timer_handle::time{0}, uvw::timer_handle::time{1})); ASSERT_TRUE(handleNoRepeat->active()); ASSERT_FALSE(handleNoRepeat->closing()); @@ -50,13 +56,9 @@ TEST(Timer, Again) { auto loop = uvw::loop::get_default(); auto handle = loop->resource(); - bool checkErrorEvent = false; bool checkTimerEvent = false; - handle->on([&checkErrorEvent](const auto &, auto &) { - ASSERT_FALSE(checkErrorEvent); - checkErrorEvent = true; - }); + handle->on([](const auto &, auto &) { FAIL(); }); handle->on([&checkTimerEvent](const auto &, auto &hndl) { static bool guard = false; @@ -68,17 +70,15 @@ TEST(Timer, Again) { ASSERT_TRUE(hndl.closing()); } else { guard = true; - hndl.again(); + ASSERT_EQ(0, hndl.again()); ASSERT_EQ(hndl.repeat(), uvw::timer_handle::time{1}); ASSERT_FALSE(hndl.closing()); } }); - ASSERT_NO_THROW(handle->again()); + ASSERT_NE(0, handle->again()); ASSERT_FALSE(handle->active()); - ASSERT_TRUE(checkErrorEvent); - checkErrorEvent = false; handle->start(uvw::timer_handle::time{0}, uvw::timer_handle::time{1}); ASSERT_TRUE(handle->active()); @@ -86,7 +86,6 @@ TEST(Timer, Again) { loop->run(); - ASSERT_FALSE(checkErrorEvent); ASSERT_TRUE(checkTimerEvent); handle->close(); @@ -94,9 +93,7 @@ TEST(Timer, Again) { ASSERT_FALSE(handle->active()); ASSERT_TRUE(handle->closing()); - handle->start(uvw::timer_handle::time{0}, uvw::timer_handle::time{1}); - - ASSERT_TRUE(checkErrorEvent); + ASSERT_NE(0, handle->start(uvw::timer_handle::time{0}, uvw::timer_handle::time{1})); } TEST(Timer, Repeat) { diff --git a/test/uvw/work.cpp b/test/uvw/work.cpp index 1246c06d..1d2241b7 100644 --- a/test/uvw/work.cpp +++ b/test/uvw/work.cpp @@ -21,7 +21,9 @@ TEST(Work, RunTask) { }); handle->start(); - req->queue(); + + ASSERT_EQ(0, req->queue()); + loop->run(); ASSERT_TRUE(checkTask);