mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-25 02:31:46 +00:00
Merge remote-tracking branch 'origin/consensus_refactor' into consensus_refactor_jae
This commit is contained in:
@ -206,7 +206,7 @@ func _jsonStringToArg(ty reflect.Type, arg string) (reflect.Value, error) {
|
||||
// rpc.websocket
|
||||
|
||||
const (
|
||||
writeChanCapacity = 20
|
||||
writeChanCapacity = 1000
|
||||
wsWriteTimeoutSeconds = 30 // each write times out after this
|
||||
wsReadTimeoutSeconds = 30 // connection times out if we haven't received *anything* in this long, not even pings.
|
||||
wsPingTickerSeconds = 10 // send a ping every PingTickerSeconds.
|
||||
@ -289,7 +289,7 @@ func (wsc *WSConnection) readTimeoutRoutine() {
|
||||
}
|
||||
}
|
||||
|
||||
// Block trying to write to writeChan until service stops.
|
||||
// Blocking write to writeChan until service stops.
|
||||
func (wsc *WSConnection) writeRPCResponse(resp RPCResponse) {
|
||||
select {
|
||||
case <-wsc.Quit:
|
||||
@ -298,6 +298,18 @@ func (wsc *WSConnection) writeRPCResponse(resp RPCResponse) {
|
||||
}
|
||||
}
|
||||
|
||||
// Nonblocking write.
|
||||
func (wsc *WSConnection) tryWriteRPCResponse(resp RPCResponse) bool {
|
||||
select {
|
||||
case <-wsc.Quit:
|
||||
return false
|
||||
case wsc.writeChan <- resp:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Read from the socket and subscribe to or unsubscribe from events
|
||||
func (wsc *WSConnection) readRoutine() {
|
||||
// Do not close writeChan, to allow writeRPCResponse() to fail.
|
||||
@ -340,8 +352,9 @@ func (wsc *WSConnection) readRoutine() {
|
||||
} else {
|
||||
log.Notice("Subscribe to event", "id", wsc.id, "event", event)
|
||||
wsc.evsw.AddListenerForEvent(wsc.id, event, func(msg types.EventData) {
|
||||
// NOTE: EventSwitch callbacks must be nonblocking
|
||||
// NOTE: RPCResponses of subscribed events have id suffix "#event"
|
||||
wsc.writeRPCResponse(NewRPCResponse(request.ID+"#event", ctypes.ResultEvent{event, msg}, ""))
|
||||
wsc.tryWriteRPCResponse(NewRPCResponse(request.ID+"#event", ctypes.ResultEvent{event, msg}, ""))
|
||||
})
|
||||
continue
|
||||
}
|
||||
|
Reference in New Issue
Block a user