github.com/hlts2/go@v0.0.0-20170904000733-812b34efaed8/src/net/rawconn_windows_test.go (about) 1 // Copyright 2017 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package net 6 7 import ( 8 "syscall" 9 "testing" 10 ) 11 12 func TestRawConn(t *testing.T) { 13 c, err := newLocalPacketListener("udp") 14 if err != nil { 15 t.Fatal(err) 16 } 17 defer c.Close() 18 cc, err := c.(*UDPConn).SyscallConn() 19 if err != nil { 20 t.Fatal(err) 21 } 22 23 var operr error 24 fn := func(s uintptr) { 25 operr = syscall.SetsockoptInt(syscall.Handle(s), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1) 26 } 27 err = cc.Control(fn) 28 if err != nil || operr != nil { 29 t.Fatal(err, operr) 30 } 31 c.Close() 32 err = cc.Control(fn) 33 if err == nil { 34 t.Fatal("should fail") 35 } 36 }