2

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.

Bryan Fok
  • 2,965
  • 2
  • 29
  • 55

2 Answers2

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
  • 18,863
  • 5
  • 39
  • 72
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,238
  • 3
  • 34
  • 42