...
1 package transport
2
3 import (
4 "syscall"
5 )
6
7 type Controls []func(network, addr string, conn syscall.RawConn) error
8
9 func (ctls Controls) Control(network, addr string, conn syscall.RawConn) error {
10 for _, s := range ctls {
11 if err := s(network, addr, conn); err != nil {
12 return err
13 }
14 }
15 return nil
16 }
17
18 type SocketOpts struct {
19
20
21
22
23
24 ReusePort bool `json:"reuse-port"`
25
26
27
28
29 ReuseAddress bool `json:"reuse-address"`
30 }
31
32 func getControls(sopts *SocketOpts) Controls {
33 ctls := Controls{}
34 if sopts.ReuseAddress {
35 ctls = append(ctls, setReuseAddress)
36 }
37 if sopts.ReusePort {
38 ctls = append(ctls, setReusePort)
39 }
40 return ctls
41 }
42
43 func (sopts *SocketOpts) Empty() bool {
44 return !sopts.ReuseAddress && !sopts.ReusePort
45 }
46
View as plain text