Skip to content

Commit 1969162

Browse files
philwoneild
authored andcommitted
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 <[email protected]> Reviewed-by: Damien Neil <[email protected]>
1 parent deeebf5 commit 1969162

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/net/sendfile_unix_alt.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ package net
99
import (
1010
"internal/poll"
1111
"io"
12-
"os"
12+
"io/fs"
13+
"syscall"
1314
)
1415

1516
// 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) {
3435
return 0, nil, true
3536
}
3637
}
37-
f, ok := r.(*os.File)
38+
f, ok := r.(interface {
39+
fs.File
40+
io.Seeker
41+
syscall.Conn
42+
})
3843
if !ok {
3944
return 0, nil, false
4045
}

0 commit comments

Comments
 (0)