diff --git a/cmd/router/srvhnakra/hnakra.go b/cmd/router/srvhnakra/hnakra.go index 71bbde4..653eada 100644 --- a/cmd/router/srvhnakra/hnakra.go +++ b/cmd/router/srvhnakra/hnakra.go @@ -11,6 +11,8 @@ type Server struct { underlying net.Listener Config config.Config Router *router.Router + + running bool } func (server *Server) Run () (err error) { @@ -18,17 +20,25 @@ func (server *Server) Run () (err error) { "tcp", fmt.Sprint(":", server.Config.RouterPort()), config.TLSConfigFor(server.Config)) if err != nil { return err } - + + server.running = true log.Println(".// router on", server.underlying.Addr()) for { conn, err := server.underlying.Accept() - if err != nil { return err } + if err != nil { + if server.running { + return err + } else { + return nil + } + } log.Println("-=E incoming connection from", conn.RemoteAddr()) server.Router.Accept(conn) } } func (server *Server) Shutdown () error { + server.running = false return server.underlying.Close() } diff --git a/cmd/router/srvhttps/https.go b/cmd/router/srvhttps/https.go index 9539d72..05a7c57 100644 --- a/cmd/router/srvhttps/https.go +++ b/cmd/router/srvhttps/https.go @@ -9,6 +9,8 @@ type Server struct { underlying *http.Server Config config.Config Handler http.Handler + + running bool } func (server *Server) Run () error { @@ -22,10 +24,17 @@ func (server *Server) Run () error { Handler: server.Handler, } + server.running = true log.Println(".// https on", server.underlying.Addr) - return server.underlying.ListenAndServeTLS("", "") + err := server.underlying.ListenAndServeTLS("", "") + if server.running { + return err + } else { + return nil + } } func (server *Server) Shutdown () error { + server.running = false return server.underlying.Close() } diff --git a/service/http.go b/service/http.go index 31b0ecd..b8ceefa 100644 --- a/service/http.go +++ b/service/http.go @@ -19,11 +19,13 @@ type HTTP struct { Handler http.Handler conn *Conn + running bool requests requestManager } // Close closes the mount abruptly, interrupting any active connections. func (htmount *HTTP) Close () error { + htmount.running = false return htmount.conn.Close() } @@ -44,12 +46,19 @@ func (htmount *HTTP) Run (service ServiceInfo) (err error) { } htmount.conn, err = Dial(htmount.MountInfo, service) if err != nil { return } - + + htmount.running = true htmount.requests.init() for { message, err := htmount.conn.Receive() - if err != nil { return err } + if err != nil { + if htmount.running { + return err + } else { + return nil + } + } switch message.(type) { case protocol.MessageHTTPRequest: