]> Cypherpunks repositories - gostls13.git/commitdiff
net: fix sendfile regression with io.Copy on macOS
authorPhilipp Wollermann <philwo@google.com>
Tue, 23 Apr 2024 08:18:20 +0000 (17:18 +0900)
committerDamien Neil <dneil@google.com>
Fri, 26 Apr 2024 17:08:30 +0000 (17:08 +0000)
Since CL 472475, io.Copy can no longer use sendfile on macOS for copying
files to a socket due to a too strict type assertion. This CL fixes the
issue by checking for the necessary interfaces instead of the concrete
os.File type in sendfile_unix_alt.go.

Fixes #66988

Change-Id: Ia0dd190f6575016a191c34a935132907147c8e10
Reviewed-on: https://go-review.googlesource.com/c/go/+/581035
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
src/net/sendfile_unix_alt.go

index 5cb65ee7670c49f6c4ae1bab2ca5cda209042156..5a10540f8af265007a605fb9a607f04563290894 100644 (file)
@@ -9,7 +9,8 @@ package net
 import (
        "internal/poll"
        "io"
-       "os"
+       "io/fs"
+       "syscall"
 )
 
 // sendFile copies the contents of r to c using the sendfile
@@ -34,7 +35,11 @@ func sendFile(c *netFD, r io.Reader) (written int64, err error, handled bool) {
                        return 0, nil, true
                }
        }
-       f, ok := r.(*os.File)
+       f, ok := r.(interface {
+               fs.File
+               io.Seeker
+               syscall.Conn
+       })
        if !ok {
                return 0, nil, false
        }