From 1bf07d6b588573d13471dfc0a41bc3cfcc4f79dd Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Mon, 12 May 2014 21:15:18 -0300 Subject: [PATCH] Write response before shutting down --- cmd/syncthing/gui.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/syncthing/gui.go b/cmd/syncthing/gui.go index ac89d6f7d..c5aa4b31c 100644 --- a/cmd/syncthing/gui.go +++ b/cmd/syncthing/gui.go @@ -157,19 +157,28 @@ func restGetConfigInSync(w http.ResponseWriter) { json.NewEncoder(w).Encode(map[string]bool{"configInSync": configInSync}) } -func restPostRestart() { +func restPostRestart(w http.ResponseWriter) { + flushResponse(`{"ok": "restarting"}`, w) go restart() } -func restPostReset() { +func restPostReset(w http.ResponseWriter) { + flushResponse(`{"ok": "resetting repos"}`, w) resetRepositories() go restart() } -func restPostShutdown() { +func restPostShutdown(w http.ResponseWriter) { + flushResponse(`{"ok": "shutting down"}`, w) go shutdown() } +func flushResponse(s string, w http.ResponseWriter) { + w.Write([]byte(s + "\n")) + f := w.(http.Flusher) + f.Flush() +} + var cpuUsagePercent [10]float64 // The last ten seconds var cpuUsageLock sync.RWMutex