Opened 6 years ago

Last modified 6 years ago

#12437 new Bugs

asio::async_read with a tcp socket gives erroneous results under Windows

Reported by: anonymous Owned by: chris_kohlhoff
Milestone: Boost 1.61.0 Component: asio
Version: Boost 1.62.0 Severity: Showstopper
Keywords: Cc:

Description

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

Change History (1)

comment:1 by anonymous, 6 years ago

It looks like the asio code is ok and this is an application bug. I attempted to close this ticket but couldn't find a way I can do that.

Note: See TracTickets for help on using tickets.