diff --git a/src/uvw/stream.hpp b/src/uvw/stream.hpp index 4b480fba..d80e43cb 100644 --- a/src/uvw/stream.hpp +++ b/src/uvw/stream.hpp @@ -67,6 +67,10 @@ public: void write(uv_stream_t *handle, const uv_buf_t bufs[], unsigned int nbufs) { exec(&uv_write, get(), handle, bufs, nbufs); } + + void write(uv_stream_t *handle, const uv_buf_t bufs[], unsigned int nbufs, uv_stream_t *send) { + exec(&uv_write2, get(), handle, bufs, nbufs, send); + } }; @@ -127,7 +131,7 @@ public: } template - void accept(U &ref) { + void accept(Stream &ref) { this->invoke(&uv_accept, this->template get(), ref.template get()); } @@ -156,7 +160,24 @@ public: write(data.get(), len); } - // TODO uv_write2 + template + void write(Stream &send, char *data, ssize_t len) { + uv_buf_t bufs[] = { uv_buf_init(data, len) }; + + auto listener = [ptr = this->shared_from_this()](const auto &event, details::Write &) { + ptr->publish(event); + }; + + auto write = this->loop().template resource(); + write->template once(listener); + write->template once(listener); + write->write(this->template get(), bufs, 1, send.template get()); + } + + template + void write(Stream &send, std::unique_ptr data, ssize_t len) { + write(send, data.get(), len); + } int tryWrite(char *data, ssize_t len) { uv_buf_t bufs[] = { uv_buf_init(data, len) }; @@ -182,7 +203,9 @@ public: return (uv_is_writable(this->template get()) == 1); } - // TODO uv_stream_set_blocking + void blocking(bool enable = false) { + this->invoke(&uv_stream_set_blocking, this->template get(), enable); + } };