Commit 5d50a01f authored by alexstocks's avatar alexstocks

add session.go:(Session){ID, LocalAddr, RemoteAddr}

parent f5224e3a
......@@ -11,13 +11,19 @@
## develop history ##
---
- 2016/11/02
> 1 add session.go:Session{ID(), LocalAddr(), RemoteAddr()}
>
> 2 add conn.go:iConn{id(), localAddr(), remoteAddr()}
>
> 2 version: 0.4.08
- 2016/11/01
> 1 session.go:Session{maxPkgLen(int)} -> Session{maxPkgLen(int32)}
>
> 2 add remarks in session.go
>
> 2 version: 0.4.07
> 2 version: 0.4.07(0.4.06 is a obsolete version)
- 2016/10/21
> 1 session.go:(Session)RunEventLoop -> session.go:(Session)run
......
......@@ -32,6 +32,9 @@ var (
/////////////////////////////////////////
type iConn interface {
id() uint32
localAddr() string
remoteAddr() string
incReadPkgCount()
incWritePkgCount()
updateActive()
......@@ -68,6 +71,18 @@ type gettyConn struct {
peer string // peer address
}
func (this *gettyConn) id() uint32 {
return this.ID
}
func (this *gettyConn) localAddr() string {
return this.local
}
func (this *gettyConn) remoteAddr() string {
return this.peer
}
func (this *gettyConn) incReadPkgCount() {
atomic.AddUint32(&this.readPkgCount, 1)
}
......
......@@ -77,9 +77,6 @@ type Session struct {
lock sync.RWMutex
}
// if nerr, ok = err.(net.Error); ok && nerr.Timeout() {
// break
// }
func NewSession() *Session {
session := &Session{
name: defaultSessionName,
......@@ -166,6 +163,21 @@ func (this *Session) gettyConn() *gettyConn {
return nil
}
// get session ID
func (this *Session) ID() uint32 {
return this.iConn.id()
}
// get local address
func (this *Session) LocalAddr() string {
return this.iConn.localAddr()
}
// get peer address
func (this *Session) RemoteAddr() string {
return this.iConn.remoteAddr()
}
// return the connect statistic data
func (this *Session) Stat() string {
var conn *gettyConn
......@@ -315,12 +327,7 @@ func (this *Session) GetActive() time.Time {
}
func (this *Session) sessionToken() string {
var conn *gettyConn
if conn = this.gettyConn(); conn == nil {
return ""
}
return fmt.Sprintf("{%s:%d:%s<->%s}", this.name, conn.ID, conn.local, conn.peer)
return fmt.Sprintf("{%s:%d:%s<->%s}", this.name, this.iConn.id(), this.iConn.localAddr(), this.iConn.remoteAddr())
}
// Queued write, for handler
......
......@@ -10,9 +10,9 @@
package getty
const (
Version = "0.4.07"
DATE = "2016/11/01"
Version = "0.4.08"
DATE = "2016/11/02"
GETTY_MAJOR = 0
GETTY_MINOR = 4
GETTY_BUILD = 7
GETTY_BUILD = 8
)
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