mpb added the comment: > It's just a patch to avoid returning garbage in the address.
Right, which is why I pursued the point. recvfrom should not return ambiguous data (the ambiguity being between shutdown and receiving a zero length message). It is now possible to distinguish the two by looking at the src_addr. (Arguably this could have been done before, but garbage in src_addr is not a reliable indicator, IMO.) > But AFAICT, recvfrom() returning 0 is enough to know that the socket > was shut down. My example code clearly shows a zero length UPD message being sent and received prior to shutdown. I admit, sending a zero length UDP message is probably pretty rare, but it is allowed and it does work. And it makes more sense than returning garbage in src_addr. > But two things to keep in mind: > - it'll only work on "connected" datagram sockets What will only work on connected datagram sockets? Shutdown *already* works (ie, wakes up blocked threads) on non-connected datagram sockets on Linux. Shutdown does wake them up (it just happens to return an error *after* waking them up). So... the only reason to connect the UDP socket (prior to calling shutdown) is to avoid the error (or, in Python, to avoid the raised Exception). > - even then, I'm not sure it's supported by POSIX: I can't think of > any spec specifying the behavior in case of cross-thread shutdown (and > close won't unblock for example). Also, I think HP-UX doesn't wake up > the waiting thread in that situation. Do you consider the POSIX specifications to be robust when it comes to threading? It would not surprise me if there are other threading related grey areas in POSIX. > So I'd still advise you to either use a timeout or a select(). My application only needs to run on Linux. If I cared about portability, I might well do something else. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue19530> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com