I want to receive data from an UDP socket asynchronously using Boost ASIO library. I don't want to use a fixed length buffer while receiving data using async_receive_from.
The following code is how I used boost asio::null_buffers to determine the incoming packet size and create buffer accordingly.
socket.async_receive_from(boost::asio::null_buffers(),
remote_endpoint,
[&](boost::system::error_code ec, std::size_t bytes) {
unsigned int readbytes = socket.available();
if (readbytes > buffer_size) {
//reallocate buffer
}
std::size_t recvbytes = socket.receive_from(
boost::asio::buffer(buffer, buffer_size), remote_endpoint, 0, error);
Everything works as expected, however, I want to know if boost null_buffer allocates an internal buffer to keep a copy of the UDP packet received and copies to the given buffer when socket.receive_from() is called.
Also I want to know what is the impact of using null_buffer on performance and memory usage while using a UDP socket.