* read returns EAGAIN on a _blocking_ socket, but should not?
@ 2005-12-25 15:16 Marc Lehmann
2005-12-25 16:17 ` read returns EAGAIN on a _blocking_ socket, but should not? (solved) Marc Lehmann
0 siblings, 1 reply; 2+ messages in thread
From: Marc Lehmann @ 2005-12-25 15:16 UTC (permalink / raw)
To: linux-kernel
Hi!
The SuS documents EAGAIN for read(2) as:
[EAGAIN]
The O_NONBLOCK flag is set for the file descriptor and the thread would
be delayed.
And the linux manpage for read(2) says something similar. Yet, I do get
EAGAIN when reading from a blocking socket. Here is a short strace:
socket(PF_FILE, SOCK_STREAM, 0) = 3
connect(3, {sa_family=AF_FILE, path="/serv"}, 110) = 0
write(3, "\0\3", 2) = 2
write(3, "NEW", 3) = 3
... many writes and reads omitted
sendmsg(3, {msg_name(0)=NULL, msg_iov(1)=[{"\0", 1}], msg_controllen=20, {cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, {3}}, msg_flags=MSG_OOB|MSG_DONTROUTE}, 0) = 1
read(3, "\0\3", 2) = 2
read(3, 0x51d030, 3) = -1 EAGAIN (Resource temporarily unavailable)
write(2, "protocol error: unexpected eof f"..., 44) = 44
(the sendmsg call in the source, incidentally, specifies "0" as flags
argument, not MSG_OOB|MSG_DONTROUTE, but this is likely irrelevant).
Here is the server side for the last exchange above:
recvmsg(9, {msg_name(0)=NULL, msg_iov(1)=[{"\0", 1}], msg_controllen=24, {cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, {10}}, msg_flags=0}, 0) = 1
... ioctls on other fds omitted
write(9, "\0\3", 2) = 2
write(9, "END", 3) = 3
Now, the first backtrace creates a unix domain socket, connects to an
existing one, passes a file descriptor and then read() returns with
EAGAIN. Nowhere does it set the socket to blocking.
The full backtraces can be found as http://data.plan9.de/x.20407 (client
getting EAGAIN) and at http://data.plan9.de/x.20406 (server writing).
I am looking for the obvious logical error I made, but I can only
come up with the conclusion that read returning EAGAIN on a blocking
socket must be a kernel bug. It is also interesting that this code and
the server/client exchanges worked reliably _until_ I started to pass
filehandles from client to server.
I am using linux 2.6.14 on x86_64.
Thanks for your time and any insights you can give!
--
The choice of a
-----==- _GNU_
----==-- _ generation Marc Lehmann
---==---(_)__ __ ____ __ pcg@goof.com
--==---/ / _ \/ // /\ \/ / http://schmorp.de/
-=====/_/_//_/\_,_/ /_/\_\ XX11-RIPE
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: read returns EAGAIN on a _blocking_ socket, but should not? (solved)
2005-12-25 15:16 read returns EAGAIN on a _blocking_ socket, but should not? Marc Lehmann
@ 2005-12-25 16:17 ` Marc Lehmann
0 siblings, 0 replies; 2+ messages in thread
From: Marc Lehmann @ 2005-12-25 16:17 UTC (permalink / raw)
To: linux-kernel
On Sun, Dec 25, 2005 at 04:16:11PM +0100, Marc Lehmann <schmorp@schmorp.de> wrote:
> Hi!
>
> The SuS documents EAGAIN for read(2) as:
Argl, false alarm, very very sorry :(
> sendmsg(3, {msg_name(0)=NULL, msg_iov(1)=[{"\0", 1}], msg_controllen=20, {cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, {3}}, msg_flags=MSG_OOB|MSG_DONTROUTE}, 0) = 1
Due to a bug, this sendmsg call passes the wrong fd (3), which the other
process then sets to non-blocking.
Again, sorry :(
--
The choice of a
-----==- _GNU_
----==-- _ generation Marc Lehmann
---==---(_)__ __ ____ __ pcg@goof.com
--==---/ / _ \/ // /\ \/ / http://schmorp.de/
-=====/_/_//_/\_,_/ /_/\_\ XX11-RIPE
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-12-25 16:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-25 15:16 read returns EAGAIN on a _blocking_ socket, but should not? Marc Lehmann
2005-12-25 16:17 ` read returns EAGAIN on a _blocking_ socket, but should not? (solved) Marc Lehmann
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.