Commit 493e5afc authored by alexstocks's avatar alexstocks

defeat self connection

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