Skip to content

Commit 4f4cf6a

Browse files
alexbrainmanianlancetaylor
authored andcommitted
[release-branch.go1.10] internal/poll: specify current file position when calling TransmitFile
Current SendFile implementation assumes that TransmitFile starts from the current file position. But that appears not true for Windows 10 Version 1803. TransmitFile documentation https://msdn.microsoft.com/en-us/library/windows/desktop/ms740565(v=vs.85).aspx suggests, "You can use the lpOverlapped parameter to specify a 64-bit offset within the file at which to start the file data transfer by setting the Offset and OffsetHigh member of the OVERLAPPED structure." Do as it advises. Fixes #25722 Change-Id: I241d3bf76d0d5590d4df27c6f922d637068232fb Reviewed-on: https://go-review.googlesource.com/117816 Run-TryBot: Alex Brainman <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> (cherry picked from commit af4d604) Reviewed-on: https://go-review.googlesource.com/c/146780 Run-TryBot: Ian Lance Taylor <[email protected]>
1 parent 30ccc62 commit 4f4cf6a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/internal/poll/sendfile_windows.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ func SendFile(fd *FD, src syscall.Handle, n int64) (int64, error) {
2525
o := &fd.wop
2626
o.qty = uint32(n)
2727
o.handle = src
28+
29+
// TODO(brainman): skip calling syscall.Seek if OS allows it
30+
curpos, err := syscall.Seek(o.handle, 0, 1)
31+
if err != nil {
32+
return 0, err
33+
}
34+
35+
o.o.OffsetHigh = uint32(curpos)
36+
o.o.Offset = uint32(curpos >> 32)
37+
2838
done, err := wsrv.ExecIO(o, func(o *operation) error {
2939
return syscall.TransmitFile(o.fd.Sysfd, o.handle, o.qty, 0, &o.o, nil, syscall.TF_WRITE_BEHIND)
3040
})

0 commit comments

Comments
 (0)