Commit 3e5b5d69 authored by Jake B's avatar Jake B Committed by Alex Brainman

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: 3bf2b8b46bb8cf79903930631433a1f2ce50ec42
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: default avatarAlex Brainman <alex.brainman@gmail.com>
parent 22afb357
...@@ -761,9 +761,6 @@ func (fd *FD) Writev(buf *[][]byte) (int64, error) { ...@@ -761,9 +761,6 @@ func (fd *FD) Writev(buf *[][]byte) (int64, error) {
// WriteTo wraps the sendto network call. // WriteTo wraps the sendto network call.
func (fd *FD) WriteTo(buf []byte, sa syscall.Sockaddr) (int, error) { func (fd *FD) WriteTo(buf []byte, sa syscall.Sockaddr) (int, error) {
if len(buf) == 0 {
return 0, nil
}
if err := fd.writeLock(); err != nil { if err := fd.writeLock(); err != nil {
return 0, err return 0, err
} }
......
...@@ -357,13 +357,15 @@ func TestUDPZeroBytePayload(t *testing.T) { ...@@ -357,13 +357,15 @@ func TestUDPZeroBytePayload(t *testing.T) {
var b [1]byte var b [1]byte
if genericRead { if genericRead {
_, err = c.(Conn).Read(b[:]) _, 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 { } else {
_, _, err = c.ReadFrom(b[:]) _, _, err = c.ReadFrom(b[:])
} if err != nil {
switch err {
case nil: // ReadFrom succeeds
default: // Read may timeout, it depends on the platform
if nerr, ok := err.(Error); !ok || !nerr.Timeout() {
t.Fatal(err) t.Fatal(err)
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment