summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-07-17 18:01:24 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-07-17 18:01:24 (GMT)
commit370023682f739722e8717a5c70d24cc0610fa7a7 (patch)
tree3feb2b67b74047ad881d7f6165f13c37d500c775 /src
parentd6cf861d9db69584f33c464e76c8387c9099fafb (diff)
only add callback to session list updates once
Diffstat (limited to 'src')
-rw-r--r--src/rhimportd/ctrlWebSocket.go14
1 files changed, 10 insertions, 4 deletions
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))