boost::corosio::tcp

Encapsulate the TCP protocol for socket creation.

Synopsis

Declared in <boost/corosio/tcp.hpp>

class tcp;

Description

This class identifies the TCP protocol and its address family (IPv4 or IPv6). It is used to parameterize socket and acceptor open() calls with a self‐documenting type.

The family(), type(), and protocol() members return the three integers passed to the operating system's socket() call. Their values are platform‐defined constants taken from the system socket headers. For an inline variant that includes those headers, use native_tcp.

Example

tcp_acceptor acc( ioc );
acc.open( tcp::v6() );  // IPv6 socket
acc.set_option( socket_option::reuse_address( true ) );
acc.bind( endpoint( ipv6_address::any(), 8080 ) );
acc.listen();

Type Aliases

Name

Description

acceptor

The acceptor type to use with this protocol, tcp_acceptor.

socket

The socket type to use with this protocol, tcp_socket.

Member Functions

Name

Description

family

Return the address family (AF_INET or AF_INET6).

is_v6

Return true if this is IPv6.

Static Member Functions

Name

Description

protocol

Return the IP protocol (IPPROTO_TCP).

type

Return the socket type (SOCK_STREAM).

v4

Construct an IPv4 TCP protocol.

v6

Construct an IPv6 TCP protocol.

Friends

Name

Description

boost::corosio::operator!=

Test for inequality.

boost::corosio::operator==

Test for equality.

See Also

native_tcp, tcp_socket, tcp_acceptor

Created with MrDocs