From 29b631e6f4fb3729cf4b369bcf47316f0d426845 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 11 Jun 2018 14:41:58 +0200 Subject: [PATCH] net: update file read position after sendfile syscall On dragonfly, freebsd and solaris the sendfile syscall does not update the read position of the source fd. Update it after sendfile so successive calls start at the correct position. Fixes #25809 Change-Id: Iaac79f89704b75b8038d4bb60eaf793a262cdd8f Reviewed-on: https://go-review.googlesource.com/117895 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/net/sendfile_test.go | 6 ------ src/net/sendfile_unix_alt.go | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/net/sendfile_test.go b/src/net/sendfile_test.go index acf1cd9955378..ecc00d3c2a0ca 100644 --- a/src/net/sendfile_test.go +++ b/src/net/sendfile_test.go @@ -13,7 +13,6 @@ import ( "fmt" "io" "os" - "runtime" "testing" ) @@ -94,11 +93,6 @@ func TestSendfile(t *testing.T) { } func TestSendfileParts(t *testing.T) { - switch runtime.GOOS { - case "dragonfly", "freebsd", "solaris": - t.Skipf("skipping on %s (see golang.org/issue/25809 for details)", runtime.GOOS) - } - ln, err := newLocalListener("tcp") if err != nil { t.Fatal(err) diff --git a/src/net/sendfile_unix_alt.go b/src/net/sendfile_unix_alt.go index 97aeebbed2139..9b3ba4ee624a3 100644 --- a/src/net/sendfile_unix_alt.go +++ b/src/net/sendfile_unix_alt.go @@ -63,5 +63,11 @@ func sendFile(c *netFD, r io.Reader) (written int64, err error, handled bool) { if lr != nil { lr.N = remain - written } + + _, err1 := f.Seek(written, io.SeekCurrent) + if err1 != nil && err == nil { + return written, err1, written > 0 + } + return written, wrapSyscallError("sendfile", err), written > 0 }