37 Star 407 Fork 74

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
client_dialer.go 987 Bytes
一键复制 编辑 原始数据 按行查看 历史
package remotedialer
import (
"io"
"net"
"sync"
"time"
)
func clientDial(conn *connection, message *message) {
defer conn.Close()
var (
netConn net.Conn
err error
)
if message.deadline == 0 {
netConn, err = net.Dial(message.proto, message.address)
} else {
netConn, err = net.DialTimeout(message.proto, message.address, time.Duration(message.deadline)*time.Millisecond)
}
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.0.7-rc1

搜索帮助