Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost/Asio short read error
From: Igor R (boost.lists_at_[hidden])
Date: 2012-05-22 09:43:28


> 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.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net