From 23ef7106aec96458fead784fd10fffa3e2c1b7be Mon Sep 17 00:00:00 2001 From: "wtc%netscape.com" Date: Sat, 20 May 2000 05:43:08 +0000 Subject: [PATCH] Bugzilla bug #34920: modified PR_EmulateSendFile so that it doesn't depend on the mmap alignment being a power of 2. git-svn-id: svn://10.0.0.236/trunk@70548 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/nsprpub/pr/src/io/priometh.c | 29 +++++++++------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/mozilla/nsprpub/pr/src/io/priometh.c b/mozilla/nsprpub/pr/src/io/priometh.c index 964061cf906..147e32e4ef8 100644 --- a/mozilla/nsprpub/pr/src/io/priometh.c +++ b/mozilla/nsprpub/pr/src/io/priometh.c @@ -352,31 +352,20 @@ PR_IMPLEMENT(PRInt32) PR_EmulateSendFile( file_bytes = info.size - sfd->file_offset; alignment = PR_GetMemMapAlignment(); + + /* number of initial bytes to skip in mmap'd segment */ + addr_offset = sfd->file_offset % alignment; + + /* find previous mmap alignment boundary */ + file_mmap_offset = sfd->file_offset - addr_offset; + /* * If the file is large, mmap and send the file in chunks so as * to not consume too much virtual address space */ - if (!sfd->file_offset || !(sfd->file_offset & (alignment - 1))) { - /* - * case 1: page-aligned file offset - */ - mmap_len = PR_MIN(file_bytes, SENDFILE_MMAP_CHUNK); - len = mmap_len; - file_mmap_offset = sfd->file_offset; - addr_offset = 0; - } else { - /* - * case 2: non page-aligned file offset - */ - /* find previous page boundary */ - file_mmap_offset = (sfd->file_offset & ~(alignment - 1)); + mmap_len = PR_MIN(file_bytes + addr_offset, SENDFILE_MMAP_CHUNK); + len = mmap_len - addr_offset; - /* number of initial bytes to skip in mmap'd segment */ - addr_offset = sfd->file_offset - file_mmap_offset; - PR_ASSERT(addr_offset > 0); - mmap_len = PR_MIN(file_bytes + addr_offset, SENDFILE_MMAP_CHUNK); - len = mmap_len - addr_offset; - } /* * Map in (part of) file. Take care of zero-length files. */