mirror of
https://github.com/golang/go
synced 2024-11-18 00:04:43 -07:00
net: ensure WriteTo on Windows sends even zero-byte payloads
This builds on:
https://github.com/golang/go/pull/27445
"...And then send change to fix windows internal/poll.FD.WriteTo - together with making TestUDPZeroBytePayload run again."
- alexbrainman - https://github.com/golang/go/issues/26668#issuecomment-408657503
Fixes #26668
Change-Id: Icd9ecb07458f13e580b3e7163a5946ccec342509
GitHub-Last-Rev: 3bf2b8b46b
GitHub-Pull-Request: golang/go#27446
Reviewed-on: https://go-review.googlesource.com/132781
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
This commit is contained in:
parent
22afb3571c
commit
3e5b5d69dc
@ -761,9 +761,6 @@ func (fd *FD) Writev(buf *[][]byte) (int64, error) {
|
||||
|
||||
// WriteTo wraps the sendto network call.
|
||||
func (fd *FD) WriteTo(buf []byte, sa syscall.Sockaddr) (int, error) {
|
||||
if len(buf) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
if err := fd.writeLock(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
@ -357,13 +357,15 @@ func TestUDPZeroBytePayload(t *testing.T) {
|
||||
var b [1]byte
|
||||
if genericRead {
|
||||
_, err = c.(Conn).Read(b[:])
|
||||
// Read may timeout, it depends on the platform.
|
||||
if err != nil {
|
||||
if nerr, ok := err.(Error); !ok || !nerr.Timeout() {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_, _, err = c.ReadFrom(b[:])
|
||||
}
|
||||
switch err {
|
||||
case nil: // ReadFrom succeeds
|
||||
default: // Read may timeout, it depends on the platform
|
||||
if nerr, ok := err.(Error); !ok || !nerr.Timeout() {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user