-
Notifications
You must be signed in to change notification settings - Fork 4
add darwin #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
add darwin #1
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package tcpkeepalive | ||
|
|
||
| import ( | ||
| "os" | ||
| "runtime" | ||
| "syscall" | ||
| "time" | ||
| ) | ||
|
|
||
| const sysTCP_KEEPINTVL = 0x101 | ||
|
|
||
| func setIdle(fd uintptr, d time.Duration) error { | ||
| // not possible with darwin | ||
| return nil | ||
| } | ||
|
|
||
| func setCount(fd uintptr, n int) error { | ||
| // not possible with darwin | ||
| return nil | ||
| } | ||
|
|
||
| func setInterval(fd uintptr, d time.Duration) error { | ||
| // # from https://golang.org/src/net/tcpsockopt_darwin.go | ||
| d += (time.Second - time.Nanosecond) | ||
| secs := int(d.Seconds()) | ||
| switch err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, sysTCP_KEEPINTVL, secs); err { | ||
| case nil, syscall.ENOPROTOOPT: // OS X 10.7 and earlier don't support this option | ||
| default: | ||
| return os.NewSyscallError("setsockopt", err) | ||
| } | ||
| err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, syscall.TCP_KEEPALIVE, secs) | ||
|
||
| runtime.KeepAlive(fd) | ||
|
||
| return os.NewSyscallError("setsockopt", err) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the source code https://github.com/apple/darwin-xnu/blob/0a798f6738bc1db01281fc08ae024145e84df927/bsd/netinet/tcp.h looks like also count is implemented on darwin (not sure from which version)
In this repo that uses the hackish way of calling setsockopt they are using it:
https://github.com/felixge/tcpkeepalive/blob/master/keepalive_darwin.go