added bw calcs
unfortunately there is an issue with how these are calculated, and they don't decrease as things quiet down. Well, the bad numbers are their for your consumption, and should Just Work TM when appropriate changes in bitbucket.org/smcquay/bandwith land. And they will. But I'm tired now.
This commit is contained in:
@@ -1,26 +1,30 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"code.google.com/p/go.net/websocket"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"bitbucket.org/smcquay/bandwidth"
|
||||
"code.google.com/p/go.net/websocket"
|
||||
)
|
||||
|
||||
const maxMessageSize = 1024
|
||||
|
||||
type protoTalker struct {
|
||||
ws *websocket.Conn
|
||||
bw *bandwidth.Bandwidth
|
||||
send chan Message
|
||||
buff []byte
|
||||
Id string
|
||||
}
|
||||
|
||||
func NewProtoTalker(id string, ws *websocket.Conn) *protoTalker {
|
||||
func NewProtoTalker(id string, ws *websocket.Conn, bw *bandwidth.Bandwidth) *protoTalker {
|
||||
return &protoTalker{
|
||||
send: make(chan Message, 16),
|
||||
ws: ws,
|
||||
bw: bw,
|
||||
Id: id,
|
||||
buff: make([]byte, maxMessageSize),
|
||||
}
|
||||
@@ -33,8 +37,8 @@ func (pt *protoTalker) sender() {
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
// XXX: send the count to our bandwidth analyzer ...
|
||||
_, err = pt.ws.Write(b)
|
||||
n, err := pt.ws.Write(b)
|
||||
pt.bw.AddTx <- n
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
@@ -50,7 +54,7 @@ func (pt *protoTalker) readJSON(buff []byte) (map[string]Instruction, error) {
|
||||
log.Printf("%s: problem reading from player: %s", pt.Id, err)
|
||||
return nil, err
|
||||
}
|
||||
// XXX: send n to our bandwidth analyzer ...
|
||||
pt.bw.AddRx <- n
|
||||
if n == len(buff) {
|
||||
errMsg := fmt.Sprintf("%s: read buffer overfull: %s", pt.Id, string(buff))
|
||||
log.Printf(errMsg)
|
||||
@@ -70,10 +74,10 @@ type player struct {
|
||||
protoTalker
|
||||
}
|
||||
|
||||
func NewPlayer(id string, ws *websocket.Conn) *player {
|
||||
func NewPlayer(id string, ws *websocket.Conn, bw *bandwidth.Bandwidth) *player {
|
||||
return &player{
|
||||
Robots: []*Robot{},
|
||||
protoTalker: *NewProtoTalker(id, ws),
|
||||
protoTalker: *NewProtoTalker(id, ws, bw),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,9 +156,9 @@ type Spectator struct {
|
||||
protoTalker
|
||||
}
|
||||
|
||||
func NewSpectator(id string, ws *websocket.Conn) *Spectator {
|
||||
func NewSpectator(id string, ws *websocket.Conn, bw *bandwidth.Bandwidth) *Spectator {
|
||||
return &Spectator{
|
||||
protoTalker: *NewProtoTalker(id, ws),
|
||||
protoTalker: *NewProtoTalker(id, ws, bw),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user