From 196916299da7568a2a2165246e5164637df03fb9 Mon Sep 17 00:00:00 2001 From: Philipp Wollermann Date: Tue, 23 Apr 2024 17:18:20 +0900 Subject: 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 Reviewed-by: Damien Neil --- src/net/sendfile_unix_alt.go | 9 +++++++-- 1 file 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 } -- cgit v1.2.3-54-g00ecf