cubefs

Форк
0
60 строк · 1.8 Кб
1
// +build !appengine
2

3
/*
4
 *
5
 * Copyright 2018 gRPC authors.
6
 *
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
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
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.
18
 *
19
 */
20

21
package credentials
22

23
import (
24
	"net"
25
	"syscall"
26
)
27

28
type sysConn = syscall.Conn
29

30
// syscallConn keeps reference of rawConn to support syscall.Conn for channelz.
31
// SyscallConn() (the method in interface syscall.Conn) is explicitly
32
// implemented on this type,
33
//
34
// Interface syscall.Conn is implemented by most net.Conn implementations (e.g.
35
// TCPConn, UnixConn), but is not part of net.Conn interface. So wrapper conns
36
// that embed net.Conn don't implement syscall.Conn. (Side note: tls.Conn
37
// doesn't embed net.Conn, so even if syscall.Conn is part of net.Conn, it won't
38
// help here).
39
type syscallConn struct {
40
	net.Conn
41
	// sysConn is a type alias of syscall.Conn. It's necessary because the name
42
	// `Conn` collides with `net.Conn`.
43
	sysConn
44
}
45

46
// WrapSyscallConn tries to wrap rawConn and newConn into a net.Conn that
47
// implements syscall.Conn. rawConn will be used to support syscall, and newConn
48
// will be used for read/write.
49
//
50
// This function returns newConn if rawConn doesn't implement syscall.Conn.
51
func WrapSyscallConn(rawConn, newConn net.Conn) net.Conn {
52
	sysConn, ok := rawConn.(syscall.Conn)
53
	if !ok {
54
		return newConn
55
	}
56
	return &syscallConn{
57
		Conn:    newConn,
58
		sysConn: sysConn,
59
	}
60
}
61

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.