uvw 2.12.1
|
The StreamHandle handle. More...
#include <stream.h>
Public Member Functions | |
void | shutdown () |
Shutdowns the outgoing (write) side of a duplex stream. | |
void | listen (int backlog=DEFAULT_BACKLOG) |
Starts listening for incoming connections. | |
template<typename S > | |
void | accept (S &ref) |
Accepts incoming connections. | |
void | read () |
Starts reading data from an incoming stream. | |
void | stop () |
Stops reading data from the stream. | |
template<typename Deleter > | |
void | write (std::unique_ptr< char[], Deleter > data, unsigned int len) |
Writes data to the stream. | |
void | write (char *data, unsigned int len) |
Writes data to the stream. | |
template<typename S , typename Deleter > | |
void | write (S &send, std::unique_ptr< char[], Deleter > data, unsigned int len) |
Extended write function for sending handles over a pipe handle. | |
template<typename S > | |
void | write (S &send, char *data, unsigned int len) |
Extended write function for sending handles over a pipe handle. | |
int | tryWrite (std::unique_ptr< char[]> data, unsigned int len) |
Queues a write request if it can be completed immediately. | |
template<typename V , typename W > | |
int | tryWrite (std::unique_ptr< char[]> data, unsigned int len, StreamHandle< V, W > &send) |
Queues a write request if it can be completed immediately. | |
int | tryWrite (char *data, unsigned int len) |
Queues a write request if it can be completed immediately. | |
template<typename V , typename W > | |
int | tryWrite (char *data, unsigned int len, StreamHandle< V, W > &send) |
Queues a write request if it can be completed immediately. | |
bool | readable () const noexcept |
Checks if the stream is readable. | |
bool | writable () const noexcept |
Checks if the stream is writable. | |
bool | blocking (bool enable=false) |
Enables or disables blocking mode for a stream. | |
size_t | writeQueueSize () const noexcept |
Gets the amount of queued bytes waiting to be sent. | |
![]() | |
HandleCategory | category () const noexcept |
Gets the category of the handle. | |
HandleType | type () const noexcept |
Gets the type of the handle. | |
bool | active () const noexcept |
Checks if the handle is active. | |
bool | closing () const noexcept |
Checks if a handle is closing or closed. | |
void | close () noexcept |
Request handle to be closed. | |
void | reference () noexcept |
Reference the given handle. | |
void | unreference () noexcept |
Unreference the given handle. | |
bool | referenced () const noexcept |
Checks if the given handle referenced. | |
std::size_t | size () const noexcept |
Returns the size of the underlying handle type. | |
int | sendBufferSize () |
Gets the size of the send buffer used for the socket. | |
bool | sendBufferSize (int value) |
Sets the size of the send buffer used for the socket. | |
int | recvBufferSize () |
Gets the size of the receive buffer used for the socket. | |
bool | recvBufferSize (int value) |
Sets the size of the receive buffer used for the socket. | |
OSFileDescriptor | fd () const |
Gets the platform dependent file descriptor equivalent. | |
![]() | |
template<typename R = void> | |
std::shared_ptr< R > | data () const |
Gets user-defined data. uvw won't use this field in any case. | |
void | data (std::shared_ptr< void > uData) |
Sets arbitrary data. uvw won't use this field in any case. | |
![]() | |
Loop & | loop () const noexcept |
Gets the loop from which the resource was originated. | |
const U * | raw () const noexcept |
Gets the underlying raw data structure. | |
U * | raw () noexcept |
Gets the underlying raw data structure. | |
![]() | |
template<typename E > | |
Connection< E > | on (Listener< E > f) |
Registers a long-lived listener with the event emitter. | |
template<typename E > | |
Connection< E > | once (Listener< E > f) |
Registers a short-lived listener with the event emitter. | |
template<typename E > | |
void | erase (Connection< E > conn) noexcept |
Disconnects a listener from the event emitter. | |
template<typename E > | |
void | clear () noexcept |
Disconnects all the listeners for the given event type. | |
void | clear () noexcept |
Disconnects all the listeners. | |
template<typename E > | |
bool | empty () const noexcept |
Checks if there are listeners registered for the specific event. | |
bool | empty () const noexcept |
Checks if there are listeners registered with the event emitter. | |
Additional Inherited Members | |
![]() | |
![]() | |
template<typename... Args> | |
static std::shared_ptr< T > | create (Args &&...args) |
Creates a new resource of the given type. | |
![]() | |
![]() | |
![]() | |
![]() | |
![]() | |
![]() |
The StreamHandle handle.
Stream handles provide an abstraction of a duplex communication channel. StreamHandle is an intermediate type, uvw
provides three stream implementations: TCPHandle, PipeHandle and TTYHandle.
|
inline |
Accepts incoming connections.
This call is used in conjunction with listen()
to accept incoming connections. Call this function after receiving a ListenEvent event to accept the connection. Before calling this function, the submitted handle must be initialized.
An ErrorEvent event will be emitted in case of errors.
When the ListenEvent event is emitted it is guaranteed that this function will complete successfully the first time. If you attempt to use it more than once, it may fail.
It is suggested to only call this function once per ListenEvent event.
ref | An initialized handle to be used to accept the connection. |
|
inline |
Enables or disables blocking mode for a stream.
When blocking mode is enabled all writes complete synchronously. The interface remains unchanged otherwise, e.g. completion or failure of the operation will still be reported through events which are emitted asynchronously.
See the official documentation for further details.
enable | True to enable blocking mode, false otherwise. |
|
inline |
Starts listening for incoming connections.
When a new incoming connection is received, a ListenEvent event is emitted.
An ErrorEvent event will be emitted in case of errors.
backlog | Indicates the number of connections the kernel might queue, same as listen(2). |
|
inline |
|
inlinenoexcept |
|
inline |
Shutdowns the outgoing (write) side of a duplex stream.
It waits for pending write requests to complete. The handle should refer to a initialized stream.
A ShutdownEvent event will be emitted after shutdown is complete.
|
inline |
|
inline |
Queues a write request if it can be completed immediately.
Same as write()
, but won’t queue a write request if it can’t be completed immediately.
An ErrorEvent event will be emitted in case of errors.
data | The data to be written to the stream. |
len | The lenght of the submitted data. |
|
inline |
Queues a write request if it can be completed immediately.
Same as tryWrite
for sending handles over a pipe.
An ErrorEvent event will be emitted in case of errors.
data | The data to be written to the stream. |
len | The lenght of the submitted data. |
send | A valid handle suitable for the purpose. |
|
inline |
Queues a write request if it can be completed immediately.
Same as write()
, but won’t queue a write request if it can’t be completed immediately.
An ErrorEvent event will be emitted in case of errors.
data | The data to be written to the stream. |
len | The lenght of the submitted data. |
|
inline |
Queues a write request if it can be completed immediately.
Same as tryWrite
for sending handles over a pipe.
An ErrorEvent event will be emitted in case of errors.
data | The data to be written to the stream. |
len | The lenght of the submitted data. |
send | A valid handle suitable for the purpose. |
|
inlinenoexcept |
|
inline |
Writes data to the stream.
Data are written in order. The handle doesn't take the ownership of the data. Be sure that their lifetime overcome the one of the request.
A WriteEvent event will be emitted when the data have been written.
An ErrorEvent event will be emitted in case of errors.
data | The data to be written to the stream. |
len | The lenght of the submitted data. |
|
inline |
Extended write function for sending handles over a pipe handle.
The pipe must be initialized with ipc == true
.
send
must be a TCPHandle or PipeHandle handle, which is a server or a connection (listening or connected state). Bound sockets or pipes will be assumed to be servers.
The handle doesn't take the ownership of the data. Be sure that their lifetime overcome the one of the request.
A WriteEvent event will be emitted when the data have been written.
An ErrorEvent wvent will be emitted in case of errors.
send | The handle over which to write data. |
data | The data to be written to the stream. |
len | The lenght of the submitted data. |
|
inline |
Extended write function for sending handles over a pipe handle.
The pipe must be initialized with ipc == true
.
send
must be a TCPHandle or PipeHandle handle, which is a server or a connection (listening or connected state). Bound sockets or pipes will be assumed to be servers.
The handle takes the ownership of the data and it is in charge of delete them.
A WriteEvent event will be emitted when the data have been written.
An ErrorEvent wvent will be emitted in case of errors.
send | The handle over which to write data. |
data | The data to be written to the stream. |
len | The lenght of the submitted data. |
|
inline |
Writes data to the stream.
Data are written in order. The handle takes the ownership of the data and it is in charge of delete them.
A WriteEvent event will be emitted when the data have been written.
An ErrorEvent event will be emitted in case of errors.
data | The data to be written to the stream. |
len | The lenght of the submitted data. |
|
inlinenoexcept |