diff options
author | Christian Pointner <equinox@helsinki.at> | 2015-12-30 15:11:32 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2015-12-30 15:11:32 (GMT) |
commit | a81d48a3beef8b63fd19cc272a6388ad9e21bb4c (patch) | |
tree | 712787dcd19c2d2d1b5d4f26feca78f88c37ac87 /src/helsinki.at/rhimportd/ctrlWebSocket.go | |
parent | b4165f9269cb71ccb20e9b525c06951e0033ea2b (diff) |
reconnecting session works now
Diffstat (limited to 'src/helsinki.at/rhimportd/ctrlWebSocket.go')
-rw-r--r-- | src/helsinki.at/rhimportd/ctrlWebSocket.go | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/helsinki.at/rhimportd/ctrlWebSocket.go b/src/helsinki.at/rhimportd/ctrlWebSocket.go index df58f3f..346dd6a 100644 --- a/src/helsinki.at/rhimportd/ctrlWebSocket.go +++ b/src/helsinki.at/rhimportd/ctrlWebSocket.go @@ -160,6 +160,23 @@ func (self *webSocketSession) startNewSession(reqdata *webSocketRequestData, con return http.StatusOK, "SUCCESS" } +func (self *webSocketSession) reconnectSession(reqdata *webSocketRequestData, sessions *rhimport.SessionStoreChan) (int, string) { + s, code, errstring := sessions.Get(reqdata.UserName, reqdata.Id) + if code != http.StatusOK { + return code, errstring + } + self.id = reqdata.Id + self.session = s + if err := s.AddDoneHandler(self, webSocketDone); err != nil { + return http.StatusInternalServerError, err.Error() + } + if err := s.AddProgressHandler(self, webSocketProgress); err != nil { + return http.StatusInternalServerError, err.Error() + } + s.Run(time.Duration(reqdata.Timeout) * time.Second) + return http.StatusOK, "SUCCESS" +} + func webSocketSessionHandler(reqchan <-chan webSocketRequestData, ws *websocket.Conn, conf *rhimport.Config, rddb *rhimport.RdDbChan, sessions *rhimport.SessionStoreChan) { defer ws.Close() @@ -194,8 +211,13 @@ func webSocketSessionHandler(reqchan <-chan webSocketRequestData, ws *websocket. sendWebSocketErrorResponse(ws, "", http.StatusBadRequest, "This connection already handles a session") return } - sendWebSocketErrorResponse(ws, "", http.StatusNotImplemented, "reconnect session - not yet implemented") - return + code, errstring := session.reconnectSession(&reqdata, sessions) + if code != http.StatusOK { + sendWebSocketErrorResponse(ws, "", code, errstring) + return + } else { + sendWebSocketResponse(ws, &webSocketResponseData{ResponseCode: code, Type: "ACK", Id: session.id}) + } default: sendWebSocketErrorResponse(ws, "", http.StatusBadRequest, fmt.Sprintf("unknown command '%s'", reqdata.Command)) return |