37 Star 411 Fork 76

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)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.1.8

搜索帮助

0d507c66 1850385 C8b1a773 1850385