[Boost-bugs] [Boost C++ Libraries] #12437: asio::async_read with a tcp socket gives erroneous results under Windows

Subject: [Boost-bugs] [Boost C++ Libraries] #12437: asio::async_read with a tcp socket gives erroneous results under Windows
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-09-05 05:09:12


#12437: asio::async_read with a tcp socket gives erroneous results under Windows
--------------------------+----------------------------
 Reporter: anonymous | Owner: chris_kohlhoff
     Type: Bugs | Status: new
Milestone: Boost 1.61.0 | Component: asio
  Version: Boost 1.62.0 | Severity: Showstopper
 Keywords: |
--------------------------+----------------------------
 I'm seeing asio::async_read give erroneous results with a tcp socket under
 Windows.

 From the asio source code, async_read under Windows calls WSARecv, and it
 directly violates the "specification" of that function. The line in error
 is in the function "start_receive_op" in the source file socket_ops.ipp.
 It reads:

 int result = ::WSARecv(impl.socket_, buffers,
     static_cast<DWORD>(buffer_count),
     &bytes_transferred, &recv_flags, op, 0);

 asio is using both the 3rd parameter lpNumberOfBytesRecvd which is set to
 "&bytes_transferred" and the 5th parameter lpOverlapped which is set to
 "op". This violates the documentation for WSARecv.

 According to Microsoft's documentation for WSARecv's 3rd parameter
 lpNumberOfBytesRecvd: "Use NULL for this parameter if the lpOverlapped
 parameter is not NULL to avoid potentially erroneous results." Because the
 5th parameter lpOverlapped is not NULL, the 3rd parameter
 lpNumberOfBytesRecvd must be set to NULL and bytes_transferred must be
 determined by some other method (probably by examining the contents of the
 lpOverlapped parameter).

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/12437>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:20 UTC