Skip to content

Commit

Permalink
remove not supported control flag on darwin (#1025)
Browse files Browse the repository at this point in the history
* remove not supported control flag on darwin

Signed-off-by: kpango <[email protected]>

* remove not supported control flag on darwin

Signed-off-by: kpango <[email protected]>

* format & update

Signed-off-by: kpango <[email protected]>
  • Loading branch information
kpango authored Feb 19, 2021
1 parent bf20447 commit 4bf65f8
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 108 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ all: clean deps
.PHONY: clean
## clean
clean:
rm -rf vendor
go clean -cache -modcache -testcache -i -r
mv ./apis/grpc/v1/vald/vald.go $(TEMP_DIR)/vald.go
rm -rf \
Expand Down
22 changes: 11 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module github.com/vdaas/vald

go 1.15
go 1.16

replace (
cloud.google.com/go => cloud.google.com/go v0.77.0
github.com/Azure/go-autorest => github.com/Azure/go-autorest v14.2.0+incompatible
github.com/aws/aws-sdk-go => github.com/aws/aws-sdk-go v1.37.13
github.com/aws/aws-sdk-go => github.com/aws/aws-sdk-go v1.37.14
github.com/boltdb/bolt => github.com/boltdb/bolt v1.3.1
github.com/chzyer/logex => github.com/chzyer/logex v1.1.11-0.20170329064859-445be9e134b2
github.com/coreos/etcd => go.etcd.io/etcd v3.3.25+incompatible
Expand All @@ -26,12 +26,12 @@ replace (
golang.org/x/crypto => golang.org/x/crypto v0.0.0-20210218145215-b8e89b74b9df
google.golang.org/grpc => google.golang.org/grpc v1.35.0
google.golang.org/protobuf => google.golang.org/protobuf v1.25.0
k8s.io/api => k8s.io/api v0.20.3
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.20.3
k8s.io/apimachinery => k8s.io/apimachinery v0.20.3
k8s.io/cli-runtime => k8s.io/cli-runtime v0.20.3
k8s.io/client-go => k8s.io/client-go v0.20.3
k8s.io/metrics => k8s.io/metrics v0.20.3
k8s.io/api => k8s.io/api v0.20.4
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.20.4
k8s.io/apimachinery => k8s.io/apimachinery v0.20.4
k8s.io/cli-runtime => k8s.io/cli-runtime v0.20.4
k8s.io/client-go => k8s.io/client-go v0.20.4
k8s.io/metrics => k8s.io/metrics v0.20.4
sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.8.2
)

Expand Down Expand Up @@ -82,10 +82,10 @@ require (
google.golang.org/genproto v0.0.0-20210218151259-fe80b386bf06
google.golang.org/grpc v1.35.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.20.3
k8s.io/apimachinery v0.20.3
k8s.io/api v0.20.4
k8s.io/apimachinery v0.20.4
k8s.io/cli-runtime v0.0.0-00010101000000-000000000000
k8s.io/client-go v0.20.3
k8s.io/client-go v0.20.4
k8s.io/metrics v0.0.0-00010101000000-000000000000
sigs.k8s.io/controller-runtime v0.0.0-00010101000000-000000000000
)
38 changes: 18 additions & 20 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hC
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/aws/aws-sdk-go v1.37.13 h1:7w1gJHJdpMfv+JbedCeOkQrYu46k0j01ULpv7oLfb3U=
github.com/aws/aws-sdk-go v1.37.13/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
github.com/aws/aws-sdk-go v1.37.14 h1:thuR1hd1doCvsaMDYDMhqCGSmw39bSvZaw+DPGhMm5w=
github.com/aws/aws-sdk-go v1.37.14/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down Expand Up @@ -218,7 +218,6 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/martian/v3 v3.1.0 h1:wCKgOCHuUEVfsaQLpPSJb7VdYCdTVZQAuOdYm1yc/60=
github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
github.com/google/pprof v0.0.0-20210208152844-1612e9be7af6 h1:38TDCVodvyooskjOFh+Ve8EY37rS8ZNzEIPHMWZaY/Y=
github.com/google/pprof v0.0.0-20210208152844-1612e9be7af6/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
Expand Down Expand Up @@ -755,7 +754,6 @@ gonum.org/v1/gonum v0.8.1/go.mod h1:oe/vMfY3deqTw+1EZJhuvEW2iwGF1bW9wwu7XCu0+v0=
gonum.org/v1/hdf5 v0.0.0-20190227001252-83207889d689/go.mod h1:g+PDU5ogjIKcc3Cg4ALAK7X4c8bBQvPzPKWNW5NB7I0=
gonum.org/v1/hdf5 v0.0.0-20200504100616-496fefe91614 h1:6opGC6JlNr8Efmo4HPh6P7JFrNL/8VH2/prV5esilyk=
gonum.org/v1/hdf5 v0.0.0-20200504100616-496fefe91614/go.mod h1:BQUWDHIAygjdt1HnUPQ0eWqLN2n5FwJycrpYUVUOx2I=
gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0 h1:OE9mWmgKkjJyEmDAAtGMPjXu+YNeGvK9VTSHY6+Qihc=
gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw=
gonum.org/v1/plot v0.0.0-20190515093506-e2840ee46a6b/go.mod h1:Wt8AAjI+ypCyYX3nZBvf6cAIx93T+c/OS2HFAYskSZc=
gonum.org/v1/plot v0.8.1 h1:1oWyfw7tIDDtKb+t+SbR9RFruMmNJlsKiZUolHdys2I=
Expand Down Expand Up @@ -853,21 +851,21 @@ honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4 h1:UoveltGrhghAA7ePc+e+QYDHXrBps2PqFZiHkGR/xK8=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
k8s.io/api v0.20.3 h1:rGtKGUSo7Do4dxFKS4ju77GovaSGT5Zze25PS5HhqgE=
k8s.io/api v0.20.3/go.mod h1:9/N1PKffb5ioImFknLewyktqAKCAh6xnhc7JFMhX6zg=
k8s.io/apiextensions-apiserver v0.20.3 h1:1jmB7QFZXiCltjXk0HxgIYNQwfvgW9yiXWRBTcHy9ic=
k8s.io/apiextensions-apiserver v0.20.3/go.mod h1:WIswo1dBghieNakH6WfZ1NLRRUiw/IMxocQWJ4/efQA=
k8s.io/apimachinery v0.20.3 h1:P0heYNTI2km9gTUAb0PX5qRd8oHAaesICvkg13k97y4=
k8s.io/apimachinery v0.20.3/go.mod h1:WlLqWAHZGg07AeltaI0MV5uk1Omp8xaN0JGLY6gkRpU=
k8s.io/apiserver v0.20.3/go.mod h1:9HMGY+Abj3WT1Fx/Ul5w/AV037PoR9yL88smTBseUhA=
k8s.io/cli-runtime v0.20.3 h1:qSJqaZ14fw6z6nQxznAHONmGd8Knt7MIpeRC/J4VYuo=
k8s.io/cli-runtime v0.20.3/go.mod h1:Jiu/JWK581aLFN62t5Mb9ZF8h+qbYJERqJ1j/EeZCG4=
k8s.io/client-go v0.20.3 h1:6ofV+ycm6X/5DfSTo1aJ9C8jloi2nJTzFgRMXJcrK4I=
k8s.io/client-go v0.20.3/go.mod h1:tRUgITfrhGECV2MGpZPr1Db3pNv9k5coAn89asDm/YE=
k8s.io/code-generator v0.20.3/go.mod h1:UsqdF+VX4PU2g46NC2JRs4gc+IfrctnwHb76RNbWHJg=
k8s.io/api v0.20.4 h1:xZjKidCirayzX6tHONRQyTNDVIR55TYVqgATqo6ZULY=
k8s.io/api v0.20.4/go.mod h1:++lNL1AJMkDymriNniQsWRkMDzRaX2Y/POTUi8yvqYQ=
k8s.io/apiextensions-apiserver v0.20.4 h1:VO/Y5PwBdznMIctX/vvgSNhxffikEmcLC/V1bpbhHhU=
k8s.io/apiextensions-apiserver v0.20.4/go.mod h1:Hzebis/9c6Io5yzHp24Vg4XOkTp1ViMwKP/6gmpsfA4=
k8s.io/apimachinery v0.20.4 h1:vhxQ0PPUUU2Ns1b9r4/UFp13UPs8cw2iOoTjnY9faa0=
k8s.io/apimachinery v0.20.4/go.mod h1:WlLqWAHZGg07AeltaI0MV5uk1Omp8xaN0JGLY6gkRpU=
k8s.io/apiserver v0.20.4/go.mod h1:Mc80thBKOyy7tbvFtB4kJv1kbdD0eIH8k8vianJcbFM=
k8s.io/cli-runtime v0.20.4 h1:jVU13lBeebHLtarHeHkoIi3uRONFzccmP7hHLzEoQ4w=
k8s.io/cli-runtime v0.20.4/go.mod h1:dz38e1CM4uuIhy8PMFUZv7qsvIdoE3ByZYlmbHNCkt4=
k8s.io/client-go v0.20.4 h1:85crgh1IotNkLpKYKZHVNI1JT86nr/iDCvq2iWKsql4=
k8s.io/client-go v0.20.4/go.mod h1:LiMv25ND1gLUdBeYxBIwKpkSC5IsozMMmOOeSJboP+k=
k8s.io/code-generator v0.20.4/go.mod h1:UsqdF+VX4PU2g46NC2JRs4gc+IfrctnwHb76RNbWHJg=
k8s.io/component-base v0.20.2/go.mod h1:pzFtCiwe/ASD0iV7ySMu8SYVJjCapNM9bjvk7ptpKh0=
k8s.io/component-base v0.20.3 h1:gzMrbr5U0d1QWO/xwz/txIuOJGVOpHfiYOSalfo2dus=
k8s.io/component-base v0.20.3/go.mod h1:Sru/qMz6MCSxPntXfuU0xwz/cizjBAnLFvG5fNq9ydw=
k8s.io/component-base v0.20.4 h1:gdvPs4G11e99meQnW4zN+oYOjH8qkLz1sURrAzvKWqc=
k8s.io/component-base v0.20.4/go.mod h1:t4p9EdiagbVCJKrQ1RsA5/V4rFQNDfRlevJajlGwgjI=
k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
k8s.io/gengo v0.0.0-20201113003025-83324d819ded/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
Expand All @@ -876,8 +874,8 @@ k8s.io/klog/v2 v2.4.0 h1:7+X0fUguPyrKEC4WjH8iGDg3laWgMo5tMnRTIGTTxGQ=
k8s.io/klog/v2 v2.4.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y=
k8s.io/kube-openapi v0.0.0-20201113171705-d219536bb9fd h1:sOHNzJIkytDF6qadMNKhhDRpc6ODik8lVC6nOur7B2c=
k8s.io/kube-openapi v0.0.0-20201113171705-d219536bb9fd/go.mod h1:WOJ3KddDSol4tAGcJo0Tvi+dK12EcqSLqcWsryKMpfM=
k8s.io/metrics v0.20.3 h1:hKoYuUmE8e61Nc2ObHV7149OPS4xGR9+9kG30kNgfWM=
k8s.io/metrics v0.20.3/go.mod h1:XRoc7kX96+w9nuSfU/i2iASyDXaYlQLkLHPlMebBqpA=
k8s.io/metrics v0.20.4 h1:SxpF5zcFbUCvF3qzY6WPicp4VVFn9VCMHxnEvrwWJoQ=
k8s.io/metrics v0.20.4/go.mod h1:DDXS+Ls+2NAxRcVhXKghRPa3csljyJRjDRjPe6EOg/g=
k8s.io/utils v0.0.0-20201110183641-67b214c5f920/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
k8s.io/utils v0.0.0-20210111153108-fddb29f9d009 h1:0T5IaWHO3sJTEmCP6mUlBvMukxPKUQWqiI/YuiBNMiQ=
k8s.io/utils v0.0.0-20210111153108-fddb29f9d009/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
Expand Down
16 changes: 8 additions & 8 deletions hack/go.mod.default
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/vdaas/vald

go 1.15
go 1.16

replace (
cloud.google.com/go => cloud.google.com/go latest
Expand All @@ -26,12 +26,12 @@ replace (
golang.org/x/crypto => golang.org/x/crypto latest
google.golang.org/grpc => google.golang.org/grpc latest
google.golang.org/protobuf => google.golang.org/protobuf latest
k8s.io/api => k8s.io/api v0.20.3
k8s.io/client-go => k8s.io/client-go v0.20.3
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.20.3
k8s.io/apimachinery => k8s.io/apimachinery v0.20.3
k8s.io/cli-runtime => k8s.io/cli-runtime v0.20.3
k8s.io/client-go => k8s.io/client-go v0.20.3
k8s.io/metrics => k8s.io/metrics v0.20.3
k8s.io/api => k8s.io/api v0.20.4
k8s.io/client-go => k8s.io/client-go v0.20.4
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.20.4
k8s.io/apimachinery => k8s.io/apimachinery v0.20.4
k8s.io/cli-runtime => k8s.io/cli-runtime v0.20.4
k8s.io/client-go => k8s.io/client-go v0.20.4
k8s.io/metrics => k8s.io/metrics v0.20.4
sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.8.2
)
11 changes: 4 additions & 7 deletions internal/info/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ import (
"go.uber.org/goleak"
)

var (
// Goroutine leak is detected by `fastime`, but it should be ignored in the test because it is an external package.
goleakIgnoreOptions = []goleak.Option{
goleak.IgnoreTopFunction("github.com/kpango/fastime.(*Fastime).StartTimerD.func1"),
}
)
// Goroutine leak is detected by `fastime`, but it should be ignored in the test because it is an external package.
var goleakIgnoreOptions = []goleak.Option{
goleak.IgnoreTopFunction("github.com/kpango/fastime.(*Fastime).StartTimerD.func1"),
}

func TestMain(m *testing.M) {
log.Init()
Expand Down Expand Up @@ -523,7 +521,6 @@ func TestNew(t *testing.T) {
if err := test.checkFunc(test.want, got, err); err != nil {
tt.Errorf("error = %v", err)
}

})
}
}
Expand Down
10 changes: 4 additions & 6 deletions internal/info/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ import (
// Option represent the functional option for info.
type Option func(i *info) error

var (
defaultOpts = []Option{
WithRuntimeCaller(runtime.Caller),
WithRuntimeFuncForPC(runtime.FuncForPC),
}
)
var defaultOpts = []Option{
WithRuntimeCaller(runtime.Caller),
WithRuntimeFuncForPC(runtime.FuncForPC),
}

// WithServerName returns the option to set the server name.
func WithServerName(s string) Option {
Expand Down
90 changes: 54 additions & 36 deletions internal/net/control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ const (
TCPDeferAccept
IPTransparent
IPRecoverDestinationAddr

// from linux/include/uapi/linux/tcp.h
TCP_FASTOPEN int = 0x17
TCP_FASTOPEN_CONNECT int = 0x1e
)

func New(flag SocketFlag, keepAlive int) SocketController {
Expand Down Expand Up @@ -99,38 +95,54 @@ func (ctrl *control) GetControl() func(network, addr string, c syscall.RawConn)
log.Debugf("controlling socket for %s://%s, config %#v", network, address, ctrl)
f := int(fd)
var ierr error
ierr = SetsockoptInt(f, SOL_SOCKET, SO_REUSEPORT, boolint(ctrl.reusePort))
if ierr != nil {
err = errors.Wrap(err, ierr.Error())
}
ierr = SetsockoptInt(f, SOL_SOCKET, SO_REUSEADDR, boolint(ctrl.reuseAddr))
if ierr != nil {
err = errors.Wrap(err, ierr.Error())
}
if isTCP(network) {
ierr = SetsockoptInt(f, IPPROTO_TCP, TCP_FASTOPEN, boolint(ctrl.tcpFastOpen))
if SO_REUSEPORT != 0 {
ierr = SetsockoptInt(f, SOL_SOCKET, SO_REUSEPORT, boolint(ctrl.reusePort))
if ierr != nil {
err = errors.Wrap(err, ierr.Error())
}
ierr = SetsockoptInt(f, IPPROTO_TCP, TCP_FASTOPEN_CONNECT, boolint(ctrl.tcpFastOpen))
}
if SO_REUSEADDR != 0 {
ierr = SetsockoptInt(f, SOL_SOCKET, SO_REUSEADDR, boolint(ctrl.reuseAddr))
if ierr != nil {
err = errors.Wrap(err, ierr.Error())
}
ierr = SetsockoptInt(f, IPPROTO_TCP, TCP_NODELAY, boolint(ctrl.tcpNoDelay))
if ierr != nil {
err = errors.Wrap(err, ierr.Error())
}
if isTCP(network) {
if TCP_FASTOPEN != 0 {
ierr = SetsockoptInt(f, IPPROTO_TCP, TCP_FASTOPEN, boolint(ctrl.tcpFastOpen))
if ierr != nil {
err = errors.Wrap(err, ierr.Error())
}
}
ierr = SetsockoptInt(f, IPPROTO_TCP, TCP_CORK, boolint(ctrl.tcpCork))
if ierr != nil {
err = errors.Wrap(err, ierr.Error())
if TCP_FASTOPEN_CONNECT != 0 {
ierr = SetsockoptInt(f, IPPROTO_TCP, TCP_FASTOPEN_CONNECT, boolint(ctrl.tcpFastOpen))
if ierr != nil {
err = errors.Wrap(err, ierr.Error())
}
}
ierr = SetsockoptInt(f, IPPROTO_TCP, TCP_QUICKACK, boolint(ctrl.tcpQuickAck))
if ierr != nil {
err = errors.Wrap(err, ierr.Error())
if TCP_NODELAY != 0 {
ierr = SetsockoptInt(f, IPPROTO_TCP, TCP_NODELAY, boolint(ctrl.tcpNoDelay))
if ierr != nil {
err = errors.Wrap(err, ierr.Error())
}
}
ierr = SetsockoptInt(f, IPPROTO_TCP, TCP_DEFER_ACCEPT, boolint(ctrl.tcpDeferAccept))
if ierr != nil {
err = errors.Wrap(err, ierr.Error())
if TCP_CORK != 0 {
ierr = SetsockoptInt(f, IPPROTO_TCP, TCP_CORK, boolint(ctrl.tcpCork))
if ierr != nil {
err = errors.Wrap(err, ierr.Error())
}
}
if TCP_QUICKACK != 0 {
ierr = SetsockoptInt(f, IPPROTO_TCP, TCP_QUICKACK, boolint(ctrl.tcpQuickAck))
if ierr != nil {
err = errors.Wrap(err, ierr.Error())
}
}
if TCP_DEFER_ACCEPT != 0 {
ierr = SetsockoptInt(f, IPPROTO_TCP, TCP_DEFER_ACCEPT, boolint(ctrl.tcpDeferAccept))
if ierr != nil {
err = errors.Wrap(err, ierr.Error())
}
}
}
var sol, trans, rda int
Expand All @@ -153,18 +165,24 @@ func (ctrl *control) GetControl() func(network, addr string, c syscall.RawConn)
}
}

ierr = SetsockoptInt(f, SOL_SOCKET, SO_KEEPALIVE, boolint(ctrl.keepAlive > 0))
if ierr != nil {
err = errors.Wrap(err, ierr.Error())
}
if ctrl.keepAlive > 0 && isTCP(network) {
ierr = SetsockoptInt(f, IPPROTO_TCP, TCP_KEEPINTVL, ctrl.keepAlive)
if SO_KEEPALIVE != 0 {
ierr = SetsockoptInt(f, SOL_SOCKET, SO_KEEPALIVE, boolint(ctrl.keepAlive > 0))
if ierr != nil {
err = errors.Wrap(err, ierr.Error())
}
ierr = SetsockoptInt(f, IPPROTO_TCP, TCP_KEEPIDLE, ctrl.keepAlive)
if ierr != nil {
err = errors.Wrap(err, ierr.Error())
}
if ctrl.keepAlive > 0 && isTCP(network) {
if TCP_KEEPINTVL != 0 {
ierr = SetsockoptInt(f, IPPROTO_TCP, TCP_KEEPINTVL, ctrl.keepAlive)
if ierr != nil {
err = errors.Wrap(err, ierr.Error())
}
}
if TCP_KEEPIDLE != 0 {
ierr = SetsockoptInt(f, IPPROTO_TCP, TCP_KEEPIDLE, ctrl.keepAlive)
if ierr != nil {
err = errors.Wrap(err, ierr.Error())
}
}
}
})
Expand Down
44 changes: 24 additions & 20 deletions internal/net/control/control_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,34 @@ package control

import (
"syscall"

"golang.org/x/sys/unix"
)

var SetsockoptInt = syscall.SetsockoptInt
var SetsockoptInt = unix.SetsockoptInt

const (
SOL_SOCKET = syscall.SOL_SOCKET
IPPROTO_TCP = syscall.IPPROTO_TCP
SOL_IP = syscall.SOL_IP
SOL_IPV6 = syscall.SOL_IPV6

SO_REUSEADDR = syscall.SO_REUSEADDR
SO_REUSEPORT = syscall.SO_REUSEPORT
SO_KEEPALIVE = syscall.SO_KEEPALIVE

TCP_NODELAY = syscall.TCP_NODELAY
TCP_CORK = syscall.TCP_CORK
TCP_QUICKACK = syscall.TCP_QUICKACK
TCP_DEFER_ACCEPT = syscall.TCP_DEFER_ACCEPT
TCP_KEEPINTVL = syscall.TCP_KEEPINTVL
TCP_KEEPIDLE = syscall.TCP_KEEPIDLE

IP_TRANSPARENT = syscall.IP_TRANSPARENT
IPV6_TRANSPARENT = syscall.IPV6_TRANSPARENT

IP_RECVORIGDSTADDR = syscall.IP_RECVORIGDSTADDR
IPV6_RECVORIGDSTADDR = syscall.IPV6_RECVORIGDSTADDR
SOL_IP = 0
SOL_IPV6 = 0

SO_REUSEADDR = unix.SO_REUSEADDR
SO_REUSEPORT = unix.SO_REUSEPORT
SO_KEEPALIVE = unix.SO_KEEPALIVE

TCP_NODELAY = unix.TCP_NODELAY
TCP_CORK = 0
TCP_QUICKACK = 0
TCP_DEFER_ACCEPT = 0
TCP_KEEPINTVL = unix.TCP_KEEPINTVL
TCP_KEEPIDLE = 0
TCP_FASTOPEN = unix.TCP_FASTOPEN
TCP_FASTOPEN_CONNECT = 0

IP_TRANSPARENT = 0
IPV6_TRANSPARENT = 0

IP_RECVORIGDSTADDR = 0
IPV6_RECVORIGDSTADDR = 0
)
2 changes: 2 additions & 0 deletions internal/net/control/control_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const (
TCP_DEFER_ACCEPT = 0
TCP_KEEPINTVL = 0
TCP_KEEPIDLE = 0
TCP_FASTOPEN = 0
TCP_FASTOPEN_CONNECT = 0
IP_TRANSPARENT = 0
IPV6_TRANSPARENT = 0
IP_RECVORIGDSTADDR = 0
Expand Down
3 changes: 3 additions & 0 deletions internal/net/control/control_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ const (
TCP_DEFER_ACCEPT = unix.TCP_DEFER_ACCEPT
TCP_KEEPINTVL = unix.TCP_KEEPINTVL
TCP_KEEPIDLE = unix.TCP_KEEPIDLE
// from linux/include/uapi/linux/tcp.h
TCP_FASTOPEN = unix.TCP_FASTOPEN
TCP_FASTOPEN_CONNECT = unix.TCP_FASTOPEN_CONNECT

IP_TRANSPARENT = unix.IP_TRANSPARENT
IPV6_TRANSPARENT = unix.IPV6_TRANSPARENT
Expand Down
Loading

0 comments on commit 4bf65f8

Please sign in to comment.