mirror of https://github.com/golang/go.git
[release-branch.go1.10] internal/poll, net: fix sendfile on Windows, add test
Cherry pick of CL 130855, done manually to avoid a merge conflict on the test. Fixes #27085 Change-Id: I7c4939cf5db23253a824c46c3f00fab4edec86b4 Reviewed-on: https://go-review.googlesource.com/c/146797 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
7495cdaf3d
commit
fba2c4d76b
|
|
@ -32,8 +32,8 @@ func SendFile(fd *FD, src syscall.Handle, n int64) (int64, error) {
|
|||
return 0, err
|
||||
}
|
||||
|
||||
o.o.OffsetHigh = uint32(curpos)
|
||||
o.o.Offset = uint32(curpos >> 32)
|
||||
o.o.Offset = uint32(curpos)
|
||||
o.o.OffsetHigh = uint32(curpos >> 32)
|
||||
|
||||
done, err := wsrv.ExecIO(o, func(o *operation) error {
|
||||
return syscall.TransmitFile(o.fd.Sysfd, o.handle, o.qty, 0, &o.o, nil, syscall.TF_WRITE_BEHIND)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
package net
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
|
|
@ -88,3 +89,64 @@ func TestSendfile(t *testing.T) {
|
|||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendfileSeeked(t *testing.T) {
|
||||
ln, err := newLocalListener("tcp")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer ln.Close()
|
||||
|
||||
const seekTo = 65 << 10
|
||||
const sendSize = 10 << 10
|
||||
|
||||
errc := make(chan error, 1)
|
||||
go func(ln Listener) {
|
||||
// Wait for a connection.
|
||||
conn, err := ln.Accept()
|
||||
if err != nil {
|
||||
errc <- err
|
||||
close(errc)
|
||||
return
|
||||
}
|
||||
|
||||
go func() {
|
||||
defer close(errc)
|
||||
defer conn.Close()
|
||||
|
||||
f, err := os.Open(twain)
|
||||
if err != nil {
|
||||
errc <- err
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
if _, err := f.Seek(seekTo, os.SEEK_SET); err != nil {
|
||||
errc <- err
|
||||
return
|
||||
}
|
||||
|
||||
_, err = io.CopyN(conn, f, sendSize)
|
||||
if err != nil {
|
||||
errc <- err
|
||||
return
|
||||
}
|
||||
}()
|
||||
}(ln)
|
||||
|
||||
c, err := Dial("tcp", ln.Addr().String())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
buf.ReadFrom(c)
|
||||
|
||||
if buf.Len() != sendSize {
|
||||
t.Errorf("Got %d bytes; want %d", buf.Len(), sendSize)
|
||||
}
|
||||
|
||||
for err := range errc {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue