uvcc
libuv C++ bindings
uv::tcp Class Reference

TCP handle. More...

#include "handle-stream.hpp"

Inheritance diagram for uv::tcp:
uv::stream uv::io uv::handle

Public Types

using uv_t = ::uv_tcp_t
 
- Public Types inherited from uv::stream
using uv_t = ::uv_stream_t
 
using on_connection_t = std::function< void(stream _server) >
 The function type of the callback called when a stream server has received an incoming connection. More...
 
- Public Types inherited from uv::io
using uv_t = void
 
using on_read_t = std::function< void(io _handle, ssize_t _nread, buffer _buffer, int64_t _offset, void *_info) >
 The function type of the callback called by read_start() when data was read from an I/O endpoint. More...
 
- Public Types inherited from uv::handle
using uv_t = ::uv_handle_t
 
using on_destroy_t = std::function< void(void *_data) >
 The function type of the callback called when the handle has been closed and about to be destroyed. More...
 

Public Member Functions

 tcp (const tcp &)=default
 
tcpoperator= (const tcp &)=default
 
 tcp (tcp &&) noexcept=default
 
tcpoperator= (tcp &&) noexcept=default
 
 tcp (uv::loop &_loop, unsigned _flags=AF_UNSPEC)
 Create a TCP socket with the specified flags. More...
 
 tcp (uv::loop &_loop, ::uv_os_sock_t _socket, bool _set_blocking)
 Create a handle object from an existing native platform depended TCP socket descriptor. More...
 
::uv_os_sock_t socket () const noexcept
 Get the platform dependent socket descriptor. The alias for handle::fileno().
 
int nodelay (bool _enable) noexcept
 Enable or disable Nagle’s algorithm on the socket.
 
int keepalive (bool _enable, unsigned int _delay) noexcept
 Enable or disable TCP keep-alive. More...
 
int simultaneous_accepts (bool _enable) noexcept
 
template<typename _T_ , typename = std::enable_if_t< is_one_of< _T_, ::sockaddr, ::sockaddr_in, ::sockaddr_in6, ::sockaddr_storage >::value >>
int bind (const _T_ &_sockaddr, unsigned int _flags=0) noexcept
 Bind the handle to an address and port. More...
 
template<typename _T_ , typename = std::enable_if_t< is_one_of< _T_, ::sockaddr_in, ::sockaddr_in6, ::sockaddr_storage >::value >>
bool getsockname (_T_ &_sockaddr) const noexcept
 Get the local address which this handle is bound to. More...
 
template<typename _T_ , typename = std::enable_if_t< is_one_of< _T_, ::sockaddr_in, ::sockaddr_in6, ::sockaddr_storage >::value >>
bool getpeername (_T_ &_sockaddr) const noexcept
 Get the address of the remote peer connected to this handle. More...
 
unsigned int send_buffer_size () const noexcept
 Get the size of the send buffer that the operating system uses for the socket. More...
 
void send_buffer_size (unsigned int _value) noexcept
 Set the size of the send buffer that the operating system uses for the socket. More...
 
unsigned int recv_buffer_size () const noexcept
 Get the size of the receive buffer that the operating system uses for the socket. More...
 
void recv_buffer_size (unsigned int _value) noexcept
 Set the size of the receive buffer that the operating system uses for the socket. More...
 
 operator const uv_t * () const noexcept
 
 operator uv_t * () noexcept
 
- Public Member Functions inherited from uv::stream
 stream (const stream &)=default
 
streamoperator= (const stream &)=default
 
 stream (stream &&) noexcept=default
 
streamoperator= (stream &&) noexcept=default
 
on_connection_ton_connection () const noexcept
 
int listen (int _backlog, const on_connection_t &_connection_cb) const
 Start listening for incoming connections. More...
 
stream accept () const
 Accept incoming connections. More...
 
std::size_t write_queue_size () const noexcept
 The amount of queued bytes waiting to be sent.
 
bool is_readable () const noexcept
 Check if the stream is readable.
 
