Skip to content

Commit

Permalink
Add graceful leaving for cc server
Browse files Browse the repository at this point in the history
  • Loading branch information
prairir committed Nov 27, 2021
1 parent 39531ad commit 1efd336
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cc-server/cc-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ port: 80
# a AM/PM marker
# Example:
# 11:30AM
trigger-time: "4:00PM"
trigger-time: "4:30PM"
# length of trigger period
# time can be represented with its symbols
# Example:
Expand Down
11 changes: 6 additions & 5 deletions cc-server/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ func wsHandler(w http.ResponseWriter, r *http.Request) {
for {
mt, message, err := conn.ReadMessage()
if err != nil {
if e, ok := err.(*websocket.CloseError); ok &&
(e.Code == websocket.CloseNormalClosure ||
e.Code == websocket.CloseNoStatusReceived) {
log.Infof("Connect %s leaving", r.RemoteAddr)
break
}
log.Errorf("fatal read error: %s", err)
break
}

// if connection closes
if mt == websocket.CloseNormalClosure {
break
}

// init handler
if mt == websocket.TextMessage && string(message[:5]) == "init:" {
err = handler.Init(message, conn)
Expand Down

0 comments on commit 1efd336

Please sign in to comment.