summaryrefslogtreecommitdiff
path: root/src/helsinki.at/rhimportd
diff options
context:
space:
mode:
Diffstat (limited to 'src/helsinki.at/rhimportd')
-rw-r--r--src/helsinki.at/rhimportd/ctrlWebSocket.go26
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