5 * Copyright 2018 gRPC authors.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 // Package internal contains credentials-internal code.
29 type sysConn = syscall.Conn
31 // syscallConn keeps reference of rawConn to support syscall.Conn for channelz.
32 // SyscallConn() (the method in interface syscall.Conn) is explicitly
33 // implemented on this type,
35 // Interface syscall.Conn is implemented by most net.Conn implementations (e.g.
36 // TCPConn, UnixConn), but is not part of net.Conn interface. So wrapper conns
37 // that embed net.Conn don't implement syscall.Conn. (Side note: tls.Conn
38 // doesn't embed net.Conn, so even if syscall.Conn is part of net.Conn, it won't
40 type syscallConn struct {
42 // sysConn is a type alias of syscall.Conn. It's necessary because the name
43 // `Conn` collides with `net.Conn`.
47 // WrapSyscallConn tries to wrap rawConn and newConn into a net.Conn that
48 // implements syscall.Conn. rawConn will be used to support syscall, and newConn
49 // will be used for read/write.
51 // This function returns newConn if rawConn doesn't implement syscall.Conn.
52 func WrapSyscallConn(rawConn, newConn net.Conn) net.Conn {
53 sysConn, ok := rawConn.(syscall.Conn)