From a69fffbaf864ad88f9f7472960e39e2a03c1ff5f Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Wed, 30 Oct 2024 08:18:25 +0800 Subject: [PATCH] net,os: consolidate poll.SendFile sending until EOF with 0 We've already use size==0 to indicate sending until EOF for poll.SendFile on non-Linux platforms: Windows/*BSD/macOS/Solaris. Let's harmonize Linux with others, making poll.SendFile on Linux match its comment. Change-Id: Ibfe9c9aa8f16bc37812afce9f95995c715cce0bb Reviewed-on: https://go-review.googlesource.com/c/go/+/623057 Reviewed-by: Ian Lance Taylor Reviewed-by: Damien Neil Auto-Submit: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI --- src/net/sendfile_linux.go | 2 +- src/os/zero_copy_linux.go | 2 +- src/os/zero_copy_solaris.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/net/sendfile_linux.go b/src/net/sendfile_linux.go index f8a7bec8d3..75af617416 100644 --- a/src/net/sendfile_linux.go +++ b/src/net/sendfile_linux.go @@ -20,7 +20,7 @@ const supportsSendfile = true // // if handled == false, sendFile performed no work. func sendFile(c *netFD, r io.Reader) (written int64, err error, handled bool) { - var remain int64 = 1<<63 - 1 // by default, copy until EOF + var remain int64 = 0 // 0 indicates sending until EOF lr, ok := r.(*io.LimitedReader) if ok { diff --git a/src/os/zero_copy_linux.go b/src/os/zero_copy_linux.go index 0c9a8beb7e..27a0882560 100644 --- a/src/os/zero_copy_linux.go +++ b/src/os/zero_copy_linux.go @@ -28,7 +28,7 @@ func (f *File) writeTo(w io.Writer) (written int64, handled bool, err error) { } rerr := sc.Read(func(fd uintptr) (done bool) { - written, err, handled = poll.SendFile(pfd, int(fd), 1<<63-1) + written, err, handled = poll.SendFile(pfd, int(fd), 0) return true }) diff --git a/src/os/zero_copy_solaris.go b/src/os/zero_copy_solaris.go index 7fc9ebdada..94a8de6062 100644 --- a/src/os/zero_copy_solaris.go +++ b/src/os/zero_copy_solaris.go @@ -17,7 +17,7 @@ func (f *File) writeTo(w io.Writer) (written int64, handled bool, err error) { // readFrom is basically a refactor of net.sendFile, but adapted to work for the target of *File. func (f *File) readFrom(r io.Reader) (written int64, handled bool, err error) { - var remain int64 = 0 + var remain int64 = 0 // 0 indicates sending until EOF lr, ok := r.(*io.LimitedReader) if ok { remain, r = lr.N, lr.R