Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
roc::netio Namespace Reference

Network I/O. More...

Classes

class  BasicPort
 Base class for ports. More...
 
class  ICloseHandler
 Close handler interface. More...
 
class  IConn
 Connection interface. More...
 
class  IConnAcceptor
 Connection acceptor interface. More...
 
class  IConnHandler
 Connection event handler interface. More...
 
class  INetworkTaskCompleter
 Network task completion handler. More...
 
class  IResolverRequestHandler
 Resolver request result handler interface. More...
 
class  ITerminateHandler
 Termination handler interface. More...
 
class  NetworkLoop
 Network event loop thread. More...
 
class  NetworkTask
 Base class for network loop tasks. More...
 
class  Resolver
 Hostname resolver. More...
 
struct  ResolverRequest
 Resolver request. More...
 
struct  TcpConnectionConfig
 TCP connection parameters. More...
 
struct  TcpClientConfig
 TCP connection parameters. More...
 
class  TcpConnectionPort
 TCP connection port. More...
 
struct  TcpServerConfig
 TCP server parameters. More...
 
class  TcpServerPort
 TCP server. More...
 
struct  UdpConfig
 UDP port parameters. More...
 
class  UdpPort
 UDP sender/receiver port. More...
 
struct  SocketOpts
 Socket options. More...
 

Typedefs

typedef int SocketHandle
 Platform-specific socket handle. More...
 

Enumerations

enum  AsyncOperationStatus { AsyncOp_Started , AsyncOp_Completed }
 Asynchronous operation status. More...
 
enum  TcpConnectionType { TcpConn_Client , TcpConn_Server }
 TCP connection type. More...
 
enum  TerminationMode { Term_Normal , Term_Failure }
 Connection termination mode. More...
 
enum  SocketType { SocketType_Tcp , SocketType_Udp }
 Socket type. More...
 
enum  SocketError { SockErr_WouldBlock = -1 , SockErr_StreamEnd = -2 , SockErr_Failure = -3 }
 I/O error codes. More...
 

Functions

const char * termination_mode_to_str (TerminationMode mode)
 Get string representation of termination mode. More...
 
ROC_ATTR_NODISCARD bool socket_create (address::AddrFamily family, SocketType type, SocketHandle &new_sock)
 Create non-blocking socket. More...
 
ROC_ATTR_NODISCARD bool socket_accept (SocketHandle sock, SocketHandle &new_sock, address::SocketAddr &remote_address)
 Accept incoming connection. More...
 
ROC_ATTR_NODISCARD bool socket_setup (SocketHandle sock, const SocketOpts &options)
 Set socket options. More...
 
ROC_ATTR_NODISCARD bool socket_bind (SocketHandle sock, address::SocketAddr &local_address)
 Bind socket to local address. More...
 
ROC_ATTR_NODISCARD bool socket_listen (SocketHandle sock, size_t backlog)
 Start listening for incoming connections. More...
 
ROC_ATTR_NODISCARD bool socket_begin_connect (SocketHandle sock, const address::SocketAddr &remote_address, bool &completed_immediately)
 Initiate connecting to remote peer. More...
 
ROC_ATTR_NODISCARD bool socket_end_connect (SocketHandle sock)
 Finish connecting to remote peer. More...
 
ROC_ATTR_NODISCARD ssize_t socket_try_recv (SocketHandle sock, void *buf, size_t bufsz)
 Try to read bytes from socket without blocking. More...
 
ROC_ATTR_NODISCARD ssize_t socket_try_send (SocketHandle sock, const void *buf, size_t bufsz)
 Try to write bytes to socket without blocking. More...
 
ROC_ATTR_NODISCARD ssize_t socket_try_send_to (SocketHandle sock, const void *buf, size_t bufsz, const address::SocketAddr &remote_address)
 Try to send datagram via socket to given address, without blocking. More...
 
ROC_ATTR_NODISCARD bool socket_shutdown (SocketHandle sock)
 Gracefully shutdown connection. More...
 
ROC_ATTR_NODISCARD bool socket_close (SocketHandle sock)
 Close socket. More...
 
ROC_ATTR_NODISCARD bool socket_close_with_reset (SocketHandle sock)
 Close socket and send reset to remote peer. Remote peer will get error when reading from connection. More...
 

Variables

const SocketHandle SocketInvalid = -1
 Invalid socket handle. More...
 

Detailed Description

Network I/O.

Typedef Documentation

◆ SocketHandle

Platform-specific socket handle.

Definition at line 51 of file socket_ops.h.

Enumeration Type Documentation

◆ AsyncOperationStatus

Asynchronous operation status.

Enumerator
AsyncOp_Started 

Operation is initiated and running.

AsyncOp_Completed 

Operation is completed.

Definition at line 19 of file operation_status.h.

◆ SocketError

I/O error codes.

Enumerator
SockErr_WouldBlock 

Operation can't be performed without blocking, try later.

SockErr_StreamEnd 

End of stream, no more data.

SockErr_Failure 

Failure.

Definition at line 39 of file socket_ops.h.

◆ SocketType

Socket type.

Enumerator
SocketType_Tcp 

TCP socket.

SocketType_Udp 

UDP socket.

Definition at line 23 of file socket_ops.h.

◆ TcpConnectionType

TCP connection type.

Enumerator
TcpConn_Client 

Local peer is client, remote peer is server.

TcpConn_Server 

Local peer is server, remote peer is client.

Definition at line 49 of file tcp_connection_port.h.

◆ TerminationMode

Connection termination mode.

Enumerator
Term_Normal 

Normal graceful termination.

Remarks
Remote peer will recieve stream end without errors.
Term_Failure 

Termination with error.

Remarks
Remote peer will receive connection reset and report failure.

Definition at line 19 of file termination_mode.h.

Function Documentation

◆ socket_accept()

ROC_ATTR_NODISCARD bool roc::netio::socket_accept ( SocketHandle  sock,
SocketHandle new_sock,
address::SocketAddr remote_address 
)

Accept incoming connection.

◆ socket_begin_connect()

ROC_ATTR_NODISCARD bool roc::netio::socket_begin_connect ( SocketHandle  sock,
const address::SocketAddr remote_address,
bool &  completed_immediately 
)

Initiate connecting to remote peer.

Returns
true if connection was successfully initiated. Sets completed_immediately to true if connection was established immediately and there is no need to wait for it.

◆ socket_bind()

ROC_ATTR_NODISCARD bool roc::netio::socket_bind ( SocketHandle  sock,
address::SocketAddr local_address 
)

Bind socket to local address.

◆ socket_close()

ROC_ATTR_NODISCARD bool roc::netio::socket_close ( SocketHandle  sock)

Close socket.

◆ socket_close_with_reset()

ROC_ATTR_NODISCARD bool roc::netio::socket_close_with_reset ( SocketHandle  sock)

Close socket and send reset to remote peer. Remote peer will get error when reading from connection.

◆ socket_create()

ROC_ATTR_NODISCARD bool roc::netio::socket_create ( address::AddrFamily  family,
SocketType  type,
SocketHandle new_sock 
)

Create non-blocking socket.

◆ socket_end_connect()

ROC_ATTR_NODISCARD bool roc::netio::socket_end_connect ( SocketHandle  sock)

Finish connecting to remote peer.

Returns
true if connection was successfully established.

◆ socket_listen()

ROC_ATTR_NODISCARD bool roc::netio::socket_listen ( SocketHandle  sock,
size_t  backlog 
)

Start listening for incoming connections.

◆ socket_setup()

ROC_ATTR_NODISCARD bool roc::netio::socket_setup ( SocketHandle  sock,
const SocketOpts options 
)

Set socket options.

◆ socket_shutdown()

ROC_ATTR_NODISCARD bool roc::netio::socket_shutdown ( SocketHandle  sock)

Gracefully shutdown connection.

◆ socket_try_recv()

ROC_ATTR_NODISCARD ssize_t roc::netio::socket_try_recv ( SocketHandle  sock,
void *  buf,
size_t  bufsz 
)

Try to read bytes from socket without blocking.

Returns
number of bytes read (>= 0) or SocketError (< 0).

◆ socket_try_send()

ROC_ATTR_NODISCARD ssize_t roc::netio::socket_try_send ( SocketHandle  sock,
const void *  buf,
size_t  bufsz 
)

Try to write bytes to socket without blocking.

Returns
number of bytes written (>= 0) or SocketError (< 0).

◆ socket_try_send_to()

ROC_ATTR_NODISCARD ssize_t roc::netio::socket_try_send_to ( SocketHandle  sock,
const void *  buf,
size_t  bufsz,
const address::SocketAddr remote_address 
)

Try to send datagram via socket to given address, without blocking.

Returns
number of bytes written (>= 0) or SocketError (< 0).

◆ termination_mode_to_str()

const char* roc::netio::termination_mode_to_str ( TerminationMode  mode)

Get string representation of termination mode.

Variable Documentation

◆ SocketInvalid

const SocketHandle roc::netio::SocketInvalid = -1

Invalid socket handle.

Definition at line 54 of file socket_ops.h.