1
0
mirror of https://github.com/golang/go synced 2024-11-17 23:14:49 -07:00

net: ensure WriteTo on Windows sends even zero-byte payloads

Fixes #26668
This commit is contained in:
Jake B 2018-09-03 19:48:36 +10:00
parent c9cc20bd3a
commit 3bf2b8b46b
2 changed files with 7 additions and 8 deletions

View File

@ -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
}

View File

@ -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)
}
}