<div dir="ltr"><div>The TCP/IP protocol was designed to work over unreliable networks, including sections that hop over radio links and dial-up telephone lines.</div><div><br></div><div>In a nutshell, the way the internet works is that packets are transmitted and it is assumed that they may or may not arrive at some time in the future. There are timeouts built in, but they are longer than you would probably want, on account of all the unreliable dial-ups between you and the other peer.</div><div><br></div><div>Therefore, to involve a timeout you need to run a timer in parallel with the send/receive operation and cancel the operation if the timeout occurs before the operation has completed.</div><div><br></div><div>This is easier with asio&#39;s async interface, but you can still do it with the synchronous interface by using SIGALM (or equivalent).</div><div><br></div><div>The relevant voodoo is documented here for linux:</div><div><a href="https://man7.org/linux/man-pages/man7/signal.7.html">https://man7.org/linux/man-pages/man7/signal.7.html</a><br></div><div><br></div><div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 19 Feb 2021 at 17:52, Child OfGod via Boost-users &lt;<a href="mailto:boost-users@lists.boost.org">boost-users@lists.boost.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">In TgBot library i use under MSVC++, in tgbot/net/BoostHttpOnlySslClient.cpp,<br>a call to boost::asio::read() does not return when internet is disconnected for a few minutes.<br><br>I would appreciate any help to get this resolved, i.e. for the read function to return if it fails after some timeout has passed<br><br>the code block in the 

tgbot/net/BoostHttpOnlySslClient.cpp file:<br><br>[code]<div>string BoostHttpOnlySslClient::makeRequest(const Url&amp; url, const vector&lt;HttpReqArg&gt;&amp; args) const {<br>    tcp::resolver resolver(_ioService);<br>    tcp::resolver::query query(url.host, &quot;443&quot;);<br><br>    ssl::context context(ssl::context::tlsv12_client);<br>    context.set_default_verify_paths();<br>    ssl::stream&lt;tcp::socket&gt; socket(_ioService, context);<br>    connect(socket.lowest_layer(), resolver.resolve(query));<br><br>    #ifdef TGBOT_DISABLE_NAGLES_ALGORITHM<br>    socket.lowest_layer().set_option(tcp::no_delay(true));<br>    #endif //TGBOT_DISABLE_NAGLES_ALGORITHM<br>    #ifdef TGBOT_CHANGE_SOCKET_BUFFER_SIZE<br>    #if _arm64 || _WIN64 || __amd64__ || __x86_64__ || __MINGW64__ || __aarch64__ || __powerpc64__<br>    socket.lowest_layer().set_option(socket_base::send_buffer_size(65536));<br>    socket.lowest_layer().set_option(socket_base::receive_buffer_size(65536));<br>    #else //for 32-bit<br>    socket.lowest_layer().set_option(socket_base::send_buffer_size(32768));<br>    socket.lowest_layer().set_option(socket_base::receive_buffer_size(32768));<br>    #endif //Processor architecture<br>    #endif //TGBOT_CHANGE_SOCKET_BUFFER_SIZE<br>    socket.set_verify_mode(ssl::verify_none);<br>    socket.set_verify_callback(ssl::rfc2818_verification(url.host));<br><br>    socket.handshake(ssl::stream&lt;tcp::socket&gt;::client);<br><br>    string requestText = _httpParser.generateRequest(url, args, false);<br>    write(socket, buffer(requestText.c_str(), requestText.length()));<br><br>    string response;<br><br>    #ifdef TGBOT_CHANGE_READ_BUFFER_SIZE<br>    #if _M_ARM64 || _WIN64 || __amd64__ || __x86_64__ || __MINGW64__ || __aarch64__ || __powerpc64__<br>    char buff[65536];<br>    #else //for 32-bit<br>    char buff[32768];<br>    #endif //Processor architecture<br>    #else<br>    char buff[1024];<br>    #endif //TGBOT_CHANGE_READ_BUFFER_SIZE<br><br>    boost::system::error_code error;<br>    while (!error) {<br>        std::size_t bytes = read(socket, buffer(buff), error);<br>        response += string(buff, bytes);<br>    }<br><br>    return _httpParser.extractBody(response);<br>}<br><div>[/code]<br><br>Thankyou in advance😀🙏</div></div></div>
_______________________________________________<br>
Boost-users mailing list<br>
<a href="mailto:Boost-users@lists.boost.org" target="_blank">Boost-users@lists.boost.org</a><br>
<a href="https://lists.boost.org/mailman/listinfo.cgi/boost-users" rel="noreferrer" target="_blank">https://lists.boost.org/mailman/listinfo.cgi/boost-users</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr">Richard Hodges<div><a href="mailto:hodges.r@gmail.com" target="_blank">hodges.r@gmail.com</a></div><div>office: +442032898513</div><div>home: +376841522</div><div>mobile: +376380212</div><div><br></div></div></div></div></div></div>