Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Linux - Kernel This forum is for all discussion relating to the Linux kernel.


  Search this Thread
Old 06-25-2010, 02:17 AM   #1
LQ Newbie
Registered: Jun 2010
Location: beweth
Distribution: Ubuntu, RHEL, Monta Vista, QNX
Posts: 16

Rep: Reputation: 0
Clarification on how the I/O on a socket wakes up selec()

Hi All,

I have been working on a select driven program which deals with around 2k sockets. While debugging a program hung I've been observed that if a RST comes on the socket, it wakes up select() with both read_set and write_set set for that socket. And if I don't close the socket after a recv() there and re-call the select() on that socket it is waking up immediately after sleeping 0 secs. And this time onwards I'm seeing only read_set set.

I even looked at the kernel TCP code but couldn't find the answer on this. Any help is highly appreciated.

Thanks a lot in advance,
Old 06-25-2010, 02:35 PM   #2
Senior Member
Registered: Apr 2009
Posts: 1,496

Rep: Reputation: 136Reputation: 136
If the TCP session received RST flag in packet, TCP/IP stack will close the session. When recv() is called, the return value is less than 0, you have to close the TCP session.
Old 06-26-2010, 01:16 PM   #3
LQ Newbie
Registered: Jun 2010
Location: beweth
Distribution: Ubuntu, RHEL, Monta Vista, QNX
Posts: 16

Original Poster
Rep: Reputation: 0

Thanks for your reply. But I've figured out the answer myself from the code.

I'm putting here what ever I figured out thinking that it might help somebody someday.

When you call the select, it works internally by socket polling. where the poll() function checks for the sk->err and returns immediately from there, it wakes up select(). and interestingly the sk->err will be cleared after the first read itself. With the RST the err will be set to ECONNRESET or ECONNREFUSED based on the current state and the socket will be closed. Next time onwards when I call the select, the sk->err will be cleared but the socket state will be closed. Then also poll() returns and which makes the select() to wake up with only POLL_IN ie, read_set.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASUS K70IO wakes up immeditely after standby miniBill Linux - Laptop and Netbook 1 09-28-2009 07:17 AM
SIGIO sigaction wakes sleep up early bldrco Programming 2 07-09-2009 08:56 AM
LXer: Midnight Commander wakes from deep sleep LXer Syndicated Linux News 0 02-02-2009 12:50 PM
Who wakes up the hard drive? shturm Fedora 3 01-09-2007 10:34 PM
Standby/Sleep immediately wakes up again bsander Linux - Laptop and Netbook 2 05-07-2005 03:29 PM > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 05:52 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration