Is it possible to read how many bytes has buffered in a udp socket buffer in Linux using c++? unfortunately FIONREAD couldn't do that under linux.
Asked
Active
Viewed 720 times
2 Answers
1
Sort of. You can get the number of bytes available for the current datagram. When you call recvfrom
pass it the MSG_PEEK
flag. This will leave the datagram intact but allow you to look at the data and get how many bytes are available.
recvfrom(socket, buffer, size, MSG_PEEK, &address, &address_len);

Captain Obvlious
- 19,754
- 5
- 44
- 74
1
If you're using recv
or recvfrom
this would be accomplished by setting flags
to MSG_PEEK
.
If you are using another method of reading from sockets, let me know and I'll see what I can find.

fredrik
- 6,483
- 3
- 35
- 45