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>
diff --git a/src/net/sendfile_unix_alt.go b/src/net/sendfile_unix_alt.go
index 5cb65ee..5a10540 100644
--- a/src/net/sendfile_unix_alt.go
+++ b/src/net/sendfile_unix_alt.go
@@ -9,7 +9,8 @@
import (
"internal/poll"
"io"
- "os"
+ "io/fs"
+ "syscall"
)
// sendFile copies the contents of r to c using the sendfile
@@ -34,7 +35,11 @@
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
}