<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Jan 25, 2013, at 12:04 PM, Guido van Rossum <<a href="mailto:guido@python.org">guido@python.org</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div class="gmail_quote">On Fri, Jan 25, 2013 at 10:11 AM, Nikolay Kim <span dir="ltr"><<a href="mailto:fafhrd91@gmail.com" target="_blank">fafhrd91@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><br><div><div><div class="h5"><div>On Jan 25, 2013, at 10:08 AM, Guido van Rossum <<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>> wrote:</div><br><blockquote type="cite">
On Fri, Jan 25, 2013 at 10:03 AM, Nikolay Kim <span dir="ltr"><<a href="mailto:fafhrd91@gmail.com" target="_blank">fafhrd91@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
I think Transport needs 'sendfile' api, something like:<br>
<br>
@tasks.coroutine<br>
def sendfile(self, fd, offset, nbytes):<br>
….<br>
<br>
otherwise it is impossible to implement sendfile without breaking transport encapsulation</blockquote><div> </div></div>Really? Can't the user write this themselves? What's wrong with this:<br><br>while True:<br>
data = os.read(fd, 16*1024)<br> if not data: break<br> transport.write(data)<br><br>(Perhaps augmented with a way to respond to pause() requests.)<br></blockquote><div><br></div></div></div><div><div>i mean 'os.sendfile()', zero-copy sendfile.</div>
</div></div></div></blockquote></div><br>I see (<a href="http://docs.python.org/dev/library/os.html#os.sendfile">http://docs.python.org/dev/library/os.html#os.sendfile</a>).<br><br>Hm, that function is so platform-specific that we might as well force users to do it this way:<br>
<br>sock = transport.get_extra_info("socket")<br>if sock is not None:<br> os.sendfile(sock.fileno(), ......)<br>else:<br> <use write() like I suggested above><br clear="all"></blockquote><div><br></div><div>there should some kind of way to flush write buffer or write callbacks. </div><div><br></div><div>sock = transport.get_extra_info("socket")</div><div>if sock is not None:</div><div> os.sendfile(sock.fileno(), ......)</div><div>else:</div><div> yield from transport.write_buffer_flush()</div><div> <use of write() method></div><div><br></div><div><br></div><div><br></div></div></body></html>