Skip to content

Commit

Permalink
net: ensure WriteTo on Windows sends even zero-byte payloads
Browse files Browse the repository at this point in the history
This builds on:
#27445

"...And then send change to fix windows internal/poll.FD.WriteTo - together with making TestUDPZeroBytePayload run again."
- alexbrainman - #26668 (comment)

Fixes #26668

Change-Id: Icd9ecb07458f13e580b3e7163a5946ccec342509
GitHub-Last-Rev: 3bf2b8b
GitHub-Pull-Request: #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>
  • Loading branch information
silbinarywolf authored and alexbrainman committed Sep 6, 2018
1 parent 22afb35 commit 3e5b5d6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
3 changes: 0 additions & 3 deletions src/internal/poll/fd_windows.go
Expand Up @@ -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
}
Expand Down
12 changes: 7 additions & 5 deletions src/net/udpsock_test.go
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 3e5b5d6

Please sign in to comment.