Boost logo

Boost :

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


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

> In continuation of above original code, as send() static API worked fine,
> now to to set "Keep Alive Option" for the socket, I did tried as -
>
> ---
> int sockKeepAliveOption = 1;
> int n2 = setsockopt(socket.native(), SOL_SOCKET, SO_SNDTIMEO,
> &sockKeepAliveOption, sizeof(sockKeepAliveOption));
>
> if(n2 == -1)
> 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;
> ---
>
> It goes to if condition of "n2 = -1", i.e unable to set keep alive tcp
> connection.
>
> Please suggest - How can I correct above to have "Keep Alive option set".
>
> Thanks!!

This page might be helpful:

http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/basic_stream_socket/keep_alive.html

So, I think you'd do something like:

socket.set_option( boost::ip::tcp::socket::keep_alive( true ) );

- Trey


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