Re: [Boost-users] Boost/Asio short read error

Windows 7 64 bit ultimate, boost 1.49, examples from: http://www.stderr.org/doc/libasio-doc/examples/ssl_client_cpp.html http://www.stderr.org/doc/libasio-doc/examples/ssl_server_cpp.html Currently SSL works great, but several days ago I had many times "short read" error. Best regards Marcin
What boost/asio version do you use? What's your platform? What specific example are you talking about?
I have problem with Boost/asio - sometimes server returns "short read" error. I'm using client/server from the examples. Please write me - is it a bug or just wrong implemented example because the error occurs not every time. How to protect my application against the error?
Dom Maklerski Banku Ochrony Środowiska Spółka Akcyjna ul. Marszałkowska 78/80 / 00-517 Warszawa wpisana w Rejestrze Przedsiębiorców prowadzonym przez Sąd Rejonowy dla m. st. Warszawy XII Wydział Gospodarczy Krajowego Rejestru Sądowego pod numerem: KRS 0000048901 / NIP 526-10-26-828 Kapitał zakładowy w wysokości 21.551.200zł wpłacony w całości. P - Nie drukuj tej wiadomości, jeśli to nie jest konieczne.

Windows 7 64 bit ultimate, boost 1.49, examples from:
http://www.stderr.org/doc/libasio-doc/examples/ssl_client_cpp.html
http://www.stderr.org/doc/libasio-doc/examples/ssl_server_cpp.html
Currently SSL works great, but several days ago I had many times “short read” error.
Ok, I see. On "short read" you should re-start your async.operation (I believe then you'll get eof).

Hi, thank you for help. In the Asio mailing group another man wrote: "Actually, it is not something to worry about. Normally this error code is returned when the SSL client does not close its connection properly, i.e. without calling SSL_shutdown() (terminated from the task manager, for example). The connection is closed by the client one way or another, the server can do nothing but ignore it. You can check this error code as follows: if (error.category() == boost::asio::error::get_ssl_category() && error.value() != ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ)) // boost returns "short_read" wehen the peer calls SSL_shutdown() { // the client went down abruptly }" What is the best way to handle the error - restart async operation or do checking as mentioned above? Best regards Marcin Dom Maklerski Banku Ochrony Środowiska Spółka Akcyjna ul. Marszałkowska 78/80 / 00-517 Warszawa wpisana w Rejestrze Przedsiębiorców prowadzonym przez Sąd Rejonowy dla m. st. Warszawy XII Wydział Gospodarczy Krajowego Rejestru Sądowego pod numerem: KRS 0000048901 / NIP 526-10-26-828 Kapitał zakładowy w wysokości 21.551.200zł wpłacony w całości. P - Nie drukuj tej wiadomości, jeśli to nie jest konieczne.

In the Asio mailing group another man wrote: "Actually, it is not something to worry about.
Normally this error code is returned when the SSL client does not close its connection properly, i.e. without calling SSL_shutdown() (terminated from the task manager, for example).
The connection is closed by the client one way or another, the server can do nothing but ignore it.
You can check this error code as follows: if (error.category() == boost::asio::error::get_ssl_category() && error.value() != ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ)) // boost returns "short_read" wehen the peer calls SSL_shutdown() { // the client went down abruptly }"
What is the best way to handle the error - restart async operation or do checking as mentioned above?
Actually, after taking a look at the asio sources, I'm a bit confused: const boost::system::error_code& engine::map_error_code(boost::system::error_code& ec) const { // We only want to map the error::eof code. if (ec != boost::asio::error::eof) return ec; // If there's data yet to be read, it's an error. if (BIO_wpending(ext_bio_)) { ec = boost::system::error_code( ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ), boost::asio::error::get_ssl_category()); return ec; } // SSL v2 doesn't provide a protocol-level shutdown, so an eof on the // underlying transport is passed through. if (ssl_ && ssl_->version == SSL2_VERSION) return ec; // Otherwise, the peer should have negotiated a proper shutdown. if ((::SSL_get_shutdown(ssl_) & SSL_RECEIVED_SHUTDOWN) == 0) { ec = boost::system::error_code( ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ), boost::asio::error::get_ssl_category()); } return ec; } So, in the both cases you get the same error_code (short read). If "the peer negotiated a proper shutdown", and you try to read more, wouldn't you get another "short read" - that's the question... I believe you should experiment and see what you get.
participants (2)
-
Igor R
-
Marcin Głogowski