uvw 3.1.0
Loading...
Searching...
No Matches
Public Member Functions | List of all members
uvw::stream_handle< T, U, E > Class Template Reference

The stream handle. More...

#include <stream.h>

Inheritance diagram for uvw::stream_handle< T, U, E >:
Inheritance graph
[legend]
Collaboration diagram for uvw::stream_handle< T, U, E >:
Collaboration graph
[legend]

Public Member Functions

int shutdown ()
 Shutdowns the outgoing (write) side of a duplex stream.
 
int listen (int backlog=DEFAULT_BACKLOG)
 Starts listening for incoming connections.
 
template<typename S >
int accept (S &ref)
 Accepts incoming connections.
 
int read ()
 Starts reading data from an incoming stream.
 
int stop ()
 Stops reading data from the stream.
 
template<typename Deleter >
int write (std::unique_ptr< char[], Deleter > data, unsigned int len)
 Writes data to the stream.
 
int write (char *data, unsigned int len)
 Writes data to the stream.
 
template<typename S , typename Deleter >
int 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 >
int write (S &send, char *data, unsigned int len)
 Extended write function for sending handles over a pipe handle.
 
int try_write (std::unique_ptr< char[]> data, unsigned int len)
 Queues a write request if it can be completed immediately.
 
template<typename V , typename W >
int try_write (std::unique_ptr< char[]> data, unsigned int len, stream_handle< V, W > &send)
 Queues a write request if it can be completed immediately.
 
int try_write (char *data, unsigned int len)
 Queues a write request if it can be completed immediately.
 
