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