Commit 59ebcbc1 authored by alexstocks's avatar alexstocks

add once for done

parent 89139c56
...@@ -4,41 +4,42 @@ ...@@ -4,41 +4,42 @@
## introdction ## ## introdction ##
--- ---
> DESC : a asynchronous network I/O library in golang > DESC : a asynchronous network I/O library in golang
LICENCE : Apache License 2.0 LICENCE : Apache License 2.0
AUTHOR : https://github.com/sanbit AUTHOR : https://github.com/sanbit
MAINTAINER : Alex Stocks MAINTAINER : Alex Stocks
EMAIL : alexstocks@foxmail.com EMAIL : alexstocks@foxmail.com
## develop history ## ## develop history ##
--- ---
- 2016/08/24 - 2016/08/24
> delete session.go:Session:wg(atomic.WaitGroup). Add session.go:Session:grNum instead to prevent from (Session)Close() block on session.go:Session:wg.Wait() > delete session.go:Session:wg(atomic.WaitGroup). Add session.go:Session:grNum instead to prevent from (Session)Close() block on session.go:Session:wg.Wait()
> version: 0.2.05 > add once for session.go:Session:done(chan struct{})
> version: 0.2.05
- 2016/08/23 - 2016/08/23
> do not consider empty package as a error in (Session)handlePackage > do not consider empty package as a error in (Session)handlePackage
> version: 0.2.04 > version: 0.2.04
- 2016/08/22 - 2016/08/22
> rename (Session)OnIdle to (Session)OnCron > rename (Session)OnIdle to (Session)OnCron
> rewrite server.go: add Server{done, wg} > rewrite server.go: add Server{done, wg}
> add utils.go > add utils.go
> version: 0.2.03 > version: 0.2.03
- 2016/08/21 - 2016/08/21
> add name for Session > add name for Session
> add OnError for Codec > add OnError for Codec
- 2016/08/18 - 2016/08/18
> delete last clause of handleRead > delete last clause of handleRead
> add reqQ handle case in last clause of handleLoop > add reqQ handle case in last clause of handleLoop
> add conditon check in (*Session)RunEventLoop() > add conditon check in (*Session)RunEventLoop()
> version: 0.2.02 > version: 0.2.02
- 2016/08/16 - 2016/08/16
> rename all structs > rename all structs
> add getty connection > add getty connection
> rewrite (Session)handleRead & (Session)handleEventLoop > rewrite (Session)handleRead & (Session)handleEventLoop
> version: 0.2.01 > version: 0.2.01
...@@ -84,6 +84,7 @@ type Session struct { ...@@ -84,6 +84,7 @@ type Session struct {
*gettyConn *gettyConn
pkgHandler ReadWriter pkgHandler ReadWriter
listener EventListener listener EventListener
once sync.Once
done chan struct{} done chan struct{}
readerDone chan struct{} // end reader readerDone chan struct{} // end reader
...@@ -98,7 +99,7 @@ type Session struct { ...@@ -98,7 +99,7 @@ type Session struct {
attrs map[string]interface{} attrs map[string]interface{}
// goroutines sync // goroutines sync
grNum int32 grNum int32
lock sync.RWMutex lock sync.RWMutex
} }
func NewSession(conn net.Conn) *Session { func NewSession(conn net.Conn) *Session {
...@@ -239,7 +240,8 @@ func (this *Session) stop() { ...@@ -239,7 +240,8 @@ func (this *Session) stop() {
case <-this.done: case <-this.done:
return return
default: default:
close(this.done) // defeat "panic: close of closed channel"
this.once.Do(func() { close(this.done) })
} }
} }
......
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