]> Cypherpunks repositories - gostls13.git/commit
io: correctly process result of sendfile(2) when src returns 0 bytes
authorDaulet Zhanguzin <daulet@zhanguzin.kz>
Wed, 6 Jul 2022 22:29:35 +0000 (22:29 +0000)
committerGopher Robot <gobot@golang.org>
Wed, 9 Nov 2022 03:01:33 +0000 (03:01 +0000)
commit27c38142756902c9a2e281ff1dd0f2e0a7273f75
tree164d5cb29580116e11889700a924c43d16d69085
parentf13849a7af4c058caa6af14f7d3f9aa81982c124
io: correctly process result of sendfile(2) when src returns 0 bytes

Fixes #53658. io.Copy() uses sendfile(2) to avoid allocating extra buffers when src is a file and dst is a TCPConn. However if src returns no bytes current logic treats it as failure and falls back to copying via user space. The following is a benchmark that illustrates the bug.

Benchmark: https://go.dev/play/p/zgZwpjUatSq

Before:
BenchmarkCopy-16          541006              2137 ns/op            4077 B/op          0 allocs/op

After:
BenchmarkCopy-16          490383              2365 ns/op             174 B/op          8 allocs/op

Change-Id: I703376d53b20e080c6204a73c96867cce16b24cf
GitHub-Last-Rev: 3a50be4f169683bf9caea32892c66619a66ad21a
GitHub-Pull-Request: golang/go#53659
Reviewed-on: https://go-review.googlesource.com/c/go/+/415834
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/internal/poll/sendfile_linux.go
src/net/sendfile_linux.go