Skip to content

Commit 9695aa1

Browse files
authored
feat: rm hard dep on x/sys (#1742)
We only referenced a constant, so I inlined it.
1 parent bec0f29 commit 9695aa1

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ require (
1212
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b
1313
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783
1414
golang.org/x/sync v0.1.0
15-
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10
1615
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2
1716
google.golang.org/appengine v1.6.7
1817
google.golang.org/genproto v0.0.0-20221024183307-1bc688fe9f3e
@@ -23,6 +22,7 @@ require (
2322
cloud.google.com/go/compute v1.12.1 // indirect
2423
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
2524
github.com/golang/protobuf v1.5.2 // indirect
25+
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
2626
golang.org/x/text v0.4.0 // indirect
2727
google.golang.org/protobuf v1.28.1 // indirect
2828
)

transport/grpc/dial_socketopt.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ import (
1212
"net"
1313
"syscall"
1414

15-
"golang.org/x/sys/unix"
1615
"google.golang.org/grpc"
1716
)
1817

1918
const (
2019
// defaultTCPUserTimeout is the default TCP_USER_TIMEOUT socket option. By
2120
// default is 20 seconds.
2221
tcpUserTimeoutMilliseconds = 20000
22+
23+
// Copied from golang.org/x/sys/unix.TCP_USER_TIMEOUT.
24+
tcpUserTimeoutOp = 0x12
2325
)
2426

2527
func init() {
@@ -33,7 +35,7 @@ func dialTCPUserTimeout(ctx context.Context, addr string) (net.Conn, error) {
3335
var syscallErr error
3436
controlErr := c.Control(func(fd uintptr) {
3537
syscallErr = syscall.SetsockoptInt(
36-
int(fd), syscall.IPPROTO_TCP, unix.TCP_USER_TIMEOUT, tcpUserTimeoutMilliseconds)
38+
int(fd), syscall.IPPROTO_TCP, tcpUserTimeoutOp, tcpUserTimeoutMilliseconds)
3739
})
3840
if syscallErr != nil {
3941
return syscallErr

transport/grpc/dial_socketopt_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"time"
1818

1919
"golang.org/x/oauth2"
20-
"golang.org/x/sys/unix"
2120
"google.golang.org/api/option"
2221
"google.golang.org/api/option/internaloption"
2322
"google.golang.org/grpc"
@@ -78,7 +77,7 @@ func getTCPUserTimeout(conn net.Conn) (int, error) {
7877
var timeout int
7978
var syscalErr error
8079
controlErr := rawConn.Control(func(fd uintptr) {
81-
timeout, syscalErr = syscall.GetsockoptInt(int(fd), syscall.IPPROTO_TCP, unix.TCP_USER_TIMEOUT)
80+
timeout, syscalErr = syscall.GetsockoptInt(int(fd), syscall.IPPROTO_TCP, tcpUserTimeoutOp)
8281
})
8382
if syscalErr != nil {
8483
return 0, syscalErr

0 commit comments

Comments
 (0)