diff options
author | Philipp Wollermann <philwo@google.com> | 2024-04-23 17:18:20 +0900 |
---|---|---|
committer | Damien Neil <dneil@google.com> | 2024-04-26 17:08:30 +0000 |
commit | 196916299da7568a2a2165246e5164637df03fb9 (patch) | |
tree | cfe0639f70af648cd34f2f07502f388d15f4efab | |
parent | deeebf5655eeb91e93e60dbda5c3df294b4d5130 (diff) | |
download | go-196916299da7568a2a2165246e5164637df03fb9.tar.gz go-196916299da7568a2a2165246e5164637df03fb9.zip |
net: fix sendfile regression with io.Copy on macOS
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>
-rw-r--r-- | src/net/sendfile_unix_alt.go | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/net/sendfile_unix_alt.go b/src/net/sendfile_unix_alt.go index 5cb65ee767..5a10540f8a 100644 --- a/src/net/sendfile_unix_alt.go +++ b/src/net/sendfile_unix_alt.go @@ -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 } |