Commit f5224e3a authored by alexstocks's avatar alexstocks

add remarks for session.go

parent 0cc6334b
......@@ -11,6 +11,14 @@
## develop history ##
---
- 2016/11/01
> 1 session.go:Session{maxPkgLen(int)} -> Session{maxPkgLen(int32)}
>
> 2 add remarks in session.go
>
> 2 version: 0.4.07
- 2016/10/21
> 1 session.go:(Session)RunEventLoop -> session.go:(Session)run
>
......
......@@ -27,7 +27,7 @@ type Writer interface {
Write(*Session, interface{}) error
}
// tcp packet handler interface
// tcp package handler interface
type ReadWriter interface {
Reader
Writer
......@@ -50,6 +50,6 @@ type EventListener interface {
// invoked when receive packge. Pls attention that do not handle long time logic processing in this func.
// Y'd better set the package's maximum length. If the message's length is greater than it, u should
// should return err and getty will close this connection soon.
// should return err in Reader{Read} and getty will close this connection soon.
OnMessage(*Session, interface{})
}
......@@ -54,7 +54,7 @@ type empty struct{}
// getty base session
type Session struct {
name string
maxMsgLen int
maxMsgLen int32
// net read write
iConn
// pkgHandler ReadWriter
......@@ -193,9 +193,13 @@ func (this *Session) IsClosed() bool {
}
}
func (this *Session) SetMaxMsgLen(len int) { this.maxMsgLen = len }
func (this *Session) SetName(name string) { this.name = name }
// set maximum pacakge length of every pacakge in (EventListener)OnMessage(@pkgs)
func (this *Session) SetMaxMsgLen(length int) { this.maxMsgLen = int32(length) }
// set session name
func (this *Session) SetName(name string) { this.name = name }
// set EventListener
func (this *Session) SetEventListener(listener EventListener) {
this.listener = listener
}
......@@ -207,10 +211,12 @@ func (this *Session) SetPkgHandler(handler ReadWriter) {
// this.pkgHandler = handler
}
// set Reader
func (this *Session) SetReader(reader Reader) {
this.reader = reader
}
// set Writer
func (this *Session) SetWriter(writer Writer) {
this.writer = writer
}
......@@ -275,6 +281,7 @@ func (this *Session) SetWaitTime(waitTime time.Duration) {
this.lock.Unlock()
}
// set attribute of key @session:key
func (this *Session) GetAttribute(key string) interface{} {
var ret interface{}
this.lock.RLock()
......@@ -283,22 +290,26 @@ func (this *Session) GetAttribute(key string) interface{} {
return ret
}
// get attribute of key @session:key
func (this *Session) SetAttribute(key string, value interface{}) {
this.lock.Lock()
this.attrs[key] = value
this.lock.Unlock()
}
// delete attribute of key @session:key
func (this *Session) RemoveAttribute(key string) {
this.lock.Lock()
delete(this.attrs, key)
this.lock.Unlock()
}
// update session's active time
func (this *Session) UpdateActive() {
this.updateActive()
}
// get session's active time
func (this *Session) GetActive() time.Time {
return this.getActive()
}
......@@ -356,6 +367,7 @@ func (this *Session) WriteBytes(pkg []byte) error {
return this.iConn.write(pkg)
}
// write multiple packages at once
func (this *Session) WriteBytesArray(pkgs ...[]byte) error {
if this.IsClosed() {
return ErrSessionClosed
......@@ -602,7 +614,7 @@ func (this *Session) handleTCPPackage() error {
}
// pkg, err = this.pkgHandler.Read(this, pktBuf)
pkg, pkgLen, err = this.reader.Read(this, pktBuf.Bytes())
if err == nil && this.maxMsgLen > 0 && pkgLen > this.maxMsgLen {
if err == nil && this.maxMsgLen > 0 && pkgLen > int(this.maxMsgLen) {
err = ErrMsgTooLong
}
if err != nil {
......@@ -656,7 +668,7 @@ func (this *Session) handleWSPackage() error {
this.updateActive()
if this.reader != nil {
unmarshalPkg, length, err = this.reader.Read(this, pkg)
if err == nil && this.maxMsgLen > 0 && length > this.maxMsgLen {
if err == nil && this.maxMsgLen > 0 && length > int(this.maxMsgLen) {
err = ErrMsgTooLong
}
if err != nil {
......
......@@ -10,9 +10,9 @@
package getty
const (
Version = "0.4.05"
DATE = "2016/10/21"
Version = "0.4.07"
DATE = "2016/11/01"
GETTY_MAJOR = 0
GETTY_MINOR = 4
GETTY_BUILD = 5
GETTY_BUILD = 7
)
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