[Twisted-Python] UDP servers and socket queues
Tommi Virtanen
tv at twistedmatrix.com
Tue Apr 22 00:30:56 MDT 2003
On Mon, Apr 21, 2003 at 07:29:56PM +0100, Phil Mayers wrote:
> I figured something like that. Does anyone know if the various socket
> readiness abstractions (select(), poll(), kqueue, RT signals, etc.)
> given you sufficient information to know when you can do multiple reads?
Yes. All of them. If you want to empty the channel, read until
it would block. Same for writing..
> The other option I guess would be to for connection-less sockets to do:
>
> while 1:
> try:
> data, addr = self.socket.recvfrom(65535)
> self.protocol.datagramReceived(data, addr)
> except socket.error, se:
> if se.args[0]==errno.EWOULDBLOCK:
> break
> except:
> log.deferr()
>
> ...in doRead (line 91, twisted/internet/udp.py)?
It should do this already, in any case. It's a bug it doesn't.
select/poll/etc only give a hint that the fd might be
readable; the code must _always_ be prepared for the fact that
it might not be readable after all.
But your basic problem is trying to use UDP where it doesn't
work. Even if you find some sufficient delays that make the
system not lose packets in your specific case, changing any of
the variables (upgrading CPU, NICs, switches, OS, ...) can
make it fail again. You should use a protocol that doesn't
rely on luck, except maybe for optimization.
--
:(){ :|:&};:
More information about the Twisted-Python
mailing list