bool is_writable () const noexcept
 Check if the stream is writable.
 
int set_blocking (bool _enable) noexcept
 Enable or disable blocking mode for the stream. More...
 
 operator const uv_t * () const noexcept
 
 operator uv_t * () noexcept
 
- Public Member Functions inherited from uv::io
 io (const io &)=default
 
iooperator= (const io &)=default
 
 io (io &&) noexcept=default
 
iooperator= (io &&) noexcept=default
 
std::size_t write_queue_size () const noexcept
 The amount of queued bytes waiting to be written/sent to the I/O endpoint. More...
 
on_buffer_alloc_ton_alloc () const noexcept
 Set the input buffer allocation callback.
 
on_read_ton_read () const noexcept
 Set the read callback function.
 
int read_start (std::size_t _size=0, int64_t _offset=-1) const
 Start reading incoming data from the I/O endpoint. More...
 
int read_start (const on_buffer_alloc_t &_alloc_cb, const on_read_t &_read_cb, std::size_t _size=0, int64_t _offset=-1) const
 Start reading incoming data from the I/O endpoint with provided input buffer allocation callback (_alloc_cb) and read callback function (_read_cb). More...
 
int read_stop () const
 Stop reading data from the I/O endpoint. More...
 
int read_pause (bool _trigger_condition) const
 Pause reading data from the I/O endpoint. More...
 
int read_resume (bool _trigger_condition)
 Resume reading data from the I/O endpoint after having been paused. More...
 
 operator const uv_t * () const noexcept
 
 operator uv_t * () noexcept
 
- Public Member Functions inherited from uv::handle
 handle (const handle &_that)
 
handleoperator= (const handle &_that)
 
 handle (handle &&_that) noexcept
 
handleoperator= (handle &&_that) noexcept
 
void swap (handle &_that) noexcept
 
std::uintptr_t id () const noexcept
 The unique ID of the instance managed by this handle variable or 0 if the handle is void.
 
long nrefs () const noexcept
 The current number of existing references to the same object as this handle variable refers to.
 
int uv_status () const noexcept
 The status value returned by the last executed libuv API function on this handle.
 
on_destroy_ton_destroy () const noexcept
 
::uv_handle_type type () const noexcept
 The tag indicating the libuv type of the handle.
 
const char * type_name () const noexcept
 A string containing the name of the handle type.
 
uv::loop loop () const noexcept
 The libuv loop where the handle is running on. More...
 
void *& data () const noexcept
 The pointer to the user-defined arbitrary data. libuv and uvcc does not use this field.
 
int is_active () const noexcept
 Check if the handle is active. More...
 
int is_closing () const noexcept
 Check if the handle is closing or closed. More...
 
::uv_os_fd_t fileno () const noexcept
 Get the platform dependent handle/file descriptor. More...
 
 operator const uv_t * () const noexcept
 
 operator uv_t * () noexcept
 
 operator bool () const noexcept
 Equivalent to (id() and uv_status() >= 0).
 
void attached (bool _state) const noexcept
 
bool attached () const noexcept
 

Additional Inherited Members

- Static Public Member Functions inherited from uv::io
static io guess_handle (uv::loop &, ::uv_file)
 Create an io handle object which actual type is derived from an existing file descriptor. More...
 

Detailed Description

TCP handle.

See also
libuv API documentation: uv_tcp_t — TCP handle.

Definition at line 154 of file handle-stream.hpp.

Constructor & Destructor Documentation

◆ tcp() [1/2]

uv::tcp::tcp ( uv::loop _loop,
unsigned  _flags = AF_UNSPEC 
)
inline

Create a TCP socket with the specified flags.

Note
With AF_UNSPEC flag no socket is actually created on the system.
See also
libuv API documentation: uv_tcp_init_ex().
libuv enhancement proposals: https://github.com/libuv/leps/blob/master/003-create-sockets-early.md.

Definition at line 185 of file handle-stream.hpp.

