Skip to content

Commit

Permalink
net: do not call Windows TransmitFile for large files
Browse files Browse the repository at this point in the history
TransmitFile does not allow for number of bytes that can be
transmitted to be larger than 2147483646. See

https://docs.microsoft.com/en-us/windows/win32/api/mswsock/nf-mswsock-transmitfile

for details. So adjust sendFile accordingly.

No test added, because this would require creating large file
(more than 2GB file).

Fixes #33193.

Change-Id: I82e0cb104d112264e4ea363bb20b6d02ac30b38e
Reviewed-on: https://go-review.googlesource.com/c/go/+/187037
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
  • Loading branch information
alexbrainman authored and odeke-em committed Aug 27, 2019
1 parent 997086b commit b963149
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/net/sendfile_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ func sendFile(fd *netFD, r io.Reader) (written int64, err error, handled bool) {
if n <= 0 {
return 0, nil, true
}
// TransmitFile can be invoked in one call with at most
// 2,147,483,646 bytes: the maximum value for a 32-bit integer minus 1.
// See https://docs.microsoft.com/en-us/windows/win32/api/mswsock/nf-mswsock-transmitfile
const maxSendBytes = 0x7fffffff - 1
if n > maxSendBytes {
return 0, nil, false
}
}
f, ok := r.(*os.File)
if !ok {
Expand Down

0 comments on commit b963149

Please sign in to comment.