Skip to content

Commit 297d8dd

Browse files
authored
Cherry-pick #6841 to v1.60.x release branch (#6847)
1 parent 3580447 commit 297d8dd

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

internal/tcp_keepalive_nonunix.go

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//go:build !unix
2+
3+
/*
4+
* Copyright 2023 gRPC authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
*/
19+
20+
package internal
21+
22+
import (
23+
"net"
24+
)
25+
26+
// NetDialerWithTCPKeepalive returns a vanilla net.Dialer on non-unix platforms.
27+
func NetDialerWithTCPKeepalive() *net.Dialer {
28+
return &net.Dialer{}
29+
}

internal/tcp_keepalive.go renamed to internal/tcp_keepalive_unix.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build unix
2+
13
/*
24
* Copyright 2023 gRPC authors.
35
*
@@ -21,6 +23,8 @@ import (
2123
"net"
2224
"syscall"
2325
"time"
26+
27+
"golang.org/x/sys/unix"
2428
)
2529

2630
// NetDialerWithTCPKeepalive returns a net.Dialer that enables TCP keepalives on
@@ -43,7 +47,7 @@ func NetDialerWithTCPKeepalive() *net.Dialer {
4347
// the TCP keealive interval and time parameters.
4448
Control: func(_, _ string, c syscall.RawConn) error {
4549
return c.Control(func(fd uintptr) {
46-
syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_KEEPALIVE, 1)
50+
unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_KEEPALIVE, 1)
4751
})
4852
},
4953
}

0 commit comments

Comments
 (0)