Skip to content

Commit

Permalink
feat: rm hard dep on x/sys (#1742)
Browse files Browse the repository at this point in the history
We only referenced a constant, so I inlined it.
  • Loading branch information
codyoss authored Nov 7, 2022
1 parent bec0f29 commit 9695aa1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
6 changes: 4 additions & 2 deletions transport/grpc/dial_socketopt.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ import (
"net"
"syscall"

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

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() {
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions transport/grpc/dial_socketopt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9695aa1

Please sign in to comment.