asio C++ library

PrevUpHomeNext
basic_socket::set_option (2 of 2 overloads)

Set an option on the socket.

template<
    typename SettableSocketOption>
void set_option(
    const SettableSocketOption & option,
    asio::error_code & ec);

This function is used to set an option on the socket.

Parameters

option

The new option value to be set on the socket.

ec

Set to indicate what error occurred, if any.

Example

Setting the IPPROTO_TCP/TCP_NODELAY option:

asio::ip::tcp::socket socket(io_context);
...
asio::ip::tcp::no_delay option(true);
asio::error_code ec;
socket.set_option(option, ec);
if (ec)
{
  // An error occurred.
}

PrevUpHomeNext