Skip to content

Commit

Permalink
async_write_some() with a zero size buffer is well defined. Fixing #23
Browse files Browse the repository at this point in the history
  • Loading branch information
TorstenRobitzki committed Apr 25, 2016
1 parent 2ea38a1 commit bd7637e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions source/asio_mocks/test_socket.h
Expand Up @@ -1025,6 +1025,12 @@ void socket<Iterator, Timer, Trait>::impl::async_write_some(
return;
}

if ( boost::asio::buffer_size( buffers ) == 0 )
{
io_service_.post(boost::bind<void>(handler, boost::system::error_code(), 0));
return;
}

if ( !write_plan_.empty() )
{
const write_plan::item item = write_plan_.next_write();
Expand Down
19 changes: 19 additions & 0 deletions source/asio_mocks/test_socket_test.cpp
Expand Up @@ -412,3 +412,22 @@ BOOST_AUTO_TEST_CASE( reading_into_a_zero_byte_buffer )
BOOST_CHECK( result.called );
BOOST_CHECK_EQUAL( result.bytes_transferred, 0 );
}

BOOST_AUTO_TEST_CASE( writing_from_zero_byte_buffer )
{
asio_mocks::io_completed result;

boost::asio::io_service queue;
asio_mocks::socket<const char*> sock( queue, begin(simple_get_11), end(simple_get_11) );
const char buf = 0x42;

sock.async_write_some(
boost::asio::buffer( &buf, 0 ),
result );

tools::run( queue );

BOOST_CHECK( !result.error );
BOOST_CHECK( result.called );
BOOST_CHECK_EQUAL( result.bytes_transferred, 0 );
}

0 comments on commit bd7637e

Please sign in to comment.