* select() timeout question
@ 2009-11-25 8:29 Randi Botse
[not found] ` <da5b0fda0911250038k4f6b87e7o3fd39e4c2db5ce86@mail.gmail.com>
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Randi Botse @ 2009-11-25 8:29 UTC (permalink / raw)
To: linux-c-programming
Hi All,
Im now learning the Linux's select() system call,
#include <sys/select.h>
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 send data via write(), the select() returns and tell the
receiver there are data to read.
My question is: what happen when the receiver's select() is reaching
it's timeout while the sender send data? should the notification and
it's data lost (discarded)?
Based on my above experiment, select() never fail to notify although
it's in timeout state, and i awalys can read the data, i'm curious
with this, but i'm not sure if this always right.
Thanks before.
Randi,
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: select() timeout question
[not found] ` <da5b0fda0911250038k4f6b87e7o3fd39e4c2db5ce86@mail.gmail.com>
@ 2009-11-25 8:58 ` Randi Botse
0 siblings, 0 replies; 6+ messages in thread
From: Randi Botse @ 2009-11-25 8:58 UTC (permalink / raw)
To: Sam Liao, linux-c-programming
Hi Sam,
That's means the data is buffered right?, is it guaranteed?
- Randi
On Wed, Nov 25, 2009 at 3:38 AM, Sam Liao <phyomh@gmail.com> wrote:
> You will get the data for next select call.
>
> -Sam
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: select() timeout question
2009-11-25 8:29 select() timeout question Randi Botse
[not found] ` <da5b0fda0911250038k4f6b87e7o3fd39e4c2db5ce86@mail.gmail.com>
@ 2009-11-25 9:43 ` Michał Nazarewicz
2009-11-25 11:52 ` Randi Botse
2009-11-26 0:57 ` Helight.Xu
2 siblings, 1 reply; 6+ messages in thread
From: Michał Nazarewicz @ 2009-11-25 9:43 UTC (permalink / raw)
To: Randi Botse, linux-c-programming
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: select() timeout question
2009-11-25 9:43 ` Michał Nazarewicz
@ 2009-11-25 11:52 ` Randi Botse
0 siblings, 0 replies; 6+ messages in thread
From: Randi Botse @ 2009-11-25 11:52 UTC (permalink / raw)
To: linux-c-programming
Thanks all for your answers :)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: select() timeout question
2009-11-25 8:29 select() timeout question Randi Botse
[not found] ` <da5b0fda0911250038k4f6b87e7o3fd39e4c2db5ce86@mail.gmail.com>
2009-11-25 9:43 ` Michał Nazarewicz
@ 2009-11-26 0:57 ` Helight.Xu
2 siblings, 0 replies; 6+ messages in thread
From: Helight.Xu @ 2009-11-26 0:57 UTC (permalink / raw)
To: Randi Botse; +Cc: linux-c-programming
Randi Botse wrote:
> Hi All,
>
> Im now learning the Linux's select() system call,
>
> #include <sys/select.h>
>
> 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 send data via write(), the select() returns and tell the
> receiver there are data to read.
>
> My question is: what happen when the receiver's select() is reaching
> it's timeout while the sender send data? should the notification and
> it's data lost (discarded)?
>
NO! if timeout ,the data will stay in kernel, and select will notice you
when the select called again,
In fact , we always put select in while loop and set the timeout!
> Based on my above experiment, select() never fail to notify although
> it's in timeout state, and i awalys can read the data, i'm curious
> with this, but i'm not sure if this always right.
>
> Thanks before.
>
> Randi,
> --
> 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
>
>
--
---------------------------------
Zhenwen Xu - Open and Free
Home Page: http://zhwen.org
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: select() timeout question
@ 2009-11-28 5:43 Ardhan Madras
0 siblings, 0 replies; 6+ messages in thread
From: Ardhan Madras @ 2009-11-28 5:43 UTC (permalink / raw)
To: Randi Botse; +Cc: linux-c-programming
Hi Randi,
Basically the select syscall check the kernel buffer or in other words it just waiting to be notified by the kernel that there are pending data to read/write, it doesn't store any file-descriptor's related data.
- Ardhan
--- nightdecoder@gmail.com wrote:
From: Randi Botse <nightdecoder@gmail.com>
To: linux-c-programming@vger.kernel.org
Subject: select() timeout question
Date: Wed, 25 Nov 2009 03:29:33 -0500
Hi All,
Im now learning the Linux's select() system call,
#include <sys/select.h>
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 send data via write(), the select() returns and tell the
receiver there are data to read.
My question is: what happen when the receiver's select() is reaching
it's timeout while the sender send data? should the notification and
it's data lost (discarded)?
Based on my above experiment, select() never fail to notify although
it's in timeout state, and i awalys can read the data, i'm curious
with this, but i'm not sure if this always right.
Thanks before.
Randi,
--
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
_____________________________________________________________
Listen to KNAC, Hit the Home page and Tune In Live! ---> http://www.knac.com
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-11-28 5:43 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
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).