From 370023682f739722e8717a5c70d24cc0610fa7a7 Mon Sep 17 00:00:00 2001
From: Christian Pointner <equinox@helsinki.at>
Date: Sun, 17 Jul 2016 20:01:24 +0200
Subject: only add callback to session list updates once


diff --git a/src/rhimportd/ctrlWebSocket.go b/src/rhimportd/ctrlWebSocket.go
index f3e4438..5af59d5 100644
--- a/src/rhimportd/ctrlWebSocket.go
+++ b/src/rhimportd/ctrlWebSocket.go
@@ -308,6 +308,7 @@ func webSocketSessionHandler(reqchan <-chan webSocketRequestData, binchan <-chan
 	}()
 	listUpdates := make(chan webSocketSessionListUpdate, 5)
 	listUpdateCBArg := webSocketSessionListUpdateCBArg{closed, listUpdates}
+	alreadyListening := false
 
 	session := newWebSocketSession()
 	for {
@@ -346,11 +347,16 @@ func webSocketSessionHandler(reqchan <-chan webSocketRequestData, binchan <-chan
 					}
 				}
 			case "list":
-				sessions, code, errstring := sessions.List(reqdata.UserName, reqdata.Password, false, listUpdateCBArg, webSocketListUpdate)
-				if code != http.StatusOK {
-					sendWebSocketErrorResponse(ws, code, errstring)
+				if alreadyListening {
+					sendWebSocketErrorResponse(ws, http.StatusBadRequest, "This connection already listens for session-list updates")
 				} else {
-					sendWebSocketListResponse(ws, sessions, nil)
+					sessions, code, errstring := sessions.List(reqdata.UserName, reqdata.Password, false, listUpdateCBArg, webSocketListUpdate)
+					if code != http.StatusOK {
+						sendWebSocketErrorResponse(ws, code, errstring)
+					} else {
+						alreadyListening = true
+						sendWebSocketListResponse(ws, sessions, nil)
+					}
 				}
 			default:
 				sendWebSocketErrorResponse(ws, http.StatusBadRequest, fmt.Sprintf("unknown command '%s'", reqdata.Command))
-- 
cgit v0.10.2