How to tell how much to expect from a fd

Mark Atwood (mra@pobox.com)
27 Mar 2002 18:52:39 -0800


Does there exist a fcntl or some other way to tell how much data is
"ready to be read" from a fd?

I'm doing this thing where I make the fd non-blocking, select on it,
and then read on it into a buffer that I am pregrowing with realloc.

When the high water mark is up to the top of the buffer, I realloc the
buffer to make it bigger. At present, I'm just adding a constant
value to the buffer size each time I need to do this, but if there was
a way to easily tell how much was "ready to be read" from the fd.

It's not necessary to be exact. If more becomes available between the
time I do this wanted magic and do the read, read's 3rd parameter will
keep me safe, and if it's too low, like if a dup of the fd already
snarfed the data, also no big deal, I'm non-blocking and check the
return value.

So, is this "nice to have" available?

-- 
Mark Atwood   | Well done is better than well said.
mra@pobox.com | http://www.pobox.com/~mra
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/