[Twisted-Python] AbstractDatagramProtocol implementation question
exarkun at twistedmatrix.com
exarkun at twistedmatrix.com
Sun Dec 6 14:38:46 EST 2009
On 3 Dec, 11:33 pm, olivier.parisy at free.fr wrote:
>I am studying the implementation of twisted UDP-related classes, and I
>do not understand the point of the "numPorts" attribute of
>AbstractDatagramProtocol.
>
>It is clearly designed to avoid multiple calls to startProtocol() from
>doStart(), but I fail in imagining a scenario where this may happen
>since, as the comment states, doStart() should only be called by
>makeConnection(), which has an explicit "assert self.transport == None"
>guard which, indeed, prevents multiple calls.
>
>So why bother to count calls?
>
>Moreover, makeConnection() could be called multiple times on the same
>DatagramProtocol instance if it was "bound" to multiple ports (multiple
>calls to listenUDP), which can be an interesting scenario but is
>prevented by :
>- the above assertion,
>- the fact that AbstractDatagramProtocol.transport is not a collection,
>so only the last Port would be available anyway.
>
>Is my reasoning wrong or incomplete? If not, couldn't we simplify
>AbstractDatagramProtocol implementation by removing numPorts?
This was probably a mindless copy/paste from the TCP implementation. I
don't see any reason not to deprecate and then remove the attribute.
>
>Two other small remarks regarding documentation / understandability :
>- The note "This does not actually implement IListeningPort" on
>udp.Port
>lead me to think that IReactorUDP.listenUDP should not be declared as
>returning an object implementing IListeningPort in the first place
>(confused me!).
This docstring seems to have been inherited from the base class, which
indeed does not implement IListeningPort. It would probably be nice if
udp.Port had its own docstring which was more reflective of udp.Port.
>- I had to read the code to understand that a "transport" and a "port"
>are exactly the same thing in the UDP implementation. The tutorial and
>the documentation were not clear about this point, so I did not make
>the
>link between the "self.transport" available in DatagramProtocol and the
>value returned by listenUDP (confused me!).
Would you like to file a ticket for the numPorts issue and another one
for these documentation issues? If you also attach a patch clarifying
things, it will probably be applied quite quickly.
Thank you very much for the feedback!
Jean-Paul
More information about the Twisted-Python
mailing list