Commit 38afa856 authored by alexstocks's avatar alexstocks

use '[]byte' instead of bytes.Buffer in codec.go:(Reader)Read

parent e151651d
......@@ -14,7 +14,9 @@
- 2016/09/05
> 1 add 'errFlag = true' when got err in pkgHandler.Read loop clause in session.go:(Session)handlePackage
>
> 2 version: 0.3.03
> 2 use '[]byte' instead of bytes.Buffer in codec.go:(Reader)Read
>
> 3 version: 0.3.03
- 2016/09/04
> 1 add server.go:(Server)Listen
......
......@@ -9,10 +9,6 @@
package getty
import (
"bytes"
)
// SessionCallback will be invoked when server accepts a new client connection or client connects to server successfully.
// if there are too many client connections or u do not want to connect a server again, u can return non-nil error. And
// then getty will close the new session.
......@@ -22,7 +18,7 @@ type SessionCallback func(*Session) error
type Reader interface {
// Parse pkg from buffer and if possible return a complete pkg
// If length of buf is not long enough, u should return {nil, nil}
Read(*Session, *bytes.Buffer) (interface{}, error)
Read(*Session, []byte) (interface{}, error)
}
// Writer is used to marshal pkg and write to session
......
......@@ -491,7 +491,8 @@ func (this *Session) handlePackage() {
if pktBuf.Len() <= 0 {
break
}
pkg, err = this.pkgHandler.Read(this, pktBuf)
// pkg, err = this.pkgHandler.Read(this, pktBuf)
pkg, err = this.pkgHandler.Read(this, pktBuf.Bytes())
if err != nil {
log.Info("%s, [session.pkgHandler.Read] = error{%+v}", this.sessionToken(), err)
errFlag = true
......
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