[Twisted-Python] Flush socket

Tobias Oberstein tobias.oberstein at tavendo.de
Thu Aug 11 17:06:04 EDT 2011

For testing implementations of a TCP-based protocol, I am testing
if an implementation is agnostic wrt to in what chops in receives
octets from the wire ("stream clean").

To do that, I force out octets from the protocol test driver (written
in Twisted) in differently sized chops, down to single octets.

Currently, I am using reactor.doSelect(0) after a transport.write()
to force out outstanding octets to wire.

I know this should not be done like this, but is there a clean and
supported way to do that?

   def syncSocket(self):

      ## FIXME: find suitable replacement for this code, which appears to
      ## sometimes ..
      ## From the web: "You should never call reactor.doSelect. This isn't
portable across
      ## reactors, and it could easily break the reactor by re-entering it
where it isn't
      ## expecting to be re-entered."
         return True
         return False # socket has already gone away ..

More information about the Twisted-Python mailing list