diff --git a/src/uvw.hpp b/src/uvw.hpp index 8696fdfc..83d9c71b 100644 --- a/src/uvw.hpp +++ b/src/uvw.hpp @@ -4,6 +4,7 @@ #include "uvw/fs_poll.hpp" #include "uvw/idle.hpp" #include "uvw/loop.hpp" +#include "uvw/pipe.hpp" #include "uvw/poll.hpp" #include "uvw/prepare.hpp" #include "uvw/signal.hpp" diff --git a/src/uvw/pipe.hpp b/src/uvw/pipe.hpp index 4422a240..1413ff6e 100644 --- a/src/uvw/pipe.hpp +++ b/src/uvw/pipe.hpp @@ -26,18 +26,15 @@ public: return std::shared_ptr{new Pipe{std::forward(args)...}}; } - bool init(bool ipc = false) { return initialize(&uv_ipc_init, ipc); } + bool init(bool ipc = false) { return initialize(&uv_pipe_init, ipc); } void bind(std::string name) { invoke(&uv_pipe_bind, get(), name.data()); } void connect(std::string name) { - std::weak_ptr weak = this->shared_from_this(); - - auto listener = [weak](const auto &event, details::Connect &) { - auto ptr = weak.lock(); - if(ptr) { ptr->publish(event); } + auto listener = [ptr = this->shared_from_this()](const auto &event, details::Connect &) { + ptr->publish(event); }; auto connect = loop().resource(); @@ -49,8 +46,9 @@ public: std::string sock() const noexcept { return details::path(&uv_pipe_getsockname, get()); } std::string peer() const noexcept { return details::path(&uv_pipe_getpeername, get()); } - // TODO uv_pipe_pending_instances - // TODO uv_pipe_pending_count + void pending(int count) noexcept { uv_pipe_pending_instances(get(), count); } + int pending() noexcept { return uv_pipe_pending_count(get()); } + // TODO uv_pipe_pending_type }; diff --git a/src/uvw/request.hpp b/src/uvw/request.hpp index 5c6a3cd5..4686b3e4 100644 --- a/src/uvw/request.hpp +++ b/src/uvw/request.hpp @@ -1,6 +1,7 @@ #pragma once +#include #include #include #include @@ -41,13 +42,21 @@ class Request: public Resource { protected: using Resource::Resource; - template - auto exec(A&&... args) { - auto ret = this->invoke(std::forward(args)..., &execCallback); + template + auto exec(F &&f, A&&... args) + -> std::enable_if_t))>>::value, int> { + auto ret = this->invoke(std::forward(f), std::forward(args)..., &execCallback); if(0 == ret) { this->leak(); } return ret; } + template + auto exec(F &&f, A&&... args) + -> std::enable_if_t))>>::value> { + std::forward(f)(std::forward(args)..., &execCallback); + this->leak(); + } + public: void cancel() { this->invoke(&uv_cancel, this->template get()); diff --git a/src/uvw/stream.hpp b/src/uvw/stream.hpp index 48825fb1..191f7f67 100644 --- a/src/uvw/stream.hpp +++ b/src/uvw/stream.hpp @@ -108,11 +108,8 @@ protected: public: void shutdown() { - std::weak_ptr weak = this->shared_from_this(); - - auto listener = [weak](const auto &event, details::Shutdown &) { - auto ptr = weak.lock(); - if(ptr) { ptr->publish(event); } + auto listener = [ptr = this->shared_from_this()](const auto &event, details::Shutdown &) { + ptr->publish(event); }; auto shutdown = this->loop().template resource(); @@ -141,11 +138,9 @@ public: void write(char *data, ssize_t len) { uv_buf_t bufs[] = { uv_buf_init(data, len) }; - std::weak_ptr weak = this->shared_from_this(); - auto listener = [weak](const auto &event, details::Write &) { - auto ptr = weak.lock(); - if(ptr) { ptr->publish(event); } + auto listener = [ptr = this->shared_from_this()](const auto &event, details::Write &) { + ptr->publish(event); }; auto write = this->loop().template resource(); diff --git a/src/uvw/tcp.hpp b/src/uvw/tcp.hpp index f68d6853..7b3c985e 100644 --- a/src/uvw/tcp.hpp +++ b/src/uvw/tcp.hpp @@ -85,16 +85,10 @@ public: typename Traits::Type addr; Traits::AddrFunc(ip.data(), port, &addr); - std::weak_ptr weak = this->shared_from_this(); - - auto listener = [weak](const auto &event, details::Connect &) { - auto ptr = weak.lock(); - - if(ptr) { - ptr->sockF = &tSock; - ptr->peerF = &tPeer; - ptr->publish(event); - } + auto listener = [ptr = this->shared_from_this()](const auto &event, details::Connect &) { + ptr->sockF = &tSock; + ptr->peerF = &tPeer; + ptr->publish(event); }; auto connect = loop().resource(); diff --git a/src/uvw/udp.hpp b/src/uvw/udp.hpp index aa6270b2..b9469c31 100644 --- a/src/uvw/udp.hpp +++ b/src/uvw/udp.hpp @@ -151,16 +151,11 @@ public: Traits::AddrFunc(ip.data(), port, &addr); uv_buf_t bufs[] = { uv_buf_init(data, len) }; - std::weak_ptr weak = this->shared_from_this(); - auto listener = [weak](const auto &event, details::Send &) { - auto ptr = weak.lock(); - - if(ptr) { - ptr->sockF = &tSock; - ptr->peerF = &tPeer; - ptr->publish(event); - } + auto listener = [ptr = this->shared_from_this()](const auto &event, details::Send &) { + ptr->sockF = &tSock; + ptr->peerF = &tPeer; + ptr->publish(event); }; auto send = this->loop().resource();