template<typename V , typename W >
int try_write (char *data, unsigned int len, stream_handle< 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 write_queue_size () const noexcept
 Gets the amount of queued bytes waiting to be sent.
 
- Public Member Functions inherited from uvw::handle< T, U, listen_event, end_event, connect_event, shutdown_event, data_event, write_event, E... >
handle_category category () const noexcept
 Gets the category of the handle.
 
handle_type 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 send_buffer_size ()
 Gets the size of the send buffer used for the socket.
 
int send_buffer_size (int value)
 Sets the size of the send buffer used for the socket.
 
int recv_buffer_size ()
 Gets the size of the receive buffer used for the socket.
 
int recv_buffer_size (int value)
 Sets the size of the receive buffer used for the socket.
 
os_file_descriptor fd () const
 Gets the platform dependent file descriptor equivalent.
 
- Public Member Functions inherited from uvw::resource< T, U, close_event, E... >
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.
 
- Public Member Functions inherited from uvw::uv_type< U >
virtual int init ()
 Initializes the handle.
 
loopparent () 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.
 
- Public Member Functions inherited from uvw::emitter< T, E... >
void on (listener_t< U > f)
 Registers a long-lived listener with the event emitter.
 
void reset () noexcept
 Disconnects the listener for the given event type.
 
void reset () noexcept
 Disconnects all listeners.
 
bool has () const noexcept
 Checks if there is a listener registered for the specific event.
 

Detailed Description

template<typename T, typename U, typename... E>
class uvw::stream_handle< T, U, E >

The stream handle.

Stream handles provide an abstraction of a duplex communication channel. The stream handle is an intermediate type, uvw provides three stream implementations: tcp, pipe and tty handles.

Definition at line 108 of file stream.h.

Member Function Documentation

◆ accept()

template<typename T , typename U , typename... E>
template<typename S >
int uvw::stream_handle< T, U, E >::accept ( S &  ref)
inline

Accepts incoming connections.

This call is used in conjunction with listen() to accept incoming connections. Call this function after receiving a listen event to accept the connection. Before calling this function, the submitted handle must be initialized.

When the listen 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 listen event.

Note
Both the handles must be running on the same loop.
Parameters
refAn initialized handle to be used to accept the connection.
Returns
Underlying return value.

Definition at line 217 of file stream.h.

◆ blocking()

template<typename T , typename U , typename... E>
bool uvw::stream_handle< T, U, E >::blocking ( bool  enable = false)
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.

Parameters
enableTrue to enable blocking mode, false otherwise.
Returns
True in case of success, false otherwise.

Definition at line 451 of file stream.h.

◆ listen()

template<typename T , typename U , typename... E>
int uvw::stream_handle< T, U, E >::listen ( int  backlog = DEFAULT_BACKLOG)
inline

Starts listening for incoming connections.

When a new incoming connection is received, a listen event is emitted.

Parameters
backlogIndicates the number of connections the kernel might queue, same as listen(2).
Returns
Underlying return value.

Definition at line 193 of file stream.h.

◆ read()

template<typename T , typename U , typename... E>
int uvw::stream_handle< T, U, E >::read ( )
inline

Starts reading data from an incoming stream.

A data event will be emitted several times until there is no more data to read or stop() is called.
An end event will be emitted when there is no more data to read.

Returns
Underlying return value.

Definition at line 230 of file stream.h.

◆ readable()

template<typename T , typename U , typename... E>
bool uvw::stream_handle< T, U, E >::readable ( ) const
inlinenoexcept

Checks if the stream is readable.

Returns
True if the stream is readable, false otherwise.

Definition at line 424 of file stream.h.

◆ shutdown()

template<typename T , typename U , typename... E>
int uvw::stream_handle< T, U, E >::shutdown ( )
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 shutdown event will be emitted after shutdown is complete.

Returns
Underlying return value.

Definition at line 170 of file stream.h.

◆ stop()

template<typename T , typename U , typename... E>
int uvw::stream_handle< T, U, E >::stop ( )
inline

Stops reading data from the stream.

This function is idempotent and may be safely called on a stopped stream.

Returns
Underlying return value.

Definition at line 241 of file stream.h.

◆ try_write() [1/4]

template<typename T , typename U , typename... E>
int uvw::stream_handle< T, U, E >::try_write ( char *  data,
unsigned int  len 
)
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.

Parameters
dataThe data to be written to the stream.
lenThe lenght of the submitted data.
Returns
Underlying return value.

Definition at line 399 of file stream.h.

◆ try_write() [2/4]

template<typename T , typename U , typename... E>
template<typename V , typename W >
int uvw::stream_handle< T, U, E >::try_write ( char *  data,
unsigned int  len,
stream_handle< V, W > &  send 
)
inline

Queues a write request if it can be completed immediately.

Same as try_write for sending handles over a pipe.

Parameters
dataThe data to be written to the stream.
lenThe lenght of the submitted data.
sendA valid handle suitable for the purpose.
Returns
Underlying return value.

Definition at line 415 of file stream.h.

◆ try_write() [3/4]

template<typename T , typename U , typename... E>
int uvw::stream_handle< T, U, E >::try_write ( std::unique_ptr< char[]>  data,
unsigned int  len 
)
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.

Parameters
dataThe data to be written to the stream.
lenThe lenght of the submitted data.
Returns
Underlying return value.

Definition at line 368 of file stream.h.

◆ try_write() [4/4]

template<typename T , typename U , typename... E>
template<typename V , typename W >
int uvw::stream_handle< T, U, E >::try_write ( std::unique_ptr< char[]>  data,
unsigned int  len,
stream_handle< V, W > &  send 
)
inline

Queues a write request if it can be completed immediately.

Same as try_write for sending handles over a pipe.

Parameters
dataThe data to be written to the stream.
lenThe lenght of the submitted data.
sendA valid handle suitable for the purpose.
Returns
Underlying return value.

Definition at line 384 of file stream.h.

◆ writable()

template<typename T , typename U , typename... E>
bool uvw::stream_handle< T, U, E >::writable ( ) const
inlinenoexcept

Checks if the stream is writable.

Returns
True if the stream is writable, false otherwise.

Definition at line 432 of file stream.h.

◆ write() [1/4]

template<typename T , typename U , typename... E>
int uvw::stream_handle< T, U, E >::write ( char *  data,
unsigned int  len 
)
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 write event will be emitted when the data have been written.

Parameters
dataThe data to be written to the stream.
lenThe lenght of the submitted data.
Returns
Underlying return value.

Definition at line 282 of file stream.h.

◆ write() [2/4]

template<typename T , typename U , typename... E>
template<typename S >
int uvw::stream_handle< T, U, E >::write ( S &  send,
char *  data,
unsigned int  len 
)
inline

Extended write function for sending handles over a pipe handle.

The pipe must be initialized with ipc == true.

send must be a tcp or pipe 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 write event will be emitted when the data have been written.

Parameters
sendThe handle over which to write data.
dataThe data to be written to the stream.
lenThe lenght of the submitted data.
Returns
Underlying return value.

Definition at line 346 of file stream.h.

◆ write() [3/4]

template<typename T , typename U , typename... E>
template<typename S , typename Deleter >
int uvw::stream_handle< T, U, E >::write ( S &  send,
std::unique_ptr< char[], Deleter >  data,
unsigned int  len 
)
inline

Extended write function for sending handles over a pipe handle.

The pipe must be initialized with ipc == true.

send must be a tcp or pipe 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 write event will be emitted when the data have been written.

Parameters
sendThe handle over which to write data.
dataThe data to be written to the stream.
lenThe lenght of the submitted data.
Returns
Underlying return value.

Definition at line 314 of file stream.h.

◆ write() [4/4]

template<typename T , typename U , typename... E>
template<typename Deleter >
int uvw::stream_handle< T, U, E >::write ( std::unique_ptr< char[], Deleter >  data,
unsigned int  len 
)
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 write event will be emitted when the data have been written.

Parameters
dataThe data to be written to the stream.
lenThe lenght of the submitted data.
Returns
Underlying return value.

Definition at line 258 of file stream.h.

◆ write_queue_size()

template<typename T , typename U , typename... E>
size_t uvw::stream_handle< T, U, E >::write_queue_size ( ) const
inlinenoexcept

Gets the amount of queued bytes waiting to be sent.

Returns
Amount of queued bytes waiting to be sent.

Definition at line 459 of file stream.h.


The documentation for this class was generated from the following file: