Commit 36ec376d authored by alexstocks's avatar alexstocks

rename reconnect to errFlag

parent 7b7480dc
...@@ -9,7 +9,11 @@ ...@@ -9,7 +9,11 @@
## develop history ## ## develop history ##
--- ---
- 2016/08/29
> 1 rename reconnect to errFlag in function session.go:(Session)handlePackage
>
> 2 version: 0.2.07
- 2016/08/25 - 2016/08/25
> 1 move close done to once clause in server.go:(Server)stop > 1 move close done to once clause in server.go:(Server)stop
> >
......
...@@ -33,9 +33,9 @@ const ( ...@@ -33,9 +33,9 @@ const (
) )
var ( var (
connID uint32 = 0 connID uint32
ErrSessionClosed = errors.New("Session Already Closed") ErrSessionClosed = errors.New("Session Already Closed")
ErrSessionBlocked = errors.New("Session full blocked") ErrSessionBlocked = errors.New("Session full blocked")
) )
///////////////////////////////////////// /////////////////////////////////////////
...@@ -56,12 +56,14 @@ func newGettyConn(conn net.Conn) *gettyConn { ...@@ -56,12 +56,14 @@ func newGettyConn(conn net.Conn) *gettyConn {
} }
func (this *gettyConn) read(p []byte) (int, error) { func (this *gettyConn) read(p []byte) (int, error) {
atomic.AddUint32(&this.readCount, 1) // atomic.AddUint32(&this.readCount, 1)
atomic.AddUint32(&this.readCount, (uint32)(len(p)))
return this.conn.Read(p) return this.conn.Read(p)
} }
func (this *gettyConn) write(p []byte) (int, error) { func (this *gettyConn) write(p []byte) (int, error) {
atomic.AddUint32(&this.writeCount, 1) // atomic.AddUint32(&this.writeCount, 1)
atomic.AddUint32(&this.writeCount, (uint32)(len(p)))
return this.conn.Write(p) return this.conn.Write(p)
} }
...@@ -254,8 +256,9 @@ func (this *Session) Close() { ...@@ -254,8 +256,9 @@ func (this *Session) Close() {
func (this *Session) sessionToken() string { func (this *Session) sessionToken() string {
return fmt.Sprintf( return fmt.Sprintf(
"%s:%d:%s:%s", "{%s, %d, %s <-> %s}",
this.name, this.ID, this.name,
this.ID,
this.conn.LocalAddr().String(), this.conn.LocalAddr().String(),
this.conn.RemoteAddr().String(), this.conn.RemoteAddr().String(),
) )
...@@ -318,7 +321,7 @@ func (this *Session) handleLoop() { ...@@ -318,7 +321,7 @@ func (this *Session) handleLoop() {
err error err error
start time.Time start time.Time
ticker *time.Ticker ticker *time.Ticker
inPkg interface{} inPkg interface{}
outPkg interface{} outPkg interface{}
) )
...@@ -402,15 +405,15 @@ LAST: ...@@ -402,15 +405,15 @@ LAST:
// get package from tcp stream(packet) // get package from tcp stream(packet)
func (this *Session) handlePackage() { func (this *Session) handlePackage() {
var ( var (
err error err error
nerr net.Error nerr net.Error
ok bool ok bool
exit bool exit bool
reconnect bool errFlag bool
len int len int
buf []byte buf []byte
pktBuf *bytes.Buffer pktBuf *bytes.Buffer
pkg interface{} pkg interface{}
) )
defer func() { defer func() {
...@@ -422,8 +425,8 @@ func (this *Session) handlePackage() { ...@@ -422,8 +425,8 @@ func (this *Session) handlePackage() {
close(this.readerDone) close(this.readerDone)
grNum = atomic.AddInt32(&(this.grNum), -1) grNum = atomic.AddInt32(&(this.grNum), -1)
log.Info("%s, [session.handlePackage] gr will exit now, left gr num %d", this.sessionToken(), grNum) log.Info("%s, [session.handlePackage] gr will exit now, left gr num %d", this.sessionToken(), grNum)
if reconnect && this.listener != nil { if errFlag && this.listener != nil {
log.Info("%s, [session.handlePackage] reconnect", this.sessionToken()) log.Info("%s, [session.handlePackage] errFlag", this.sessionToken())
this.listener.OnError(this, nerr) this.listener.OnError(this, nerr)
} }
}() }()
...@@ -449,7 +452,7 @@ func (this *Session) handlePackage() { ...@@ -449,7 +452,7 @@ func (this *Session) handlePackage() {
// 遇到网络错误的时候,handlePackage能够及时退出,但是handleLoop的第一个for-select因为要处理(Codec)OnMessage // 遇到网络错误的时候,handlePackage能够及时退出,但是handleLoop的第一个for-select因为要处理(Codec)OnMessage
// 导致程序不能及时退出,此处添加(Codec)OnError调用以及时通知getty调用者 // 导致程序不能及时退出,此处添加(Codec)OnError调用以及时通知getty调用者
// AS, 2016/08/21 // AS, 2016/08/21
reconnect = true errFlag = true
exit = true exit = true
} }
break break
......
...@@ -10,5 +10,5 @@ ...@@ -10,5 +10,5 @@
package getty package getty
var ( var (
Version = "0.2.06" Version = "0.2.07"
) )
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