Skip to content
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

add darwin #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

add darwin #1

wants to merge 4 commits into from

Conversation

viphak
Copy link

@viphak viphak commented Sep 29, 2017

attempt to make it work on darwin

Copy link
Member

@sgotti sgotti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@viphak thanks for your PR.

I put some comments since I'm not sure that copying the current golang implementation is right since we have to fine grain control the 3 tcp keepalive options and looks like darwin permits this. Though I don't use any other os than Linux so I can't verify this.

// d += (time.Second - time.Nanosecond)
// secs := int(d.Seconds())
// return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, sysTCP_KEEPINTVL, secs))
// The kernel expects seconds so round to next highest second.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll keep this comment as it helps explaining the expected time unit.

return os.NewSyscallError("setsockopt", err)
}
err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, syscall.TCP_KEEPALIVE, secs)
runtime.KeepAlive(fd)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't needed since the rawConn interface alreafy guarantees that the file descriptor will remain valid https://golang.org/pkg/syscall/#RawConn

default:
return os.NewSyscallError("setsockopt", err)
}
err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, syscall.TCP_KEEPALIVE, secs)
Copy link
Member

@sgotti sgotti Oct 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the man https://github.com/apple/darwin-xnu/blob/5394bb038891708cd4ba748da79b90a33b19f82e/bsd/man/man4/tcp.4#L172 TCP_KEEPALIVE should set the idle and not the interval so it doesn't belong here but should be put in the setIdle function.

}

func setCount(fd uintptr, n int) error {
// not possible with darwin
Copy link
Member

@sgotti sgotti Oct 2, 2017

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

@sgotti
Copy link
Member

sgotti commented Oct 3, 2017

@viphak Thanks! I have some cosmetic changes in mind but I will do them in some followup PR. Did you manage to try if it works?

@viphak
Copy link
Author

viphak commented Oct 3, 2017

I'll create some unit tests for macOS tonight

@sgotti
Copy link
Member

sgotti commented Jan 22, 2018

@viphak gentle ping 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants