trying understand boost asio library, implemented async echo server. ask tcp::socket async_read_some small amount of data, namely 9 bytes (chosen testing small number), i.e. socket_.async_read_some(boost::asio::buffer(buf, 9), callback). feed small amounts of data server , read command seems callback when has full 9 bytes read, not after writing, say, 4 bytes, expected. determines when callback occurs , why doesn't occur data available on socket?
the socket.async_read_some() operation has same completion conditions synchronous counterpart, socket.read_some() operation. operation considered complete when either:
- one or more bytes of data has been received successfully
- an error occurs prevent data being received
upon completion of operation (success or failure), readhandler posted io_service deferred invocation. @ point, readhandler may invoked thread servicing io_service.
when small amounts of data being written socket, such in problem description, 1 typically observes behavior of data not being sent until subsequent data written socket because of nagle's algorithm. in short, many systems attempt mitigate ip/tcp congestion concatenating small outbound messages single message sent. explicitly disable behavior on per-socket basis, set boost::asio::ip::tcp::no_delay option:
boost::asio::ip::tcp::socket socket(io_service); // ... boost::asio::ip::tcp::no_delay option(true); socket.set_option(option); when in doubt, monitor wire traffic packet analyzer, such wireshark or tcpdump, on both sender , receiver. 1 can use these tools @ identify whether problem on sending or receiving side. upon identifying offending side, 1 has dive kernel, driver, or hardware documentation identify configurations may source of problem.
Comments
Post a Comment