From: "Michał Nazarewicz" <m.nazarewicz@samsung.com>
To: Randi Botse <nightdecoder@gmail.com>,
linux-c-programming@vger.kernel.org
Subject: Re: select() timeout question
Date: Wed, 25 Nov 2009 10:43:28 +0100 [thread overview]
Message-ID: <op.u3x2mqc07p4s8u@localhost> (raw)
In-Reply-To: <34e1241d0911250029g5e56e1cdxe7abfce03eb15836@mail.gmail.com>
On Wed, 25 Nov 2009 09:29:33 +0100, Randi Botse <nightdecoder@gmail.com> wrote:
> I'm now learning the Linux's select() system call,
>
> int select(int fd, fd_set *rset, fd_set *wset, fd_set *excepfs, struct
> timeval *timeout);
>
> I want to receive notification when the given file descriptor is ready
> to read, I use TCP socket connection to demonstrate this, one for the
> sender and other for the receiver, with normal condition, when the
> sender sends data via write(), the select() returns and tells the
> receiver there is data to read.
>
> My question is: what happens when the receiver's select() is reaching
> its timeout while the sender sends data? Should the notification and
> it's data be lost (discarded)?
Data read from a socket is buffered somewhere in kernel (and the same
goes for any other file descriptors). You may think of select(2) as
a way to check if there is any data ready in the buffer. If select(2)
reaches timeout before data is written to buffer you get 0 return value
(if I recall correctly) but the buffer is still there and if the data
is written into the buffer the next select(2) will notify about it.
In fact, you can use select(2) with a zero timeout (as opposed to
giving NULL as timeout argument) to check if there is data without
waiting for any.
--
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michał "mina86" Nazarewicz (o o)
ooo +---<mina86@mina86.com>---<mina86@jabber.org>---ooO--(_)--Ooo--
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2009-11-25 9:43 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-25 8:29 select() timeout question Randi Botse
[not found] ` <da5b0fda0911250038k4f6b87e7o3fd39e4c2db5ce86@mail.gmail.com>
2009-11-25 8:58 ` Randi Botse
2009-11-25 9:43 ` Michał Nazarewicz [this message]
2009-11-25 11:52 ` Randi Botse
2009-11-26 0:57 ` Helight.Xu
-- strict thread matches above, loose matches on Subject: below --
2009-11-28 5:43 Ardhan Madras
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=op.u3x2mqc07p4s8u@localhost \
--to=m.nazarewicz@samsung.com \
--cc=linux-c-programming@vger.kernel.org \
--cc=nightdecoder@gmail.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;
as well as URLs for NNTP newsgroup(s).