[Twisted-Python] Non-blocking UDP output?
Hi all, Today I read this line in "Unix Networking Programming". It seems that UDP output might be blocking. We also said in Section 2.11 that there is no actual UDP socket send buffer. The kernel just copies the application data and moves it down the stack, prepending the UDP and IP headers. Therefore, an output operation on a blocking UDP socket (the default) will not block for the same reason as a TCP socket, but it is possible for output operations to block on some systems due to the buffering and flow control that happens within the networking code in the kernel. But as far as I know, when I write "transport.write" in twisted code, it actually called "sendto" on the socket without using "select". Doesn't this conflict with the "non-blocking" philosophy of twisted?
On Mon, 17 Nov 2008 15:47:29 +0800, Peter Cai <newptcai@gmail.com> wrote:
Hi all,
Today I read this line in "Unix Networking Programming". It seems that UDP output might be blocking.
We also said in Section 2.11 that there is no actual UDP socket send buffer. The kernel just copies the application data and moves it down the stack, prepending the UDP and IP headers. Therefore, an output operation on a blocking UDP socket (the default) will not block for the same reason as a TCP socket, but it is possible for output operations to block on some systems due to the buffering and flow control that happens within the networking code in the kernel.
But as far as I know, when I write "transport.write" in twisted code, it actually called "sendto" on the socket without using "select".
Doesn't this conflict with the "non-blocking" philosophy of twisted?
The UDP socket is in non-blocking mode, so writing to it will not block. However, http://twistedmatrix.com/trac/ticket/3396 http://twistedmatrix.com/trac/ticket/3364 http://twistedmatrix.com/trac/ticket/2802 http://twistedmatrix.com/trac/ticket/2790 http://twistedmatrix.com/trac/ticket/2627 http://twistedmatrix.com/trac/ticket/2513 http://twistedmatrix.com/trac/ticket/2493 Jean-Paul
I know. But write to UDP socket might fail. And I didn't see any error handle code. Seems that twisted amuse that calling sendto on UDP would never fail. On Mon, Nov 17, 2008 at 10:46 PM, Jean-Paul Calderone <exarkun@divmod.com> wrote:
On Mon, 17 Nov 2008 15:47:29 +0800, Peter Cai <newptcai@gmail.com> wrote:
Hi all,
Today I read this line in "Unix Networking Programming". It seems that UDP output might be blocking.
We also said in Section 2.11 that there is no actual UDP socket send buffer. The kernel just copies the application data and moves it down the stack, prepending the UDP and IP headers. Therefore, an output operation on a blocking UDP socket (the default) will not block for the same reason as a TCP socket, but it is possible for output operations to block on some systems due to the buffering and flow control that happens within the networking code in the kernel.
But as far as I know, when I write "transport.write" in twisted code, it actually called "sendto" on the socket without using "select".
Doesn't this conflict with the "non-blocking" philosophy of twisted?
The UDP socket is in non-blocking mode, so writing to it will not block.
However,
http://twistedmatrix.com/trac/ticket/3396 http://twistedmatrix.com/trac/ticket/3364 http://twistedmatrix.com/trac/ticket/2802 http://twistedmatrix.com/trac/ticket/2790 http://twistedmatrix.com/trac/ticket/2627 http://twistedmatrix.com/trac/ticket/2513 http://twistedmatrix.com/trac/ticket/2493
Jean-Paul
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-- 而如何让自己的内心产生力量,在于自己而不在于别人。等到一跃而过,回头去看的时候,一个人因此获得了宝贵的经验和自信,下一次就可以面对更宽更深的壕沟。关键在于有多少意愿去面对这种犹豫时刻,因为大部分情况下,我们可以选择绕路的方法而回避这种艰难的选择。
Peter Cai wrote:
I know. But write to UDP socket might fail. And I didn't see any error handle code.
Here's the code in twisted/internet/udp.py that calls sendto: try: return self.socket.sendto(datagram, addr) except socket.error, se: # [snipped; a whole bunch of error handling]
Seems that twisted amuse that calling sendto on UDP would never fail.
I don't know why you think that Twisted assumes that, as the code clearly does expect to handle errors from sendto, including EINTR. -Andrew.
participants (3)
-
Andrew Bennetts -
Jean-Paul Calderone -
Peter Cai