allows to enable/disable the use of sendfile()

fix #856
This commit is contained in:
benoitc 2014-10-19 10:56:29 +02:00
parent cfc6dc778e
commit 2849147f8a
2 changed files with 14 additions and 1 deletions

View File

@ -816,6 +816,16 @@ class PreloadApp(Setting):
restarting workers.
"""
class Sendfile(Setting):
name = "sendfile"
section = "Server Mechanics"
cli = ["--sendfile"]
validator = validate_bool
action = "store_true"
default = True
desc = """\
Enables or disables the use of sendfile().
"""
class Chdir(Setting):
name = "chdir"

View File

@ -344,6 +344,9 @@ class Response(object):
self.sent += tosend
util.write(self.sock, arg, self.chunked)
def can_sendfile(self):
return (self.cfg.sendfile and (sendfile is not None))
def sendfile_all(self, fileno, sockno, offset, nbytes):
# Send file in at most 1GB blocks as some operating
# systems can have problems with sending files in blocks
@ -380,7 +383,7 @@ class Response(object):
util.write(self.sock, data, self.chunked)
def write_file(self, respiter):
if sendfile is not None and util.is_fileobject(respiter.filelike):
if can_sendfile() and util.is_fileobject(respiter.filelike):
# sometimes the fileno isn't a callable
if six.callable(respiter.filelike.fileno):
fileno = respiter.filelike.fileno()