From 9695aa13a084c1ad9857db4a6c12d57e13fc00dc Mon Sep 17 00:00:00 2001 From: Cody Oss <6331106+codyoss@users.noreply.github.com> Date: Mon, 7 Nov 2022 12:00:20 -0600 Subject: [PATCH] feat: rm hard dep on x/sys (#1742) We only referenced a constant, so I inlined it. --- go.mod | 2 +- transport/grpc/dial_socketopt.go | 6 ++++-- transport/grpc/dial_socketopt_test.go | 3 +-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index f6c9d686213..4f599e50859 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,6 @@ require ( golang.org/x/net v0.0.0-20221014081412-f15817d10f9b golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 golang.org/x/sync v0.1.0 - golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 google.golang.org/appengine v1.6.7 google.golang.org/genproto v0.0.0-20221024183307-1bc688fe9f3e @@ -23,6 +22,7 @@ require ( cloud.google.com/go/compute v1.12.1 // indirect github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/golang/protobuf v1.5.2 // indirect + golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect golang.org/x/text v0.4.0 // indirect google.golang.org/protobuf v1.28.1 // indirect ) diff --git a/transport/grpc/dial_socketopt.go b/transport/grpc/dial_socketopt.go index 4bf9e821723..507cd3ec63a 100644 --- a/transport/grpc/dial_socketopt.go +++ b/transport/grpc/dial_socketopt.go @@ -12,7 +12,6 @@ import ( "net" "syscall" - "golang.org/x/sys/unix" "google.golang.org/grpc" ) @@ -20,6 +19,9 @@ const ( // defaultTCPUserTimeout is the default TCP_USER_TIMEOUT socket option. By // default is 20 seconds. tcpUserTimeoutMilliseconds = 20000 + + // Copied from golang.org/x/sys/unix.TCP_USER_TIMEOUT. + tcpUserTimeoutOp = 0x12 ) func init() { @@ -33,7 +35,7 @@ func dialTCPUserTimeout(ctx context.Context, addr string) (net.Conn, error) { var syscallErr error controlErr := c.Control(func(fd uintptr) { syscallErr = syscall.SetsockoptInt( - int(fd), syscall.IPPROTO_TCP, unix.TCP_USER_TIMEOUT, tcpUserTimeoutMilliseconds) + int(fd), syscall.IPPROTO_TCP, tcpUserTimeoutOp, tcpUserTimeoutMilliseconds) }) if syscallErr != nil { return syscallErr diff --git a/transport/grpc/dial_socketopt_test.go b/transport/grpc/dial_socketopt_test.go index 5915d6615f0..a9af313efb7 100644 --- a/transport/grpc/dial_socketopt_test.go +++ b/transport/grpc/dial_socketopt_test.go @@ -17,7 +17,6 @@ import ( "time" "golang.org/x/oauth2" - "golang.org/x/sys/unix" "google.golang.org/api/option" "google.golang.org/api/option/internaloption" "google.golang.org/grpc" @@ -78,7 +77,7 @@ func getTCPUserTimeout(conn net.Conn) (int, error) { var timeout int var syscalErr error controlErr := rawConn.Control(func(fd uintptr) { - timeout, syscalErr = syscall.GetsockoptInt(int(fd), syscall.IPPROTO_TCP, unix.TCP_USER_TIMEOUT) + timeout, syscalErr = syscall.GetsockoptInt(int(fd), syscall.IPPROTO_TCP, tcpUserTimeoutOp) }) if syscalErr != nil { return 0, syscalErr