◆ tcp() [2/2]

uv::tcp::tcp ( uv::loop _loop,
::uv_os_sock_t  _socket,
bool  _set_blocking 
)
inline

Create a handle object from an existing native platform depended TCP socket descriptor.

See also
libuv API documentation: uv_tcp_open(), uv_tcp_init().

Definition at line 197 of file handle-stream.hpp.

Member Function Documentation

◆ keepalive()

int uv::tcp::keepalive ( bool  _enable,
unsigned int  _delay 
)
inlinenoexcept

Enable or disable TCP keep-alive.

  • _delay is the initial delay in seconds, ignored when _enable = false.

Definition at line 220 of file handle-stream.hpp.

◆ simultaneous_accepts()

int uv::tcp::simultaneous_accepts ( bool  _enable)
inlinenoexcept

Enable or disable simultaneous asynchronous accept requests that are queued by the operating system when listening for new TCP connections.

See also
libuv API documentation: uv_tcp_simultaneous_accepts().

Definition at line 223 of file handle-stream.hpp.

◆ bind()

template<typename _T_ , typename = std::enable_if_t< is_one_of< _T_, ::sockaddr, ::sockaddr_in, ::sockaddr_in6, ::sockaddr_storage >::value >>
int uv::tcp::bind ( const _T_ &  _sockaddr,
unsigned int  _flags = 0 
)
inlinenoexcept

Bind the handle to an address and port.

See also
libuv API documentation: uv_tcp_bind().

Definition at line 231 of file handle-stream.hpp.

◆ getsockname()

template<typename _T_ , typename = std::enable_if_t< is_one_of< _T_, ::sockaddr_in, ::sockaddr_in6, ::sockaddr_storage >::value >>
bool uv::tcp::getsockname ( _T_ &  _sockaddr) const
inlinenoexcept

Get the local address which this handle is bound to.

Returns
true if the operation has completed successfully (can be checked with uv_status()) and the size of the passed argument (i.e. sizeof(_T_)) is enough to hold the returned socket address structure.
See also
libuv API documentation: uv_tcp_getsockname().

Definition at line 241 of file handle-stream.hpp.

◆ getpeername()

template<typename _T_ , typename = std::enable_if_t< is_one_of< _T_, ::sockaddr_in, ::sockaddr_in6, ::sockaddr_storage >::value >>
bool uv::tcp::getpeername ( _T_ &  _sockaddr) const
inlinenoexcept

Get the address of the remote peer connected to this handle.

Returns
true if the operation has completed successfully (can be checked with uv_status()) and the size of the passed argument (i.e. sizeof(_T_)) is enough to hold the returned socket address structure.
See also
libuv API documentation: uv_tcp_getpeername().

Definition at line 254 of file handle-stream.hpp.

◆ send_buffer_size() [1/2]

unsigned int uv::tcp::send_buffer_size ( ) const
inlinenoexcept

Get the size of the send buffer that the operating system uses for the socket.

See also
libuv API documentation: uv_send_buffer_size().

Definition at line 266 of file handle-stream.hpp.

◆ send_buffer_size() [2/2]

void uv::tcp::send_buffer_size ( unsigned int  _value)
inlinenoexcept

Set the size of the send buffer that the operating system uses for the socket.

See also
libuv API documentation: uv_send_buffer_size().

Definition at line 274 of file handle-stream.hpp.

◆ recv_buffer_size() [1/2]

unsigned int uv::tcp::recv_buffer_size ( ) const
inlinenoexcept

Get the size of the receive buffer that the operating system uses for the socket.

See also
libuv API documentation: uv_recv_buffer_size().

Definition at line 278 of file handle-stream.hpp.

◆ recv_buffer_size() [2/2]

void uv::tcp::recv_buffer_size ( unsigned int  _value)
inlinenoexcept

Set the size of the receive buffer that the operating system uses for the socket.

See also
libuv API documentation: uv_recv_buffer_size().

Definition at line 286 of file handle-stream.hpp.


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