Services no longer print out errors when they shut down

This commit is contained in:
Sasha Koshka 2023-05-31 22:00:21 -04:00
parent 92b645f34c
commit c9f2c56d65
3 changed files with 33 additions and 5 deletions

View File

@ -11,6 +11,8 @@ type Server struct {
underlying net.Listener underlying net.Listener
Config config.Config Config config.Config
Router *router.Router Router *router.Router
running bool
} }
func (server *Server) Run () (err error) { func (server *Server) Run () (err error) {
@ -19,16 +21,24 @@ func (server *Server) Run () (err error) {
config.TLSConfigFor(server.Config)) config.TLSConfigFor(server.Config))
if err != nil { return err } if err != nil { return err }
server.running = true
log.Println(".// router on", server.underlying.Addr()) log.Println(".// router on", server.underlying.Addr())
for { for {
conn, err := server.underlying.Accept() 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()) log.Println("-=E incoming connection from", conn.RemoteAddr())
server.Router.Accept(conn) server.Router.Accept(conn)
} }
} }
func (server *Server) Shutdown () error { func (server *Server) Shutdown () error {
server.running = false
return server.underlying.Close() return server.underlying.Close()
} }

View File

@ -9,6 +9,8 @@ type Server struct {
underlying *http.Server underlying *http.Server
Config config.Config Config config.Config
Handler http.Handler Handler http.Handler
running bool
} }
func (server *Server) Run () error { func (server *Server) Run () error {
@ -22,10 +24,17 @@ func (server *Server) Run () error {
Handler: server.Handler, Handler: server.Handler,
} }
server.running = true
log.Println(".// https on", server.underlying.Addr) 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 { func (server *Server) Shutdown () error {
server.running = false
return server.underlying.Close() return server.underlying.Close()
} }

View File

@ -19,11 +19,13 @@ type HTTP struct {
Handler http.Handler Handler http.Handler
conn *Conn conn *Conn
running bool
requests requestManager requests requestManager
} }
// Close closes the mount abruptly, interrupting any active connections. // Close closes the mount abruptly, interrupting any active connections.
func (htmount *HTTP) Close () error { func (htmount *HTTP) Close () error {
htmount.running = false
return htmount.conn.Close() return htmount.conn.Close()
} }
@ -45,11 +47,18 @@ func (htmount *HTTP) Run (service ServiceInfo) (err error) {
htmount.conn, err = Dial(htmount.MountInfo, service) htmount.conn, err = Dial(htmount.MountInfo, service)
if err != nil { return } if err != nil { return }
htmount.running = true
htmount.requests.init() htmount.requests.init()
for { for {
message, err := htmount.conn.Receive() message, err := htmount.conn.Receive()
if err != nil { return err } if err != nil {
if htmount.running {
return err
} else {
return nil
}
}
switch message.(type) { switch message.(type) {
case protocol.MessageHTTPRequest: case protocol.MessageHTTPRequest: