select() on nonblocking sockets

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

 




Hi,

According to the manpage select() on a nonblocking socket returns
"readable" when a receive/read operation on the socket won't
block. I've noticed that select occasionally returns a socket
as "readable", but a following read() call will return EAGAIN.

I understand that this doesn't conflict with what the manpage
says, but I'm wondering why the socket is returned as readable
at all, when clearly there is nothing there to read yet?

Below is an strace of what's happening. I cannot tell from that
whether the read call got interrupted by SIGALRM, or whether
the alarm occured after read was done, but shouldn't read()
return EINTR if it was interrupted by a signal? The program is
single-threaded, so there are no other threads reading the data
before us.

 select(9, [0 3 4 5 6 7 8], [], NULL, NULL) = 1 (in [7])
 read(7, "m", 300)                      = 1
 select(9, [0 3 4 5 6 7 8], [], NULL, NULL) = 1 (in [7])
 read(7, "e", 299)                      = 1
 select(9, [0 3 4 5 6 7 8], [], NULL, NULL) = 1 (in [7])
 read(7, "d", 298)                      = 1
 select(9, [0 3 4 5 6 7 8], [], NULL, NULL) = 1 (in [7])
 read(7, 0x242827, 297)                  = -1 EAGAIN (Resource temporarily unavailable)
 --- SIGALRM (Alarm clock) ---
 sigreturn()                            = ? (mask now [])
 select(9, [0 3 4 5 6 7 8], [6], NULL, NULL) = 2 (in [7], out [6]) read(7, "i", 297) = 1
 select(9, [0 3 4 5 6 7 8], [], NULL, NULL) = 1 (in [7])
 read(7, "t", 296)                      = 1
 select(9, [0 3 4 5 6 7 8], [], NULL, NULL) = ? ERESTARTNOHAND (To be restarted)
 --- SIGALRM (Alarm clock) ---
 sigreturn()                            = ? (mask now [])

Can someone enlighten me?

-Udo.
-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.kernel.org


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux