Boost logo

Boost :

Subject: Re: [boost] Boost ASIO - Client Request TCP Help..!!
From: Joseph Van Riper (fleeb.fantastique_at_[hidden])
Date: 2013-10-14 08:35:52


On Mon, Oct 14, 2013 at 7:56 AM, Rahul Mathur <srivmuk_at_[hidden]> wrote:

> Thanks Joseph, I did try as -
>
> ---
> boost::asio::socket_base::keep_alive option;
> socket.get_option(option);
> if (bool is_set = option.value())
> std::cout << "Setsocket option err: SO_KEEPALIVE --unable
> to set keep alive tcp connection." << std::endl;
> else
> std::cout << "S0_KEEPALIVE set, with SOL_SOCKET --- Keep
> Alive option set." << std::endl;
> ---
>
> and it worked.
>

Notice that you are not affecting a change of the socket's option with this
code. You are only reporting on the keep-alive option. And even then, you
had the results reversed, reporting the option as set when it wasn't.

If you want to cause the socket's option to change, you would call it's
set_option function as in my original example.

To clarify your code a little by not setting a variable while
simultaneously testing it in an if statement, consider:

boost::asio::ip::tcp::socket::keep_alive keep_alive;
socket.get_option( keep_alive );
bool is_set = keep_alive.value();
if ( is_set )
{
  std::cout << "Socket keep-alive option is set." << std::endl;
}
else
{
  std::cout << "Socket keep-alive option is not set." << std::endl;
}

I hope this is helpful.

- Trey


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk