summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-12-29 14:10:18 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-12-29 14:10:18 (GMT)
commit4911fe3fd94019fcca730710e0b411e8e5a66847 (patch)
treec6c5d4c050675c4924991225f0076aabece3bfb7
parent485e0b2bdcec3c82d6c0b4d7719808a0dfc9289c (diff)
moved websocket session handling to same goroutine
-rw-r--r--src/helsinki.at/rhimportd/ctrlWebSocket.go49
1 files changed, 28 insertions, 21 deletions
diff --git a/src/helsinki.at/rhimportd/ctrlWebSocket.go b/src/helsinki.at/rhimportd/ctrlWebSocket.go
index 93134fd..b3f10f6 100644
--- a/src/helsinki.at/rhimportd/ctrlWebSocket.go
+++ b/src/helsinki.at/rhimportd/ctrlWebSocket.go
@@ -83,7 +83,31 @@ func sendWebSocketErrorResponse(ws *websocket.Conn, code int, err_str string) {
}
}
-func webSocketSessionHandler() {
+func webSocketSessionHandler(reqchan <-chan webSocketRequestData, ws *websocket.Conn) {
+ defer ws.Close()
+
+ select {
+ case reqdata := <-reqchan:
+ switch reqdata.Command {
+ case "new":
+ sendWebSocketErrorResponse(ws, http.StatusNotImplemented, "new session - not yet implemented")
+ return
+ case "reconnect":
+ if reqdata.UserName == "" {
+ sendWebSocketErrorResponse(ws, http.StatusBadRequest, "missing mandotary field LOGIN_NAME")
+ return
+ }
+ if reqdata.Id == "" {
+ sendWebSocketErrorResponse(ws, http.StatusBadRequest, "missing mandotary field ID")
+ return
+ }
+ sendWebSocketErrorResponse(ws, http.StatusNotImplemented, "reconnect session - not yet implemented")
+ return
+ default:
+ sendWebSocketErrorResponse(ws, http.StatusBadRequest, fmt.Sprintf("unknown command '%s'", reqdata.Command))
+ return
+ }
+ }
}
func webSocketHandler(conf *rhimport.Config, rddb *rhimport.RdDbChan, sessions *rhimport.SessionStoreChan, trusted bool, w http.ResponseWriter, r *http.Request) {
@@ -98,6 +122,8 @@ func webSocketHandler(conf *rhimport.Config, rddb *rhimport.RdDbChan, sessions *
return
}
rhdl.Println("WebSocket Client", ws.RemoteAddr(), "connected")
+ reqchan := make(chan webSocketRequestData)
+ go webSocketSessionHandler(reqchan, ws)
for {
reqdata := newWebSocketRequestData(conf)
@@ -109,26 +135,7 @@ func webSocketHandler(conf *rhimport.Config, rddb *rhimport.RdDbChan, sessions *
if trusted {
reqdata.UserName = r.Header.Get("X-Forwarded-User")
}
-
- switch reqdata.Command {
- case "new":
- sendWebSocketErrorResponse(ws, http.StatusNotImplemented, "new session - not yet implemented")
- return
- case "reconnect":
- if reqdata.UserName == "" {
- sendWebSocketErrorResponse(ws, http.StatusBadRequest, "missing mandotary field LOGIN_NAME")
- return
- }
- if reqdata.Id == "" {
- sendWebSocketErrorResponse(ws, http.StatusBadRequest, "missing mandotary field ID")
- return
- }
- sendWebSocketErrorResponse(ws, http.StatusNotImplemented, "get session - not yet implemented")
- return
- default:
- sendWebSocketErrorResponse(ws, http.StatusBadRequest, fmt.Sprintf("unknown command '%s'", reqdata.Command))
- return
- }
+ reqchan <- *reqdata
}
}