From a0a531cdd2a406fa2337e0429e3af2f8d39d627c Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Thu, 24 Jan 2019 19:19:57 -0500 Subject: [PATCH] mnet: add MListener.CloseOnStop, to allow for http.Server.Shutdown (and other entities) closing the listener instead --- mnet/mnet.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mnet/mnet.go b/mnet/mnet.go index 794ee4a..c602823 100644 --- a/mnet/mnet.go +++ b/mnet/mnet.go @@ -16,6 +16,10 @@ import ( type MListener struct { net.Listener log *mlog.Logger + + // If set to true before mrun's stop event is run, the stop event will not + // cause the MListener to be closed. + NoCloseOnStop bool } // MListen returns an MListener which will be initialized when the start event @@ -48,6 +52,9 @@ func MListen(ctx mctx.Context, network, defaultAddr string) *MListener { // TODO track connections and wait for them to complete before shutting // down? mrun.OnStop(ctx, func(mctx.Context) error { + if l.NoCloseOnStop { + return nil + } l.log.Info("stopping listener") return l.Close() })