Re: select() timeout question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 25 Nov 2009 09:29:33 +0100, Randi Botse <nightdecoder@xxxxxxxxx> 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@xxxxxxxxxx>---<mina86@xxxxxxxxxx>---ooO--(_)--Ooo--

--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux