mirror of
https://github.com/golang/go
synced 2024-11-18 01:14:48 -07:00
net: ensure WriteTo on Windows sends even zero-byte payloads
Fixes #26668
This commit is contained in:
parent
c9cc20bd3a
commit
3bf2b8b46b
@ -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) {
|
|||||||
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user