Commit 493e5afc authored by alexstocks's avatar alexstocks

defeat self connection

parent 807e92dc
......@@ -10,6 +10,13 @@
## develop history ##
---
- 2016/09/09
> 1 add defeat self connection logic in client.go & server.go
>
> 2 version: 0.3.08
- 2016/09/09
> 1 delete session.go:(Session)readerDone
>
......
......@@ -73,6 +73,9 @@ func (this *Client) dial() net.Conn {
return nil
}
conn, err = net.DialTimeout("tcp", this.addr, connectTimeout)
if err == nil && conn.LocalAddr().String() == conn.RemoteAddr().String() {
err = errSelfConnect
}
if err == nil {
return conn
}
......
......@@ -20,6 +20,10 @@ import (
log "github.com/AlexStocks/log4go"
)
var (
errSelfConnect = errors.New("connect self!")
)
type Server struct {
// net
addr string
......@@ -107,7 +111,7 @@ func (this *Server) RunEventloop(newSession NewSessionCallback) {
}
continue
}
log.Info("Server{%s}.Accept() = err {%#v}", this.addr, err)
log.Warn("Server{%s}.Accept() = err {%#v}", this.addr, err)
continue
}
delay = 0
......@@ -125,6 +129,9 @@ func (this *Server) Accept(newSession NewSessionCallback) (*Session, error) {
if err != nil {
return nil, err
}
if conn.RemoteAddr().String() == conn.LocalAddr().String() {
return nil, errSelfConnect
}
session := NewSession(conn)
err = newSession(session)
......
......@@ -10,5 +10,5 @@
package getty
var (
Version = "0.3.07"
Version = "0.3.08"
)
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