[issue10882] Add os.sendfile()

Ross Lagerwall report at bugs.python.org
Fri Jan 28 20:30:19 CET 2011


Ross Lagerwall <rosslagerwall at gmail.com> added the comment:

Attached is an updated patch that uses keyword arguments.

Using an offset with Linux was always supported although I have cleaned up the documentation a bit to make that clearer.
E.g. the following script sends part of a file over a socket (shows using an offset and None).
This requires listening with a socket on the same computer on port 8001 (e.g. nc -l 8001).

import os
import socket

with open("/tmp/test", "wb") as fp:
    fp.write(b"testdata\n" * 1000000)

cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
cli.connect(('localhost', 8010))
c = cli.fileno()
f = os.open("/tmp/test", os.O_RDONLY)

os.sendfile(c, f, 1, 7) # "estdata"
cli.send(b"\n\n")
os.sendfile(c, f, None, 4) # "test"
cli.send(b"\n\n")
os.sendfile(c, f, None, 4) # "data"
cli.send(b"\n\n")

----------
Added file: http://bugs.python.org/file20578/sendfile_v4.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10882>
_______________________________________


More information about the Python-bugs-list mailing list