Commit 3e82e215 authored by AlexStocks's avatar AlexStocks

close net.Conn when connected failed

parent 5df04180
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
* check udp connection alive after connect() * check udp connection alive after connect()
* use ReadFromUDP as the uniform UDP read interface * use ReadFromUDP as the uniform UDP read interface
* close net.UDPConn when connected failed * close net.UDPConn when connected failed
* close net.Conn when connected failed
- 2018/03/17 - 2018/03/17
> improvement > improvement
......
...@@ -127,6 +127,7 @@ func (c *client) dialTCP() Session { ...@@ -127,6 +127,7 @@ func (c *client) dialTCP() Session {
} }
conn, err = net.DialTimeout("tcp", c.addr, connectTimeout) conn, err = net.DialTimeout("tcp", c.addr, connectTimeout)
if err == nil && conn.LocalAddr().String() == conn.RemoteAddr().String() { if err == nil && conn.LocalAddr().String() == conn.RemoteAddr().String() {
conn.Close()
err = errSelfConnect err = errSelfConnect
} }
if err == nil { if err == nil {
...@@ -207,6 +208,7 @@ func (c *client) dialWS() Session { ...@@ -207,6 +208,7 @@ func (c *client) dialWS() Session {
conn, _, err = dialer.Dial(c.addr, nil) conn, _, err = dialer.Dial(c.addr, nil)
log.Info("websocket.dialer.Dial(addr:%s) = error:%s", c.addr, err) log.Info("websocket.dialer.Dial(addr:%s) = error:%s", c.addr, err)
if err == nil && conn.LocalAddr().String() == conn.RemoteAddr().String() { if err == nil && conn.LocalAddr().String() == conn.RemoteAddr().String() {
conn.Close()
err = errSelfConnect err = errSelfConnect
} }
if err == nil { if err == nil {
...@@ -283,6 +285,7 @@ func (c *client) dialWSS() Session { ...@@ -283,6 +285,7 @@ func (c *client) dialWSS() Session {
} }
conn, _, err = dialer.Dial(c.addr, nil) conn, _, err = dialer.Dial(c.addr, nil)
if err == nil && conn.LocalAddr().String() == conn.RemoteAddr().String() { if err == nil && conn.LocalAddr().String() == conn.RemoteAddr().String() {
conn.Close()
err = errSelfConnect err = errSelfConnect
} }
if err == nil { 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