Source file
src/net/tcpsockopt_darwin.go
1
2
3
4
5 package net
6
7 import (
8 "runtime"
9 "syscall"
10 "time"
11 )
12
13
14 const (
15 sysTCP_KEEPINTVL = 0x101
16 sysTCP_KEEPCNT = 0x102
17 )
18
19 func setKeepAliveIdle(fd *netFD, d time.Duration) error {
20 if d == 0 {
21 d = defaultTCPKeepAliveIdle
22 } else if d < 0 {
23 return nil
24 }
25
26
27 secs := int(roundDurationUp(d, time.Second))
28 err := fd.pfd.SetsockoptInt(syscall.IPPROTO_TCP, syscall.TCP_KEEPALIVE, secs)
29 runtime.KeepAlive(fd)
30 return wrapSyscallError("setsockopt", err)
31 }
32
33 func setKeepAliveInterval(fd *netFD, d time.Duration) error {
34 if d == 0 {
35 d = defaultTCPKeepAliveInterval
36 } else if d < 0 {
37 return nil
38 }
39
40
41 secs := int(roundDurationUp(d, time.Second))
42 err := fd.pfd.SetsockoptInt(syscall.IPPROTO_TCP, sysTCP_KEEPINTVL, secs)
43 runtime.KeepAlive(fd)
44 return wrapSyscallError("setsockopt", err)
45 }
46
47 func setKeepAliveCount(fd *netFD, n int) error {
48 if n == 0 {
49 n = defaultTCPKeepAliveCount
50 } else if n < 0 {
51 return nil
52 }
53
54 err := fd.pfd.SetsockoptInt(syscall.IPPROTO_TCP, sysTCP_KEEPCNT, n)
55 runtime.KeepAlive(fd)
56 return wrapSyscallError("setsockopt", err)
57 }
58
View as plain text