Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rm hard dep on x/sys #1742

Merged
merged 2 commits into from Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
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
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
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