LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Socket options for Linux | 5 // Socket options for Linux |
6 | 6 |
7 package net | 7 package net |
8 | 8 |
9 import ( | 9 import ( |
10 "os" | 10 "os" |
11 "syscall" | 11 "syscall" |
| 12 "time" |
12 ) | 13 ) |
| 14 |
| 15 func deadlineNano(t time.Time) int64 { |
| 16 if t.IsZero() { |
| 17 return 0 |
| 18 } |
| 19 return t.UnixNano() |
| 20 } |
| 21 |
| 22 func setDeadlineImpl(fd *netFD, t time.Time, mode int) error { |
| 23 d := t.UnixNano() |
| 24 if t.IsZero() { |
| 25 d = 0 |
| 26 } |
| 27 if err := fd.incref(false); err != nil { |
| 28 return err |
| 29 } |
| 30 defer fd.decref() |
| 31 runtime_setDeadlineFD(fd.pollServer, d, mode) |
| 32 return nil |
| 33 } |
| 34 |
| 35 func setReadDeadline(fd *netFD, t time.Time) error { |
| 36 return setDeadlineImpl(fd, t, 'r') |
| 37 } |
| 38 |
| 39 func setWriteDeadline(fd *netFD, t time.Time) error { |
| 40 return setDeadlineImpl(fd, t, 'w') |
| 41 } |
| 42 |
| 43 func setDeadline(fd *netFD, t time.Time) error { |
| 44 return setDeadlineImpl(fd, t, 'r'+'w') |
| 45 } |
13 | 46 |
14 func setDefaultSockopts(s, f, t int, ipv6only bool) error { | 47 func setDefaultSockopts(s, f, t int, ipv6only bool) error { |
15 switch f { | 48 switch f { |
16 case syscall.AF_INET6: | 49 case syscall.AF_INET6: |
17 if ipv6only { | 50 if ipv6only { |
18 syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.I
PV6_V6ONLY, 1) | 51 syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.I
PV6_V6ONLY, 1) |
19 } else { | 52 } else { |
20 // Allow both IP versions even if the OS default | 53 // Allow both IP versions even if the OS default |
21 // is otherwise. Note that some operating systems | 54 // is otherwise. Note that some operating systems |
22 // never admit this option. | 55 // never admit this option. |
(...skipping 19 matching lines...) Expand all Loading... |
42 | 75 |
43 func setDefaultMulticastSockopts(s int) error { | 76 func setDefaultMulticastSockopts(s int) error { |
44 // Allow multicast UDP and raw IP datagram sockets to listen | 77 // Allow multicast UDP and raw IP datagram sockets to listen |
45 // concurrently across multiple listeners. | 78 // concurrently across multiple listeners. |
46 err := syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR
, 1) | 79 err := syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR
, 1) |
47 if err != nil { | 80 if err != nil { |
48 return os.NewSyscallError("setsockopt", err) | 81 return os.NewSyscallError("setsockopt", err) |
49 } | 82 } |
50 return nil | 83 return nil |
51 } | 84 } |
LEFT | RIGHT |