37 Star 404 Fork 74

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
client_dialer.go 1.02 KB
一键复制 编辑 原始数据 按行查看 历史
package remotedialer
import (
"io"
"net"
"sync"
"time"
"github.com/rancher/types/config/dialer"
)
func clientDial(dialer dialer.Dialer, conn *connection, message *message) {
defer conn.Close()
var (
netConn net.Conn
err error
)
if dialer == nil {
netConn, err = net.DialTimeout(message.proto, message.address, time.Duration(message.deadline)*time.Millisecond)
} else {
netConn, err = dialer(message.proto, message.address)
}
if err != nil {
conn.tunnelClose(err)
return
}
defer netConn.Close()
pipe(conn, netConn)
}
func pipe(client *connection, server net.Conn) {
wg := sync.WaitGroup{}
wg.Add(1)
close := func(err error) error {
if err == nil {
err = io.EOF
}
client.doTunnelClose(err)
server.Close()
return err
}
go func() {
defer wg.Done()
_, err := io.Copy(server, client)
close(err)
}()
_, err := io.Copy(client, server)
err = close(err)
wg.Wait()
// Write tunnel error after no more I/O is happening, just incase messages get out of order
client.writeErr(err)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.1.2-rc13

搜索帮助