Skip to content

Commit 9819ac5

Browse files
panjf2000gopherbot
authored andcommitted
os: employ sendfile(2) for file-to-file copying on SunOS when needed
Change-Id: Ia46de6c62707db9ef193fe1a2aabb18585f1dd48 Reviewed-on: https://go-review.googlesource.com/c/go/+/603098 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Andy Pan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Damien Neil <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]>
1 parent 0b4ab20 commit 9819ac5

10 files changed

+684
-445
lines changed

src/internal/poll/sendfile_solaris.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package poll
66

77
import "syscall"
88

9+
//go:cgo_ldflag "-lsendfile"
10+
911
// Not strictly needed, but very helpful for debugging, see issue #10221.
1012
//
1113
//go:cgo_import_dynamic _ _ "libsendfile.so"
@@ -37,8 +39,13 @@ func SendFile(dstFD *FD, src int, pos, remain int64) (written int64, err error,
3739
}
3840
pos1 := pos
3941
n, err = syscall.Sendfile(dst, src, &pos1, n)
40-
if err == syscall.EAGAIN || err == syscall.EINTR {
41-
// partial write may have occurred
42+
if err == syscall.EAGAIN || err == syscall.EINTR || err == syscall.EINVAL {
43+
// Partial write or other quirks may have occurred.
44+
//
45+
// For EINVAL, this is another quirk on SunOS: sendfile() claims to support
46+
// out_fd as a regular file but returns EINVAL when the out_fd is not a
47+
// socket of SOCK_STREAM, while it actually sends out data anyway and updates
48+
// the file offset.
4249
n = int(pos1 - pos)
4350
}
4451
if n > 0 {

src/net/cgo_solaris.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
package net
88

99
/*
10-
#cgo LDFLAGS: -lsocket -lnsl -lsendfile
10+
#cgo LDFLAGS: -lsocket -lnsl
1111
#include <netdb.h>
1212
*/
1313
import "C"

0 commit comments

Comments
 (0)