]> Cypherpunks repositories - gostls13.git/commitdiff
net,os: consolidate poll.SendFile sending until EOF with 0
authorAndy Pan <i@andypan.me>
Wed, 30 Oct 2024 00:18:25 +0000 (08:18 +0800)
committerGopher Robot <gobot@golang.org>
Fri, 1 Nov 2024 01:09:12 +0000 (01:09 +0000)
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 <iant@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/net/sendfile_linux.go
src/os/zero_copy_linux.go
src/os/zero_copy_solaris.go

index f8a7bec8d38169715a622fb11cd72b4a06c75e29..75af6174165c29bf6bad0e9aad411fb94d2fd980 100644 (file)
@@ -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 {
index 0c9a8beb7ed2cf16008b1d7be35cdf39def44c3c..27a0882560ae2a75223e74088a5c5149679f98f9 100644 (file)
@@ -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
        })
 
index 7fc9ebdadaf876792181353986d0435111971790..94a8de6062cfdcb37e2784800a35a8d30908e871 100644 (file)
@@ -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