From: David Schwartz <davids@webmaster.com>
To: <mra@pobox.com>, <linux-kernel@vger.kernel.org>
Subject: Re: How to tell how much to expect from a fd
Date: Sat, 30 Mar 2002 19:03:13 -0800 [thread overview]
Message-ID: <20020331030314.AAA15293@shell.webmaster.com@whenever> (raw)
In-Reply-To: <m3663hjte0.fsf_-_@khem.blackfedora.com>
On 27 Mar 2002 18:52:39 -0800, Mark Atwood wrote:
>
>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?
It is possible that you are the one-in-a-million case that really needs
this, but the vast majority of the time people ask for this, they don't
really want it.
Consider two very important points:
First, by the time you get this information, it's obsolete. If more data
becomes available in-between when you make this call and when you attempt to
read, you'll take a double penalty. You'll need an extra 'read' later to get
the rest and your next poll/select will break out immediately (which can be
very expensive if you're dealing with a large number of fds).
Second, this would double the number of system calls you need to read the
data from the socket. There's almost no conceivable scenario in which it's
worth the cost of doing this when you can either keep a buffer that's a bit
too large around or copy it into a right-sized buffer and you can choose
which option after you know how many bytes you got.
DS
next prev parent reply other threads:[~2002-03-31 3:03 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-08-03 21:29 How does "alias ethX drivername" in modules.conf work? Mark Atwood
2001-08-04 1:21 ` Chris Wedgwood
2001-08-04 1:32 ` Thomas Duffy
2001-08-04 2:31 ` Chris Wedgwood
2001-08-04 4:39 ` Jim Roland
2001-08-04 19:35 ` Riley Williams
2001-08-06 19:59 ` Thomas Duffy
2001-08-06 22:56 ` Riley Williams
2001-08-06 23:46 ` Andrzej Krzysztofowicz
2001-08-07 7:04 ` Riley Williams
2001-08-07 10:49 ` Andrzej Krzysztofowicz
2001-08-07 19:04 ` Riley Williams
2001-08-07 21:46 ` Mark Atwood
2001-08-07 22:33 ` Tim Jansen
2001-08-07 23:06 ` Josh Wyatt
2001-08-07 23:35 ` Riley Williams
2001-08-08 0:04 ` Josh Wyatt
2001-08-08 6:28 ` Riley Williams
2001-08-08 10:59 ` Alan Cox
2001-08-08 0:08 ` Mark Atwood
2001-08-08 6:40 ` Riley Williams
2001-08-08 8:41 ` Andrzej Krzysztofowicz
2001-08-08 10:52 ` Eric W. Biederman
2001-08-08 11:40 ` Andrzej Krzysztofowicz
2001-08-08 22:04 ` Riley Williams
2001-08-08 21:09 ` Riley Williams
2001-08-08 0:11 ` Mark Atwood
2001-08-08 6:47 ` Riley Williams
2001-08-08 0:16 ` Mark Atwood
2001-08-08 20:26 ` Riley Williams
2001-08-08 9:30 ` Andrzej Krzysztofowicz
2001-08-08 21:31 ` Riley Williams
2001-08-08 21:42 ` Alan Cox
2001-08-08 22:24 ` Horst von Brand
[not found] ` <9kpub6$8fu$1@ns1.clouddancer.com>
2001-08-09 20:05 ` Colonel
2001-08-10 6:32 ` Paul Gortmaker
2001-08-10 21:25 ` Riley Williams
2001-08-15 4:32 ` Paul Gortmaker
2002-03-28 2:52 ` How to tell how much to expect from a fd Mark Atwood
2002-03-28 13:27 ` Eric Lammerts
2002-03-31 3:03 ` David Schwartz [this message]
2001-08-04 4:33 ` How does "alias ethX drivername" in modules.conf work? Jim Roland
2001-08-04 4:48 ` Jim Roland
[not found] ` <15SnZL-05h4nQC@fmrl06.sul.t-online.com>
2001-08-06 19:46 ` How to hack a network driver to use a specific ethX (was Re: How does "alias ethX drivername" in modules.conf work?) Mark Atwood
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20020331030314.AAA15293@shell.webmaster.com@whenever \
--to=davids@webmaster.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mra@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox