[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAApbN=K8j+XQG+pQF2fxBSrDEPcjD242e9uP72azD9XWBzHcGQ@mail.gmail.com>
Date: Wed, 13 Nov 2013 12:07:20 -0800
From: mpb <mpb.mail@...il.com>
To: netdev@...r.kernel.org
Subject: Fwd: Cross thread shutdown of connected UDP socket, unexpected
recvfrom behavior
Hi netdev@...r.kernel.org,
Someone on LKML suggested that I forward this issue to the netdev list.
In a nutshell, recvfrom returns ambiguous results, and it is
impossible to distinguish between these two situations:
a) calling recvfrom and receiving a zero length UDP message
b) calling recvfrom and blocking until the socket is shutdown (locally)
More details below.
Thanks!
-mpb
---------- Forwarded message ----------
From: mpb <mpb.mail@...il.com>
Date: Sat, Nov 9, 2013 at 5:32 PM
Subject: Cross thread shutdown of connected UDP socket, unexpected
recvfrom behavior
To: linux-kernel@...r.kernel.org
Hi LKML,
I have a C/pthreads program with two threads ("main" and "thread").
"thread" calls recvfrom on a connected UDP socket and blocks, waiting
for input. "main" then calls shutdown SHUT_RD on the socket. In
"thread", recvfrom returns, apparently successfully, returning a zero
length string, and setting src_addr to a bogus(?) address family,
port, and source address.
Is the above the correct behavior for recvfrom?
Here is output from my program. "main" sends "hello\0", then "" (the
empty string), then calls shutdown. "thread" receives "hello\0", "",
and then finally receives an empty string that was never sent!
thread recvfrom: Success
rv 6 addrlen 16 fam 2 port 8000 addr 100007f
thread recvfrom: Success
rv 0 addrlen 16 fam 2 port 8000 addr 100007f
main shutdown: Success
rv 0
thread recvfrom: Success
rv 0 addrlen 16 fam 59060 port 44237 addr deaadef0
The source code (2k) for the porgram is attached. I'm running Ubuntu
13.04, kernel 3.8.0-19-generic #30-Ubuntu, on 32-bit i686.
For reference, this June 2000 LKML thread discusses calling close in a
similar situation.
http://www.gossamer-threads.com/lists/linux/kernel/144379
Please CC me if you have questions, otherwise I'll try to watch for
answers in the list archives.
Thanks!
-mpb
View attachment "test.c" of type "text/x-csrc" (1861 bytes)
Powered by blists - more mailing lists