Skip to content

Commit

Permalink
[release-branch.go1.10] internal/poll: specify current file position …
Browse files Browse the repository at this point in the history
…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]>
  • Loading branch information
alexbrainman authored and ianlancetaylor committed Nov 1, 2018
1 parent 30ccc62 commit 4f4cf6a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/internal/poll/sendfile_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ func SendFile(fd *FD, src syscall.Handle, n int64) (int64, error) {
o := &fd.wop
o.qty = uint32(n)
o.handle = src

// TODO(brainman): skip calling syscall.Seek if OS allows it
curpos, err := syscall.Seek(o.handle, 0, 1)
if err != nil {
return 0, err
}

o.o.OffsetHigh = uint32(curpos)
o.o.Offset = 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)
})
Expand Down

0 comments on commit 4f4cf6a

Please sign in to comment.