Use strings in websocket send/receive.

The websocket package assumes binary blobs if []byte is used.  Since we're
using JSON-RPC for all the websocket communications, it should be text
based.

This commit changes the websocket Send/Receive and associated channels to
strings accordingly.
This commit is contained in:
Dave Collins 2014-01-17 14:48:02 -06:00
parent 75554fab09
commit 9474ef29d7

View File

@ -563,7 +563,7 @@ func (s *rpcServer) walletReqsNotifications(ws *websocket.Conn) {
} }
// msgs is a channel for all messages received over the websocket. // msgs is a channel for all messages received over the websocket.
msgs := make(chan []byte) msgs := make(chan string)
// Receive messages from websocket and send across reqs until the // Receive messages from websocket and send across reqs until the
// connection is lost. // connection is lost.
@ -574,7 +574,7 @@ func (s *rpcServer) walletReqsNotifications(ws *websocket.Conn) {
return return
default: default:
var m []byte var m string
if err := websocket.Message.Receive(ws, &m); err != nil { if err := websocket.Message.Receive(ws, &m); err != nil {
// Only close disconnected if not closed yet. // Only close disconnected if not closed yet.
select { select {
@ -628,7 +628,7 @@ func (s *rpcServer) walletReqsNotifications(ws *websocket.Conn) {
rpcsLog.Errorf("Error unmarshaling response: %v", err) rpcsLog.Errorf("Error unmarshaling response: %v", err)
continue continue
} }
if err := websocket.Message.Send(ws, mresp); err != nil { if err := websocket.Message.Send(ws, string(mresp)); err != nil {
// Only close disconnected if not closed yet. // Only close disconnected if not closed yet.
select { select {
case <-disconnected: case <-disconnected:
@ -647,7 +647,7 @@ func (s *rpcServer) walletReqsNotifications(ws *websocket.Conn) {
rpcsLog.Errorf("Error unmarshaling notification: %v", err) rpcsLog.Errorf("Error unmarshaling notification: %v", err)
continue continue
} }
if err := websocket.Message.Send(ws, mntfn); err != nil { if err := websocket.Message.Send(ws, string(mntfn)); err != nil {
// Only close disconnected if not closed yet. // Only close disconnected if not closed yet.
select { select {
case <-disconnected: case <-disconnected:
@ -664,13 +664,13 @@ func (s *rpcServer) walletReqsNotifications(ws *websocket.Conn) {
// websocketJSONHandler parses and handles a marshalled json message, // websocketJSONHandler parses and handles a marshalled json message,
// sending the marshalled reply to a wallet notification channel. // sending the marshalled reply to a wallet notification channel.
func (s *rpcServer) websocketJSONHandler(r chan *btcjson.Reply, c handlerChans, msg []byte) { func (s *rpcServer) websocketJSONHandler(r chan *btcjson.Reply, c handlerChans, msg string) {
s.wg.Add(1) s.wg.Add(1)
defer s.wg.Done() defer s.wg.Done()
var resp *btcjson.Reply var resp *btcjson.Reply
cmd, jsonErr := parseCmd(msg) cmd, jsonErr := parseCmd([]byte(msg))
if jsonErr != nil { if jsonErr != nil {
resp = &btcjson.Reply{} resp = &btcjson.Reply{}
if cmd != nil { if cmd != nil {