[erlang-patches] [PATCH] erts: fix error logic in efile_sendfile

Jovi Zhang <>
Tue Dec 6 07:51:53 CET 2011


>From 501b8f4ab78c752ff11a794984aad547b8717c5f Mon Sep 17 00:00:00 2001
From: Jovi Zhang <>
Date: Tue, 29 Nov 2011 02:11:01 +0800
Subject: [PATCH] erts: fix error logic in efile_sendfile

This commit fix two errors in efile_sendfile(linux env):
1) when *nbytes is 0, we should invoke sendfile with count *nbytes,
not SENDFILE_CHUNK_SIZE
2) "while (retval != -1 && retval == SENDFILE_CHUNK_SIZE)" is pointless,
  replace it by "while (retval == SENDFILE_CHUNK_SIZE)"
---
erts/emulator/drivers/unix/unix_efile.c |    4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/erts/emulator/drivers/unix/unix_efile.c
b/erts/emulator/drivers/unix/unix_efile.c
index eb2c5f5..fe0a0e2 100644
--- a/erts/emulator/drivers/unix/unix_efile.c
+++ b/erts/emulator/drivers/unix/unix_efile.c
@@ -1492,7 +1492,7 @@ efile_sendfile(Efile_error* errInfo, int in_fd,
int out_fd,
    ssize_t retval;
    do {
      // check if *nbytes is 0 or greater than the largest size_t
-      if (*nbytes == 0 || *nbytes > SENDFILE_CHUNK_SIZE)
+      if (*nbytes > SENDFILE_CHUNK_SIZE)
       retval = sendfile(out_fd, in_fd, offset, SENDFILE_CHUNK_SIZE);
      else
       retval = sendfile(out_fd, in_fd, offset, *nbytes);
@@ -1500,7 +1500,7 @@ efile_sendfile(Efile_error* errInfo, int in_fd,
int out_fd,
       written += retval;
       *nbytes -= retval;
      }
-    } while (retval != -1 && retval == SENDFILE_CHUNK_SIZE);
+    } while (retval == SENDFILE_CHUNK_SIZE);
    *nbytes = written;
    return check_error(retval == -1 ? -1 : 0, errInfo);
#elif defined(DARWIN)
--
1.7.2.3
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-erts-fix-error-logic-in-efile_sendfile.patch
Type: application/octet-stream
Size: 1577 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-patches/attachments/20111206/bcadb36b/attachment.obj>


More information about the erlang-patches mailing list