سؤال

I have figured out that I must use ioctl. There are similar questions here:

My questions are:

  1. What is an equivalent to FIONREAD in Python? How do I call sock.ioctl() to obtain the amount of bytes available?
  2. What if I am using Python 2.5 on Windows? socket.ioctl is new in version 2.6.
هل كانت مفيدة؟

المحلول

As there is no portable way of doing this (and often the answer is wrong), there isn't a built-in way of asking for it.

If you use non-blocking sockets, simply read as much data as possible, and only data which is present will be returned.

نصائح أخرى

You could get that number, but the number is less than useful. There is a window of time between the kernel reads the number and your code gets to actually use it. In that window more data can arrive on the socket. In other words, this number is likely to be stale.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top