5#ifndef WPINET_UV_STREAM_H_
6#define WPINET_UV_STREAM_H_
12#include <initializer_list>
71 return std::static_pointer_cast<Stream>(Handle::shared_from_this());
75 return std::static_pointer_cast<const Stream>(Handle::shared_from_this());
85 void Shutdown(
const std::shared_ptr<ShutdownReq>& req);
95 void Shutdown(std::function<
void()> callback =
nullptr);
131 void Write(std::span<const Buffer> bufs,
132 const std::shared_ptr<WriteReq>& req);
150 void Write(std::initializer_list<Buffer> bufs,
151 const std::shared_ptr<WriteReq>& req) {
152 Write({bufs.begin(), bufs.end()}, req);
168 void Write(std::span<const Buffer> bufs,
169 std::function<
void(std::span<Buffer>,
Error)> callback);
184 void Write(std::initializer_list<Buffer> bufs,
185 std::function<
void(std::span<Buffer>,
Error)> callback) {
186 Write({bufs.begin(), bufs.end()}, std::move(callback));
212 return TryWrite({bufs.begin(), bufs.end()});
240 return TryWrite2({bufs.begin(), bufs.end()}, send);
306template <
typename T,
typename U>
310 return std::static_pointer_cast<T>(Handle::shared_from_this());
314 return std::static_pointer_cast<const T>(Handle::shared_from_this());
SignalBase is an implementation of the observer pattern, through the use of an emitting object and sl...
Definition: Signal.h:495
Error code.
Definition: Error.h:15
Handle.
Definition: Handle.h:30
uv_handle_t * GetRawHandle() const noexcept
Get the underlying handle data structure.
Definition: Handle.h:176
bool Invoke(F &&f, Args &&... args) const
Definition: Handle.h:251
Request.
Definition: Request.h:130
uv_shutdown_t * GetRaw() noexcept
Get the underlying request data structure.
Definition: Request.h:145
Shutdown request.
Definition: Stream.h:30
sig::Signal complete
Shutdown completed signal.
Definition: Stream.h:41
Stream & GetStream() const
Definition: Stream.h:34
Stream handle.
Definition: Stream.h:68
std::shared_ptr< Stream > shared_from_this()
Definition: Stream.h:70
void Write(std::span< const Buffer > bufs, std::function< void(std::span< Buffer >, Error)> callback)
Write data to the stream.
sig::Signal end
Signal generated when no more read data is available.
Definition: Stream.h:299
bool IsReadable() const noexcept
Check if the stream is readable.
Definition: Stream.h:247
void StopRead()
Stop reading data from the stream.
Definition: Stream.h:113
void Write(std::span< const Buffer > bufs, const std::shared_ptr< WriteReq > &req)
Write data to the stream.
void Shutdown(std::function< void()> callback=nullptr)
Shutdown the outgoing (write) side of a duplex stream.
bool SetBlocking(bool enable) noexcept
Enable or disable blocking mode for a stream.
Definition: Stream.h:270
Stream(uv_stream_t *uv_stream)
Definition: Stream.h:302
void Write(std::initializer_list< Buffer > bufs, const std::shared_ptr< WriteReq > &req)
Write data to the stream.
Definition: Stream.h:150
int TryWrite(std::initializer_list< Buffer > bufs)
Queue a write request if it can be completed immediately.
Definition: Stream.h:211
size_t GetWriteQueueSize() const noexcept
Gets the amount of queued bytes waiting to be sent.
Definition: Stream.h:278
int TryWrite2(std::initializer_list< Buffer > bufs, Stream &send)
Same as TryWrite() and extended write function for sending handles over a pipe.
Definition: Stream.h:239
void StartRead()
Start reading data from an incoming stream.
int TryWrite2(std::span< const Buffer > bufs, Stream &send)
Same as TryWrite() and extended write function for sending handles over a pipe.
int TryWrite(std::span< const Buffer > bufs)
Queue a write request if it can be completed immediately.
void Write(std::initializer_list< Buffer > bufs, std::function< void(std::span< Buffer >, Error)> callback)
Write data to the stream.
Definition: Stream.h:184
bool IsWritable() const noexcept
Checks if the stream is writable.
Definition: Stream.h:255
uv_stream_t * GetRawStream() const noexcept
Get the underlying stream data structure.
Definition: Stream.h:287
std::shared_ptr< const Stream > shared_from_this() const
Definition: Stream.h:74
void Shutdown(const std::shared_ptr< ShutdownReq > &req)
Shutdown the outgoing (write) side of a duplex stream.
sig::Signal< Buffer &, size_t > data
Signal generated when data was read on a stream.
Definition: Stream.h:294
std::shared_ptr< const T > shared_from_this() const
Definition: Stream.h:313
std::shared_ptr< T > shared_from_this()
Definition: Stream.h:309
StreamImpl()
Definition: Stream.h:327
U * GetRaw() const noexcept
Get the underlying handle data structure.
Definition: Stream.h:322
Write request.
Definition: Stream.h:47
Stream & GetStream() const
Definition: Stream.h:51
sig::Signal< Error > finish
Write completed signal.
Definition: Stream.h:59
Definition: StdDeque.h:50
Definition: ParallelTcpConnector.h:22
UV_REQ_FIELDS uv_stream_t * handle
Definition: uv.h:419
uv_stream_t * handle
Definition: uv.h:536
UV_EXTERN int uv_read_stop(uv_stream_t *)
UV_EXTERN int uv_stream_set_blocking(uv_stream_t *handle, int blocking)
UV_EXTERN int uv_is_writable(const uv_stream_t *handle)
UV_EXTERN int uv_is_readable(const uv_stream_t *handle)