From 4f70de23e6d83e800fe1b15bdd6e3e11b9a1f27a Mon Sep 17 00:00:00 2001 From: lyuxuan Date: Mon, 25 Jun 2018 18:23:40 -0700 Subject: [PATCH] minor fix: remove redundant channelz files (#2176) --- channelz/types_linux.go | 54 ------------------ channelz/types_nonlinux.go | 38 ------------- channelz/util_linux_go19.go | 39 ------------- channelz/util_nonlinux_pre_go19.go | 26 --------- channelz/util_test.go | 91 ------------------------------ 5 files changed, 248 deletions(-) delete mode 100644 channelz/types_linux.go delete mode 100644 channelz/types_nonlinux.go delete mode 100644 channelz/util_linux_go19.go delete mode 100644 channelz/util_nonlinux_pre_go19.go delete mode 100644 channelz/util_test.go diff --git a/channelz/types_linux.go b/channelz/types_linux.go deleted file mode 100644 index 132b7702..00000000 --- a/channelz/types_linux.go +++ /dev/null @@ -1,54 +0,0 @@ -// +build !appengine - -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package channelz - -import ( - "syscall" - - "golang.org/x/sys/unix" -) - -// SocketOptionData defines the struct to hold socket option data, and related -// getter function to obtain info from fd. -type SocketOptionData struct { - Linger *unix.Linger - RecvTimeout *unix.Timeval - SendTimeout *unix.Timeval - TCPInfo *unix.TCPInfo -} - -// Getsockopt defines the function to get socket options requested by channelz. -// It is to be passed to syscall.RawConn.Control(). -func (s *SocketOptionData) Getsockopt(fd uintptr) { - if v, err := unix.GetsockoptLinger(int(fd), syscall.SOL_SOCKET, syscall.SO_LINGER); err == nil { - s.Linger = v - } - if v, err := unix.GetsockoptTimeval(int(fd), syscall.SOL_SOCKET, syscall.SO_RCVTIMEO); err == nil { - s.RecvTimeout = v - } - if v, err := unix.GetsockoptTimeval(int(fd), syscall.SOL_SOCKET, syscall.SO_SNDTIMEO); err == nil { - s.SendTimeout = v - } - if v, err := unix.GetsockoptTCPInfo(int(fd), syscall.SOL_TCP, syscall.TCP_INFO); err == nil { - s.TCPInfo = v - } - return -} diff --git a/channelz/types_nonlinux.go b/channelz/types_nonlinux.go deleted file mode 100644 index c4e7949c..00000000 --- a/channelz/types_nonlinux.go +++ /dev/null @@ -1,38 +0,0 @@ -// +build !linux appengine - -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package channelz - -import "google.golang.org/grpc/grpclog" - -func init() { - grpclog.Infof("Channelz: socket options are not supported on non-linux os and appengine.") -} - -// SocketOptionData defines the struct to hold socket option data, and related -// getter function to obtain info from fd. -// Windows OS doesn't support Socket Option -type SocketOptionData struct { -} - -// Getsockopt defines the function to get socket options requested by channelz. -// It is to be passed to syscall.RawConn.Control(). -// Windows OS doesn't support Socket Option -func (s *SocketOptionData) Getsockopt(fd uintptr) {} diff --git a/channelz/util_linux_go19.go b/channelz/util_linux_go19.go deleted file mode 100644 index e1e9e32d..00000000 --- a/channelz/util_linux_go19.go +++ /dev/null @@ -1,39 +0,0 @@ -// +build linux,go1.9,!appengine - -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package channelz - -import ( - "syscall" -) - -// GetSocketOption gets the socket option info of the conn. -func GetSocketOption(socket interface{}) *SocketOptionData { - c, ok := socket.(syscall.Conn) - if !ok { - return nil - } - data := &SocketOptionData{} - if rawConn, err := c.SyscallConn(); err == nil { - rawConn.Control(data.Getsockopt) - return data - } - return nil -} diff --git a/channelz/util_nonlinux_pre_go19.go b/channelz/util_nonlinux_pre_go19.go deleted file mode 100644 index 1d4da952..00000000 --- a/channelz/util_nonlinux_pre_go19.go +++ /dev/null @@ -1,26 +0,0 @@ -// +build !linux !go1.9 appengine - -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package channelz - -// GetSocketOption gets the socket option info of the conn. -func GetSocketOption(c interface{}) *SocketOptionData { - return nil -} diff --git a/channelz/util_test.go b/channelz/util_test.go deleted file mode 100644 index 4f3245fa..00000000 --- a/channelz/util_test.go +++ /dev/null @@ -1,91 +0,0 @@ -// +build linux,go1.10,!appengine - -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// The test in this file should be run in an environment that has go1.10 or later, -// as the function SyscallConn() (required to get socket option) was introduced -// to net.TCPListener in go1.10. - -package channelz_test - -import ( - "net" - "reflect" - "syscall" - "testing" - - "golang.org/x/sys/unix" - "google.golang.org/grpc/internal/channelz" -) - -func TestGetSocketOpt(t *testing.T) { - network, addr := "tcp", ":0" - ln, err := net.Listen(network, addr) - if err != nil { - t.Fatalf("net.Listen(%s,%s) failed with err: %v", network, addr, err) - } - defer ln.Close() - go func() { - ln.Accept() - }() - conn, _ := net.Dial(network, ln.Addr().String()) - defer conn.Close() - tcpc := conn.(*net.TCPConn) - raw, err := tcpc.SyscallConn() - if err != nil { - t.Fatalf("SyscallConn() failed due to %v", err) - } - - l := &unix.Linger{Onoff: 1, Linger: 5} - recvTimout := &unix.Timeval{Sec: 100} - sendTimeout := &unix.Timeval{Sec: 8888} - raw.Control(func(fd uintptr) { - var err error - err = unix.SetsockoptLinger(int(fd), syscall.SOL_SOCKET, syscall.SO_LINGER, l) - if err != nil { - t.Fatalf("failed to SetsockoptLinger(%v,%v,%v,%v) due to %v", int(fd), syscall.SOL_SOCKET, syscall.SO_LINGER, l, err) - } - err = unix.SetsockoptTimeval(int(fd), syscall.SOL_SOCKET, syscall.SO_RCVTIMEO, recvTimout) - if err != nil { - t.Fatalf("failed to SetsockoptTimeval(%v,%v,%v,%v) due to %v", int(fd), syscall.SOL_SOCKET, syscall.SO_RCVTIMEO, recvTimout, err) - } - err = unix.SetsockoptTimeval(int(fd), syscall.SOL_SOCKET, syscall.SO_SNDTIMEO, sendTimeout) - if err != nil { - t.Fatalf("failed to SetsockoptTimeval(%v,%v,%v,%v) due to %v", int(fd), syscall.SOL_SOCKET, syscall.SO_SNDTIMEO, sendTimeout, err) - } - }) - sktopt := channelz.GetSocketOption(conn) - if !reflect.DeepEqual(sktopt.Linger, l) { - t.Fatalf("get socket option linger, want: %v, got %v", l, sktopt.Linger) - } - if !reflect.DeepEqual(sktopt.RecvTimeout, recvTimout) { - t.Logf("get socket option recv timeout, want: %v, got %v, may be caused by system allowing non or partial setting of this value", recvTimout, sktopt.RecvTimeout) - } - if !reflect.DeepEqual(sktopt.SendTimeout, sendTimeout) { - t.Logf("get socket option send timeout, want: %v, got %v, may be caused by system allowing non or partial setting of this value", sendTimeout, sktopt.SendTimeout) - } - if sktopt == nil || sktopt.TCPInfo != nil && sktopt.TCPInfo.State != 1 { - t.Fatalf("TCPInfo.State want 1 (TCP_ESTABLISHED), got %v", sktopt) - } - - sktopt = channelz.GetSocketOption(ln) - if sktopt == nil || sktopt.TCPInfo == nil || sktopt.TCPInfo.State != 10 { - t.Fatalf("TCPInfo.State want 10 (TCP_LISTEN), got %v", sktopt) - } -}