Commit 3d7706a1 authored by alexstocks's avatar alexstocks

v0.3.01

parent 160d42fa
...@@ -10,6 +10,19 @@ ...@@ -10,6 +10,19 @@
## develop history ## ## develop history ##
--- ---
- 2016/09/03
> 1 modify return value of session.go:(Session)Close from void to error
>
> 2 add clause "this.attrs = nil" in session.go:(Session)Close
>
> 3 modify session.go:Session{*gettyConn} to session.go:Session{gettyConn}
>
> 4 session.go:(Session)Reset
>
> 5 session.go:(Session)SetConn
>
> 6 version: 0.3.01
- 2016/09/02 - 2016/09/02
> 1 add session.go:(gettyConn)close and session.go:(Session)dispose > 1 add session.go:(gettyConn)close and session.go:(Session)dispose
> >
......
...@@ -17,9 +17,7 @@ import ( ...@@ -17,9 +17,7 @@ import (
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
)
import (
log "github.com/AlexStocks/log4go" log "github.com/AlexStocks/log4go"
) )
...@@ -32,16 +30,14 @@ const ( ...@@ -32,16 +30,14 @@ const (
outputFormat = "session %s, Read Count: %d, Write Count: %d, Read Pkg Count: %d, Write Pkg Count: %d" outputFormat = "session %s, Read Count: %d, Write Count: %d, Read Pkg Count: %d, Write Pkg Count: %d"
) )
var (
connID uint32
ErrSessionClosed = errors.New("Session Already Closed")
ErrSessionBlocked = errors.New("Session full blocked")
)
///////////////////////////////////////// /////////////////////////////////////////
// getty connection // getty connection
///////////////////////////////////////// /////////////////////////////////////////
var (
connID uint32
)
type gettyConn struct { type gettyConn struct {
conn net.Conn conn net.Conn
ID uint32 ID uint32
...@@ -51,8 +47,8 @@ type gettyConn struct { ...@@ -51,8 +47,8 @@ type gettyConn struct {
writePkgCount uint32 // recv pkg count writePkgCount uint32 // recv pkg count
} }
func newGettyConn(conn net.Conn) *gettyConn { func newGettyConn(conn net.Conn) gettyConn {
return &gettyConn{conn: conn, ID: atomic.AddUint32(&connID, 1)} return gettyConn{conn: conn, ID: atomic.AddUint32(&connID, 1)}
} }
func (this *gettyConn) read(p []byte) (int, error) { func (this *gettyConn) read(p []byte) (int, error) {
...@@ -87,11 +83,16 @@ func (this *gettyConn) incWritePkgCount() { ...@@ -87,11 +83,16 @@ func (this *gettyConn) incWritePkgCount() {
// session // session
///////////////////////////////////////// /////////////////////////////////////////
var (
ErrSessionClosed = errors.New("Session Already Closed")
ErrSessionBlocked = errors.New("Session full blocked")
)
// getty base session // getty base session
type Session struct { type Session struct {
name string name string
// net read write // net read write
*gettyConn gettyConn
pkgHandler ReadWriter pkgHandler ReadWriter
listener EventListener listener EventListener
once sync.Once once sync.Once
...@@ -126,7 +127,19 @@ func NewSession(conn net.Conn) *Session { ...@@ -126,7 +127,19 @@ func NewSession(conn net.Conn) *Session {
} }
} }
func (this *Session) Conn() net.Conn { return this.conn } func (this *Session) Reset() {
this.name = defaultSessionName
this.done = make(chan struct{})
this.readerDone = make(chan struct{})
this.cronPeriod = cronPeriod
this.readDeadline = netIOTimeout
this.writeDeadline = netIOTimeout
this.wait = pendingDuration
this.attrs = make(map[string]interface{})
}
func (this *Session) SetConn(conn net.Conn) { this.gettyConn = newGettyConn(conn) }
func (this *Session) Conn() net.Conn { return this.conn }
func (this *Session) Stat() string { func (this *Session) Stat() string {
return fmt.Sprintf( return fmt.Sprintf(
...@@ -256,10 +269,13 @@ func (this *Session) stop() { ...@@ -256,10 +269,13 @@ func (this *Session) stop() {
} }
} }
func (this *Session) Close() { func (this *Session) Close() error {
this.stop() this.stop()
this.attrs = nil
log.Info("%s closed now, its current gr num %d", log.Info("%s closed now, its current gr num %d",
this.sessionToken(), atomic.LoadInt32(&(this.grNum))) this.sessionToken(), atomic.LoadInt32(&(this.grNum)))
return nil
} }
func (this *Session) sessionToken() string { func (this *Session) sessionToken() string {
...@@ -366,8 +382,8 @@ LOOP: ...@@ -366,8 +382,8 @@ LOOP:
break LOOP break LOOP
case inPkg = <-this.rQ: case inPkg = <-this.rQ:
if this.listener != nil { if this.listener != nil {
this.incReadPkgCount()
this.listener.OnMessage(this, inPkg) this.listener.OnMessage(this, inPkg)
this.incReadPkgCount()
} }
case outPkg = <-this.wQ: case outPkg = <-this.wQ:
if err = this.pkgHandler.Write(this, outPkg); err != nil { if err = this.pkgHandler.Write(this, outPkg); err != nil {
...@@ -403,8 +419,8 @@ LAST: ...@@ -403,8 +419,8 @@ LAST:
this.incWritePkgCount() this.incWritePkgCount()
case inPkg = <-this.rQ: case inPkg = <-this.rQ:
if this.listener != nil { if this.listener != nil {
this.incReadPkgCount()
this.listener.OnMessage(this, inPkg) this.listener.OnMessage(this, inPkg)
this.incReadPkgCount()
} }
default: default:
log.Info("%s, [session.handleLoop] default", this.sessionToken()) log.Info("%s, [session.handleLoop] default", this.sessionToken())
......
...@@ -10,5 +10,5 @@ ...@@ -10,5 +10,5 @@
package getty package getty
var ( var (
Version = "0.3.00" Version = "0.3.01"
) )
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