summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorTim Prouty <tprouty@samba.org>2009-02-20 13:28:36 -0800
committerTim Prouty <tprouty@samba.org>2009-02-21 15:42:37 -0800
commit0dcfa9ce1baa9f2074a002fdb5c8b88cc5db28db (patch)
tree182e177759cb3f611f50b44799dfc21e9ecd53bd /source3
parent1ff9696306894c136015f83456e4c6e039e31e26 (diff)
downloadsamba-0dcfa9ce1baa9f2074a002fdb5c8b88cc5db28db.tar.gz
samba-0dcfa9ce1baa9f2074a002fdb5c8b88cc5db28db.tar.bz2
samba-0dcfa9ce1baa9f2074a002fdb5c8b88cc5db28db.zip
s3: If sendfile returns 0 bytes read, fall back to the normal read path
This allows sendfile implementations that are atomic to avoid having to send zeros or kill the client connection on a short read (usually the file was truncated).
Diffstat (limited to 'source3')
-rw-r--r--source3/smbd/reply.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index 457f9412a9..b30ef23c0e 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -2788,6 +2788,18 @@ static void send_file_readbraw(connection_struct *conn,
DEBUG(0,("send_file_readbraw: sendfile failed for file %s (%s). Terminating\n",
fsp->fsp_name, strerror(errno) ));
exit_server_cleanly("send_file_readbraw sendfile failed");
+ } else if (sendfile_read == 0) {
+ /*
+ * Some sendfile implementations return 0 to indicate
+ * that there was a short read, but nothing was
+ * actually written to the socket. In this case,
+ * fallback to the normal read path so the header gets
+ * the correct byte count.
+ */
+ DEBUG(3, ("send_file_readbraw: sendfile sent zero "
+ "bytes falling back to the normal read: "
+ "%s\n", fsp->fsp_name));
+ goto normal_readbraw;
}
/* Deal with possible short send. */
@@ -3284,6 +3296,18 @@ static void send_file_readX(connection_struct *conn, struct smb_request *req,
DEBUG(0,("send_file_readX: sendfile failed for file %s (%s). Terminating\n",
fsp->fsp_name, strerror(errno) ));
exit_server_cleanly("send_file_readX sendfile failed");
+ } else if (nread == 0) {
+ /*
+ * Some sendfile implementations return 0 to indicate
+ * that there was a short read, but nothing was
+ * actually written to the socket. In this case,
+ * fallback to the normal read path so the header gets
+ * the correct byte count.
+ */
+ DEBUG(3, ("send_file_readX: sendfile sent zero bytes "
+ "falling back to the normal read: %s\n",
+ fsp->fsp_name));
+ goto normal_read;
}
DEBUG( 3, ( "send_file_readX: sendfile fnum=%d max=%d nread=%d\n",