<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Mar 26, 2012, at 2:21 AM, hz hanks wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Hi, all<br><br>I'm writing a program to transfer files over Internet. Sometimes the<br>files would be very big. Therefore, I'm not sure whether I could read<br>a large block of data and send them via one time<br>internet.protocol.transport.write(). On the other hand, does the<br>function internet.protocol.transport.write() have any buffer scheme?<br>If so, I could just read one line of the file each time and call that<br>function. Or if you have any advice on how to transfer large amount of<br>data, please let me know. Really appreciated.<br></div></blockquote><br></div><div>First, you want to read this &lt;<a href="http://twistedmatrix.com/documents/current/core/howto/producers.html">http://twistedmatrix.com/documents/current/core/howto/producers.html</a>&gt;.</div><div><br></div><div>Second, you should understand that transport.write() will <i>always</i>&nbsp;buffer; it will never raise an error. &nbsp;The rationale for this behavior is that if you've already got the data as a Python string (as you must, if you're calling write() with it), you have already paid the not-inconsiderable cost of pulling that data into your process, allocating memory for it, and slinging it around in Python, which probably means you've already copied it a few times by splitting it up, moving it around, etc. &nbsp;The transport implementations will endeavor to not copy it around too much more (they generally keep a list of strings around as a buffer rather than a string they keep concatenating to), but they will hold on to it until they're able to write it.</div><div><br></div><div>If you want to know about the state of the buffer you need to subscribe to it using registerProducer() - so see the above document for how to do that.</div><div><br></div><div>-glyph</div><div><br></div></body></html>