
"Igor R"
wrote in message news:cfe0a3cf0901221545q4927fa9n8078396308cb850d@mail.gmail.com... char m_buf[10]; udp::endpoint m_endpoint; <--> udpSocket.async_receive_from(buffer(buf), m_endpoint, bind(ReadHandler, ...)); service.run();
If more than 10 characters were in the datagram packet, how can they be accessed? Calling other read methods (after processing in the ReadHandler) just appears to block (I guess it is looking for another >>packet).
In the ReadHandler you can synchronously read the remained data , like this (untested!): size_t avail = udpSocket.available(); std::vector<char> data(avail); udpSocket.read(buffer(data));
I had originally tried this, which is why I mentioned that calling other read methods blocked. The "available" method returns 0, which is consistent with the block. (Also, there is no "read" method, only _receive_ methods.) I am using asio on the Windows platform, so I examined the code and ultimately it routes to the WSARecv SDK function. The MSDN documentation provided with MSVC7.1 (VS 2003) says that any datagram data that overflows the buffer is thrown away. The latest MSDN documentation suggests that the MSG_PARTIAL feature must be supported in order to acquire the data that overflows; I did a quick scan of asio to see if this was ever used, but didn't notice it. It seems that providing a buffer large enough for the data I expect to deal with is the most reliable approach.