Skip to content

Commit

Permalink
net: update file read position after sendfile syscall
Browse files Browse the repository at this point in the history
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 <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
  • Loading branch information
tklauser authored and bradfitz committed Jun 12, 2018
1 parent 9ef9765 commit 29b631e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 0 additions & 6 deletions src/net/sendfile_test.go
Expand Up @@ -13,7 +13,6 @@ import (
"fmt"
"io"
"os"
"runtime"
"testing"
)

Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions src/net/sendfile_unix_alt.go
Expand Up @@ -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
}

0 comments on commit 29b631e

Please sign in to comment.