From e111c998862692e12bc5954426b3ba8b4139af9a Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 3 Apr 2016 18:35:05 +1200 Subject: [PATCH] libnmdc: assert state parameter is set correctly --- src/libnmdc/libnmdc.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libnmdc/libnmdc.go b/src/libnmdc/libnmdc.go index 554e612..e403f15 100644 --- a/src/libnmdc/libnmdc.go +++ b/src/libnmdc/libnmdc.go @@ -342,10 +342,14 @@ func (this *HubConnection) worker() { } if err != nil { - this.OnEvent <- HubEvent{EventType: EVENT_CONNECTION_STATE_CHANGED, StateChange: CONNECTIONSTATE_CONNECTING} + this.State = CONNECTIONSTATE_DISCONNECTED this.connValid = false + } else { + this.State = CONNECTIONSTATE_CONNECTING this.connValid = true + this.OnEvent <- HubEvent{EventType: EVENT_CONNECTION_STATE_CHANGED, StateChange: CONNECTIONSTATE_CONNECTING} + } } @@ -361,7 +365,10 @@ func (this *HubConnection) worker() { // Maybe we disconnected if err != nil { this.OnEvent <- HubEvent{EventType: EVENT_CONNECTION_STATE_CHANGED, StateChange: CONNECTIONSTATE_DISCONNECTED, Message: err.Error()} + this.State = CONNECTIONSTATE_DISCONNECTED this.conn = nil + this.connValid = false + time.Sleep(30 * time.Second) // Wait before reconnect continue }