[asio-users] Question regarding asio::placeholders::bytes_transferred
Brought to you by:
chris_kohlhoff
From: Jay A. P. <jay...@ui...> - 2007-08-22 22:01:50
|
Hi, Let us jump directly to code first. Here are the relevant chunks of code: ----chunk #1---- udp_server->async_receive_from( asio::buffer(_inbound_udp_data, MAX_STR_LEN), _incoming_udp_remote_endpoint, boost::bind(&Transport::handle_udp_read, this, asio::placeholders::error, asio::placeholders::bytes_transferred)); Note: _inbound_udp_data is char[MAX_STR_LEN], udp_server is an active server socket. ----chunk #2---- void Transport::handle_udp_read(const asio::error& error, size_t bytes_recvd) { if (!error) { printf("gotten msg:[[%s]]\n", _inbound_udp_data); printf("msg str_size: %u; bytes_recvd: %u\n", strlen(_inbound_udp_data), bytes_recvd); } } -------------- The code was compiled and successfully run between two different hosts on the Internet (multiple hops away). However, when some messages are received, bytes_recvd < strlen(_inbound_udp_data). Shouldn't they be equal? The value of _inbound_udp_data and that of strlen(_inbound_udp_data) is correct. In other words, bytes_recvd is much smaller than it should be. A wild guess: Is this related to layer-2 fragmentation due to MTU? Does bytes_recvd get the value of the bytes read from the last network frame only? Note that the packet data is no longer than ~300 bytes. I'm a bit confused. Any pointers will be greatly appreciated. Exposing stupidity (on my part) will be an added bonus. Cheers, Jay. PS: Please CC me to reply. I do not monitor this mailing list yet. |