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