rpc client SetPingHandler with 30 second timeout; wire time json test

This commit is contained in:
Jae Kwon
2015-09-15 00:55:51 -07:00
parent c6e5948534
commit 726f5475b0
2 changed files with 20 additions and 7 deletions

View File

@ -3,6 +3,7 @@ package core_client
import (
"net/http"
"strings"
"time"
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/gorilla/websocket"
. "github.com/tendermint/tendermint/common"
@ -12,8 +13,11 @@ import (
"github.com/tendermint/tendermint/wire"
)
const wsEventsChannelCapacity = 10
const wsResultsChannelCapacity = 10
const (
wsEventsChannelCapacity = 10
wsResultsChannelCapacity = 10
wsWriteTimeoutSeconds = 10
)
type WSClient struct {
QuitService
@ -53,6 +57,14 @@ func (wsc *WSClient) dial() error {
if err != nil {
return err
}
// Set the ping/pong handlers
con.SetPingHandler(func(m string) error {
con.WriteControl(websocket.PongMessage, []byte(m), time.Now().Add(time.Second*wsWriteTimeoutSeconds))
return nil
})
con.SetPongHandler(func(m string) error {
return nil
})
wsc.Conn = con
return nil
}
@ -65,14 +77,14 @@ func (wsc *WSClient) receiveEventsRoutine() {
for {
_, data, err := wsc.ReadMessage()
if err != nil {
log.Info(Fmt("WSClient failed to read message: %v", err))
log.Info("WSClient failed to read message", "error", err, "data", string(data))
wsc.Stop()
break
} else {
var response ctypes.Response
wire.ReadJSON(&response, data, &err)
if err != nil {
log.Info(Fmt("WSClient failed to parse message: %v", err))
log.Info("WSClient failed to parse message", "error", err)
wsc.Stop()
break
}