[Twisted-Python] Re: A question about ITransport.write()
Lian Cheng
rhythm.mail at gmail.com
Sun Dec 28 02:01:50 MST 2008
Thanks Andrew!
Andrew Bennetts 写道:
> Lian Cheng wrote:
>> Hi, all
>>
>> As a Twisted newbie, I read the Twisted documentation, and found that:
>>
>> 1. ITransport.write() doesn't return a deferred.
>> 2. IProtocol doesn't have a dataSent() callback or something alike.
>>
>> Since ITransport.write() is a non-blocking call, how can I be informed
>> when data sent by ITransport.write() is actually sent successfully?
>
> It depends on what exactly you mean by "successfully". Just because Twisted
> has delivered the bytes to the OS for delivery (e.g. via the send(2)
> syscall) doesn't mean they'll actually arrive at your intended destination.
>
> So,
>
> If you want to know if the bytes have arrived, get the remote side to send
> back an explicit ACK of some sort.
I was actually confused by the words written in the documentation:
If possible, make sure that it is all written. No data will ever be
lost, although (obviously) the connection may be closed before it all
gets through.
Seems here the documentation means that the connection may be closed due
to some fatal errors such as network cable unplugged rather than calling
ITransport.loseConnection().
>
> If you want to know when the send buffer[1] isn't full anymore, so that you
> can start working to fill it again, implement a pull producer
> <http://twistedmatrix.com/projects/core/documentation/howto/producers.html#auto4>
> and call the transport's registerProducer method with it.
Seems like what I'm looking for :-)
>
> If you want something else, reply and tell us what :)
Thanks a lot again :-)
>
> -Andrew.
>
> [1] “send buffer” is fairly loose terminology, but it'll do.
> Lian Cheng wrote:
>> Hi, all
>>
>> As a Twisted newbie, I read the Twisted documentation, and found that:
>>
>> 1. ITransport.write() doesn't return a deferred.
>> 2. IProtocol doesn't have a dataSent() callback or something alike.
>>
>> Since ITransport.write() is a non-blocking call, how can I be informed
>> when data sent by ITransport.write() is actually sent successfully?
>
> It depends on what exactly you mean by "successfully". Just because Twisted
> has delivered the bytes to the OS for delivery (e.g. via the send(2)
> syscall) doesn't mean they'll actually arrive at your intended destination.
>
> So,
>
> If you want to know if the bytes have arrived, get the remote side to send
> back an explicit ACK of some sort.
>
> If you want to know when the send buffer[1] isn't full anymore, so that you
> can start working to fill it again, implement a pull producer
> <http://twistedmatrix.com/projects/core/documentation/howto/producers.html#auto4>
> and call the transport's registerProducer method with it.
>
> If you want something else, reply and tell us what :)
>
> -Andrew.
>
> [1] “send buffer” is fairly loose terminology, but it'll do.
More information about the Twisted-Python
mailing list