diff --git a/src/uvw/fs_poll.hpp b/src/uvw/fs_poll.hpp index 69e44678..58098d79 100644 --- a/src/uvw/fs_poll.hpp +++ b/src/uvw/fs_poll.hpp @@ -34,7 +34,7 @@ public: void start(std::string f, unsigned int interval) { file = std::move(f); - invoke(&uv_fs_poll_start, get(), &startCallback, file.c_str(), interval); + invoke(&uv_fs_poll_start, get(), &startCallback, file.data(), interval); } void stop() { invoke(&uv_fs_poll_stop, get()); } diff --git a/src/uvw/tcp.hpp b/src/uvw/tcp.hpp index 207d7e46..ac706c20 100644 --- a/src/uvw/tcp.hpp +++ b/src/uvw/tcp.hpp @@ -77,17 +77,17 @@ public: bool init() { return initialize(&uv_tcp_init); } void noDelay(bool value = false) { - invoke(&uv_tcp_nodelay, get(), value ? 1 : 0); + invoke(&uv_tcp_nodelay, get(), value); } void keepAlive(bool enable = false, Time time = Time{0}) { - invoke(&uv_tcp_keepalive, get(), enable ? 1 : 0, time.count()); + invoke(&uv_tcp_keepalive, get(), enable, time.count()); } template> void bind(std::string ip, unsigned int port, Flags flags = Flags{}) { typename Traits::Type addr; - Traits::AddrFunc(ip.c_str(), port, &addr); + Traits::AddrFunc(ip.data(), port, &addr); if(0 == invoke(&uv_tcp_bind, get(), reinterpret_cast(&addr), flags)) { addressF = &tAddress; @@ -106,7 +106,7 @@ public: template> void connect(std::string ip, unsigned int port) { typename Traits::Type addr; - Traits::AddrFunc(ip.c_str(), port, &addr); + Traits::AddrFunc(ip.data(), port, &addr); std::weak_ptr weak = this->shared_from_this(); diff --git a/src/uvw/tty.hpp b/src/uvw/tty.hpp index 66d4ed3f..a5dda816 100644 --- a/src/uvw/tty.hpp +++ b/src/uvw/tty.hpp @@ -19,11 +19,15 @@ class TTY final: public Stream { bool readable) : Stream{HandleType{}, std::move(ref)}, fd{static_cast(desc)}, - rw{readable ? 1 : 0} + rw{readable} { } public: - enum class Mode: unsigned short int { NORMAL, RAW, IO }; + enum class Mode: std::underlying_type_t { + NORMAL = UV_TTY_MODE_NORMAL, + RAW = UV_TTY_MODE_RAW, + IO = UV_TTY_MODE_IO + }; template static std::shared_ptr create(Args&&... args) { @@ -32,23 +36,11 @@ public: bool init() { return initialize(&uv_tty_init, fd, rw); } - void mode(TTY::Mode m) { - // uv_tty_set_mode is inline, cannot be used with invoke directly - auto wrap = [](auto *handle, auto m) { + void mode(Mode m) { + // uv_tty_set_mode is inline, it cannot be used with invoke directly + invoke([](auto *handle, auto m) { return uv_tty_set_mode(handle, m); - }; - - switch(m) { - case TTY::Mode::NORMAL: - invoke(std::move(wrap), get(), UV_TTY_MODE_NORMAL); - break; - case TTY::Mode::RAW: - invoke(std::move(wrap), get(), UV_TTY_MODE_RAW); - break; - case TTY::Mode::IO: - invoke(std::move(wrap), get(), UV_TTY_MODE_IO); - break; - } + }, get(), static_cast>(m)); } void reset() { invoke(&uv_tty_reset_mode); }