Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 // Copyright 2011 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 // +build darwin freebsd netbsd openbsd | |
6 | |
7 // Socket options for BSD variants | |
8 | |
9 package net | 1 package net |
10 | 2 |
11 import ( | 3 import ( |
12 "syscall" | 4 "syscall" |
13 ) | 5 ) |
14 | 6 |
15 func setDefaultSockopts(s, f, t int) { | 7 func setDefaultSockopts(s, f, t int) { |
16 switch f { | 8 switch f { |
17 case syscall.AF_INET6: | 9 case syscall.AF_INET6: |
18 // Allow both IP versions even if the OS default is otherwise. | 10 // Allow both IP versions even if the OS default is otherwise. |
19 syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.IPV6_V6ON LY, 0) | 11 syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.IPV6_V6ON LY, 0) |
20 } | 12 } |
21 | 13 |
22 if f == syscall.AF_UNIX || | 14 if f == syscall.AF_UNIX || |
23 (f == syscall.AF_INET || f == syscall.AF_INET6) && t == syscall. SOCK_STREAM { | 15 (f == syscall.AF_INET || f == syscall.AF_INET6) && t == syscall. SOCK_STREAM { |
24 // Allow reuse of recently-used addresses. | 16 // Allow reuse of recently-used addresses. |
25 syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADD R, 1) | 17 syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADD R, 1) |
26 | 18 |
27 // Allow reuse of recently-used ports. | 19 // Allow reuse of recently-used ports. |
28 // This option is supported only in descendants of 4.4BSD, | 20 // This option is supported only in descendants of 4.4BSD, |
29 // to make an effective multicast application and an application | 21 // to make an effective multicast application and an application |
30 // that requires quick draw possible. | 22 // that requires quick draw possible. |
31 syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEPOR T, 1) | 23 syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEPOR T, 1) |
32 } | 24 } |
33 | 25 |
34 // Allow broadcast. | 26 // Allow broadcast. |
35 syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_BROADCAST, 1) | 27 syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_BROADCAST, 1) |
36 } | 28 } |
37 | 29 |
38 func setDefaultMulticastSockopts(s int) { | 30 func setDefaultMulticastSockopts(fd *netFD) { |
albert.strasheim
2012/01/26 04:20:01
Related to my question about errors and Close from
mikio
2012/01/28 14:28:41
Done.
| |
39 » // Allow multicast UDP and raw IP datagram sockets to listen | |
40 » // concurrently across multiple listeners. | |
41 » syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1) | |
42 » syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEPORT, 1) | |
43 } | |
44 | |
45 func setMulticastSockopts(fd *netFD) { | |
46 fd.incref() | 31 fd.incref() |
47 defer fd.decref() | 32 defer fd.decref() |
48 // Allow multicast UDP and raw IP datagram sockets to listen | 33 // Allow multicast UDP and raw IP datagram sockets to listen |
49 // concurrently across multiple listeners. | 34 // concurrently across multiple listeners. |
50 syscall.SetsockoptInt(fd.sysfd, syscall.SOL_SOCKET, syscall.SO_REUSEADDR , 1) | 35 syscall.SetsockoptInt(fd.sysfd, syscall.SOL_SOCKET, syscall.SO_REUSEADDR , 1) |
51 syscall.SetsockoptInt(fd.sysfd, syscall.SOL_SOCKET, syscall.SO_REUSEPORT , 1) | 36 syscall.SetsockoptInt(fd.sysfd, syscall.SOL_SOCKET, syscall.SO_REUSEPORT , 1) |
52 } | 37 } |
LEFT | RIGHT |