1

I'm writing a TCP/IP server using the Twisted framework. I am sending a very large stream of data, in small chunks. So I need to know when the data I've sent has made it through Twisted's buffers and into the OS, and the OS is ready for some more data. Is there a way to be notified when this happens?

I am doing this to measure network throughput, so I'm generating an unlimited amount of data.

If I was using normal sockets (not Twisted), the answer would be to use poll() with POLLOUT for that, but I want to do this using Twisted.

Jon
  • 19
  • 6

2 Answers2

1

Yes.

self.transport.registerProducer(AProducer(), True), and then

from zope.interface import implementer
from twisted.internet.interfaces import IPushProducer
@implementer(IPushProducer)
class AProducer:
    def pauseProducing(self):
        "stop producing data; buffers are full"
    def resumeProducing(self):
        "resume producing data; buffers have space"

You can find more in the Twisted documentation for consumers and producers.

Glyph
  • 31,152
  • 11
  • 87
  • 129
1

There are so called push and pull producers. You need push producer, obviously :)

http://twistedmatrix.com/documents/13.1.0/core/howto/producers.html

monoid
  • 1,661
  • 11
  • 16