tImplement more control over the HTTP server. - tordam - A library for peer discovery inside the Tor network (HTM) git clone https://git.parazyd.org/tordam (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit 3012518656357a46673a8e8923904a47db798641 (DIR) parent c3cd139062b5450dbf4e37bf51415fb3ba75a590 (HTM) Author: parazyd <parazyd@dyne.org> Date: Tue, 12 Dec 2017 13:07:02 +0100 Implement more control over the HTTP server. Diffstat: M cmd/dam-dir/main.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) --- (DIR) diff --git a/cmd/dam-dir/main.go b/cmd/dam-dir/main.go t@@ -150,6 +150,7 @@ func handleElse(rw http.ResponseWriter, request *http.Request) { func main() { var wg sync.WaitGroup + // Chdir to our working directory. if _, err := os.Stat(lib.Cwd); os.IsNotExist(err) { err := os.Mkdir(lib.Cwd, 0700) lib.CheckError(err) t@@ -162,12 +163,18 @@ func main() { startRedis() } - http.HandleFunc("/announce", handlePost) - http.HandleFunc("/", handleElse) - + mux := http.NewServeMux() + mux.HandleFunc("/announce", handlePost) + mux.HandleFunc("/", handleElse) + srv := &http.Server{ + Addr: ListenAddress, + Handler: mux, + ReadTimeout: 30 * time.Second, + WriteTimeout: 30 * time.Second, + } wg.Add(1) - go http.ListenAndServe(ListenAddress, nil) + go srv.ListenAndServe() log.Println("Listening on", ListenAddress) - wg.Wait() + os.Exit(1) }