Commit 3e82e215 authored by AlexStocks's avatar AlexStocks

close net.Conn when connected failed

parent 5df04180
......@@ -20,6 +20,7 @@
* check udp connection alive after connect()
* use ReadFromUDP as the uniform UDP read interface
* close net.UDPConn when connected failed
* close net.Conn when connected failed
- 2018/03/17
> improvement
......
......@@ -127,6 +127,7 @@ func (c *client) dialTCP() Session {
}
conn, err = net.DialTimeout("tcp", c.addr, connectTimeout)
if err == nil && conn.LocalAddr().String() == conn.RemoteAddr().String() {
conn.Close()
err = errSelfConnect
}
if err == nil {
......@@ -207,6 +208,7 @@ func (c *client) dialWS() Session {
conn, _, err = dialer.Dial(c.addr, nil)
log.Info("websocket.dialer.Dial(addr:%s) = error:%s", c.addr, err)
if err == nil && conn.LocalAddr().String() == conn.RemoteAddr().String() {
conn.Close()
err = errSelfConnect
}
if err == nil {
......@@ -283,6 +285,7 @@ func (c *client) dialWSS() Session {
}
conn, _, err = dialer.Dial(c.addr, nil)
if err == nil && conn.LocalAddr().String() == conn.RemoteAddr().String() {
conn.Close()
err = errSelfConnect
}
if err == nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment