Get the number of bytes available in socket by 'recv' with 'MSG_PEEK' in C++

前端 未结 2 1865
小蘑菇
小蘑菇 2020-12-24 15:39

C++ has the following function to receive bytes from socket, it can check for number of bytes available with the MSG_PEEK flag. With MSG_PEEK, the

2条回答
  •  臣服心动
    2020-12-24 16:07

    On Windows, you can use the ioctlsocket() function with the FIONREAD flag to ask the socket how many bytes are available without needing to read/peek the actual bytes themselves. The value returned is the minimum number of bytes recv() can return without blocking. By the time you actually call recv(), more bytes may have arrived.

提交回复
热议问题