Skip to content

Commit

Permalink
change clientIncoming to use the same buffer for all messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Cooper committed Nov 21, 2014
1 parent 7bda9e8 commit f68273b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions gumble/client_incoming.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func clientIncoming(client *Client) {
defer client.Close()

conn := client.connection
data := make([]byte, 1024)

for {
var pType uint16
Expand All @@ -27,12 +28,14 @@ func clientIncoming(client *Client) {
if pLengthInt > maximumPacketLength {
return
}
data := make([]byte, pLengthInt)
if _, err := io.ReadFull(conn, data); err != nil {
if pLengthInt > cap(data) {
data = make([]byte, pLengthInt)
}
if _, err := io.ReadFull(conn, data[:pLengthInt]); err != nil {
return
}
if handle, ok := handlers[pType]; ok {
if err := handle(client, data); err != nil {
if err := handle(client, data[:pLengthInt]); err != nil {
// TODO: log error?
}
}
Expand Down

0 comments on commit f68273b

Please sign in to comment.