Commit 3114bd6f authored by Ron Hashimoto's avatar Ron Hashimoto Committed by Alex Brainman

net: disable SIO_UDP_CONNRESET behavior on windows.

Fixes #5834.

LGTM=alex.brainman
R=golang-codereviews, bradfitz, alex.brainman, mikioh.mikioh, in60jp, iant
CC=golang-codereviews
https://golang.org/cl/149510043
parent 7abc8c4a
......@@ -294,6 +294,18 @@ func (fd *netFD) init() error {
fd.skipSyncNotif = true
}
}
// Disable SIO_UDP_CONNRESET behavior.
// http://support.microsoft.com/kb/263823
switch fd.net {
case "udp", "udp4", "udp6":
ret := uint32(0)
flag := uint32(0)
size := uint32(unsafe.Sizeof(flag))
err := syscall.WSAIoctl(fd.sysfd, syscall.SIO_UDP_CONNRESET, (*byte)(unsafe.Pointer(&flag)), size, nil, 0, &ret, nil, 0)
if err != nil {
return os.NewSyscallError("WSAIoctl", err)
}
}
fd.rop.mode = 'r'
fd.wop.mode = 'w'
fd.rop.fd = fd
......
......@@ -9,6 +9,7 @@ import (
"runtime"
"strings"
"testing"
"time"
)
func TestResolveUDPAddr(t *testing.T) {
......@@ -34,6 +35,41 @@ func TestResolveUDPAddr(t *testing.T) {
}
}
func TestReadFromUDP(t *testing.T) {
ra, err := ResolveUDPAddr("udp", "127.0.0.1:7")
if err != nil {
t.Fatal(err)
}
la, err := ResolveUDPAddr("udp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
c, err := ListenUDP("udp", la)
if err != nil {
t.Fatal(err)
}
defer c.Close()
_, err = c.WriteToUDP([]byte("a"), ra)
if err != nil {
t.Fatal(err)
}
err = c.SetDeadline(time.Now().Add(100 * time.Millisecond))
if err != nil {
t.Fatal(err)
}
b := make([]byte, 1)
_, _, err = c.ReadFromUDP(b)
if err == nil {
t.Fatal("ReadFromUDP should fail")
} else if !isTimeout(err) {
t.Fatal(err)
}
}
func TestWriteToUDP(t *testing.T) {
switch runtime.GOOS {
case "plan9":
......
......@@ -547,6 +547,7 @@ const (
IOC_WS2 = 0x08000000
SIO_GET_EXTENSION_FUNCTION_POINTER = IOC_INOUT | IOC_WS2 | 6
SIO_KEEPALIVE_VALS = IOC_IN | IOC_VENDOR | 4
SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12
// cf. http://support.microsoft.com/default.aspx?scid=kb;en-us;257460
......
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