Skip to content

Commit 88ec1fb

Browse files
committed
src/net: sendfile: relax checks for os.File
1 parent cc9afa5 commit 88ec1fb

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/net/sendfile_linux.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package net
77
import (
88
"internal/poll"
99
"io"
10-
"os"
10+
"syscall"
1111
)
1212

1313
// sendFile copies the contents of r to c using the sendfile
@@ -27,7 +27,10 @@ func sendFile(c *netFD, r io.Reader) (written int64, err error, handled bool) {
2727
return 0, nil, true
2828
}
2929
}
30-
f, ok := r.(*os.File)
30+
f, ok := r.(interface {
31+
Fd() uintptr // not used, but limits the type to *os.File
32+
SyscallConn() (syscall.RawConn, error)
33+
})
3134
if !ok {
3235
return 0, nil, false
3336
}

src/net/sendfile_unix_alt.go

Lines changed: 8 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,12 @@ 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+
io.Seeker
40+
Fd() uintptr // not used, but limits the type to *os.File
41+
Stat() (fs.FileInfo, error)
42+
SyscallConn() (syscall.RawConn, error)
43+
})
3844
if !ok {
3945
return 0, nil, false
4046
}

src/net/sendfile_windows.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package net
77
import (
88
"internal/poll"
99
"io"
10-
"os"
1110
"syscall"
1211
)
1312

@@ -29,7 +28,9 @@ func sendFile(fd *netFD, r io.Reader) (written int64, err error, handled bool) {
2928
}
3029
}
3130

32-
f, ok := r.(*os.File)
31+
f, ok := r.(interface {
32+
Fd() uintptr
33+
})
3334
if !ok {
3435
return 0, nil, false
3536
}

0 commit comments

Comments
 (0)