libnmdc: ensure we always flush protocol commands that happened alongside a disconnection event

This commit is contained in:
mappu 2016-04-03 18:54:56 +12:00
parent debc14cea3
commit 019f67a7de
1 changed files with 13 additions and 11 deletions

View File

@ -375,17 +375,6 @@ func (this *HubConnection) worker() {
}
}
// Maybe we disconnected
if err != nil {
this.State = CONNECTIONSTATE_DISCONNECTED
this.conn = nil
this.connValid = false
this.processEvent(HubEvent{EventType: EVENT_CONNECTION_STATE_CHANGED, StateChange: CONNECTIONSTATE_DISCONNECTED, Message: err.Error()})
time.Sleep(30 * time.Second) // Wait before reconnect
continue
}
// Attempt to parse a message block
for len(fullBuffer) > 0 {
for len(fullBuffer) > 0 && fullBuffer[0] == '|' {
@ -400,6 +389,19 @@ func (this *HubConnection) worker() {
}
}
// Maybe we disconnected
// Perform this check *last*, to ensure we've had a final shot at
// clearing out any queued messages
if err != nil {
this.State = CONNECTIONSTATE_DISCONNECTED
this.conn = nil
this.connValid = false
this.processEvent(HubEvent{EventType: EVENT_CONNECTION_STATE_CHANGED, StateChange: CONNECTIONSTATE_DISCONNECTED, Message: err.Error()})
time.Sleep(30 * time.Second) // Wait before reconnect
continue
}
}
}