mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 10:41:03 +01:00
change the ListenToServer to SecondaryListen which comes before the main listen, they are non-blocking funcs now
This commit is contained in:
parent
20cd75139a
commit
65184ddaca
57
iris.go
57
iris.go
|
@ -90,7 +90,7 @@ type (
|
||||||
ListenUNIXWithErr(string, os.FileMode) error
|
ListenUNIXWithErr(string, os.FileMode) error
|
||||||
ListenUNIX(string, os.FileMode)
|
ListenUNIX(string, os.FileMode)
|
||||||
NoListen() *Server
|
NoListen() *Server
|
||||||
ListenToServer(config.Server) (*Server, error)
|
SecondaryListen(config.Server) *Server
|
||||||
Close()
|
Close()
|
||||||
// global middleware prepending, registers to all subdomains, to all parties, you can call it at the last also
|
// global middleware prepending, registers to all subdomains, to all parties, you can call it at the last also
|
||||||
MustUse(...Handler)
|
MustUse(...Handler)
|
||||||
|
@ -554,52 +554,57 @@ func (s *Framework) TemplateString(templateFile string, pageContext interface{},
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListenToServer starts a 'secondary' server which listens to this station
|
// SecondaryListen starts a server which listens to this station
|
||||||
// this server will not be the main server (unless it's the first listen)
|
|
||||||
// Note that the view engine's functions {{ url }} and {{ urlpath }} will return the first's registered server's scheme (http/https)
|
// Note that the view engine's functions {{ url }} and {{ urlpath }} will return the first's registered server's scheme (http/https)
|
||||||
//
|
//
|
||||||
// this is useful only when you want to have two listen ports ( two servers ) for the same station
|
// this is useful only when you want to have two or more listening ports ( two or more servers ) for the same station
|
||||||
//
|
//
|
||||||
// receives one parameter which is the config.Server for the new server
|
// receives one parameter which is the config.Server for the new server
|
||||||
// returns the new standalone server( you can close this server by this reference) and an error
|
// returns the new standalone server( you can close this server by the returning reference)
|
||||||
//
|
//
|
||||||
// If you have only one scheme this function is useless for you, instead you can use the normal .Listen/ListenTLS functions.
|
// If you need only one server this function is not for you, instead you must use the normal .Listen/ListenTLS functions.
|
||||||
//
|
//
|
||||||
// this is a blocking version, like .Listen/ListenTLS
|
// this is a NOT A BLOCKING version, the main iris.Listen should be always executed LAST, so this function goes before the main .Listen.
|
||||||
func ListenToServer(cfg config.Server) (*Server, error) {
|
func SecondaryListen(cfg config.Server) *Server {
|
||||||
return Default.ListenToServer(cfg)
|
return Default.SecondaryListen(cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListenToServer starts a server which listens to this station
|
// SecondaryListen starts a server which listens to this station
|
||||||
// Note that the view engine's functions {{ url }} and {{ urlpath }} will return the first's registered server's scheme (http/https)
|
// Note that the view engine's functions {{ url }} and {{ urlpath }} will return the first's registered server's scheme (http/https)
|
||||||
//
|
//
|
||||||
// this is useful only when you want to have two listen ports ( two servers ) for the same station
|
// this is useful only when you want to have two or more listening ports ( two or more servers ) for the same station
|
||||||
//
|
//
|
||||||
// receives one parameter which is the config.Server for the new server
|
// receives one parameter which is the config.Server for the new server
|
||||||
// returns the new standalone server( you can close this server by this reference) and an error
|
// returns the new standalone server( you can close this server by the returning reference)
|
||||||
//
|
//
|
||||||
// If you have only one scheme this function is useless for you, instead you can use the normal .Listen/ListenTLS functions.
|
// If you need only one server this function is not for you, instead you must use the normal .Listen/ListenTLS functions.
|
||||||
//
|
//
|
||||||
// this is a blocking version, like .Listen/ListenTLS
|
// this is a NOT A BLOCKING version, the main iris.Listen should be always executed LAST, so this function goes before the main .Listen.
|
||||||
func (s *Framework) ListenToServer(cfg config.Server) (*Server, error) {
|
func (s *Framework) SecondaryListen(cfg config.Server) *Server {
|
||||||
|
/*This not suits us because if prelisten plugins makes a lot of time to execute then the IsListening is false after 3 seconds (if the plugins have much work to do)
|
||||||
time.Sleep(time.Duration(3) * time.Second) // yes we wait, so simple, because the previous will run on goroutine
|
time.Sleep(time.Duration(3) * time.Second) // yes we wait, so simple, because the previous will run on goroutine
|
||||||
// if the main server is not yet started, then this is the main server
|
// if the main server is not yet started, then this is the main server
|
||||||
// although this function should not be used to Listen to the main server, but if so then do it right:
|
// although this function should not be used to Listen to the main server, but if so then do it right:
|
||||||
if !s.HTTPServer.IsListening() {
|
if !s.HTTPServer.IsListening() {
|
||||||
s.HTTPServer.Config = &cfg
|
s.HTTPServer.Config = &cfg
|
||||||
err := s.openServer()
|
s.openServer()
|
||||||
return s.HTTPServer, err
|
return s.HTTPServer
|
||||||
}
|
}*/
|
||||||
|
|
||||||
srv := newServer(&cfg)
|
srv := newServer(&cfg)
|
||||||
srv.Handler = s.HTTPServer.Handler
|
// add a post listen event to start this server after the previous started
|
||||||
err := srv.Open()
|
s.Plugins.Add(PostListenFunc(func(*Framework) {
|
||||||
if err == nil {
|
go func() { // goroutine in order to not block any runtime post listeners
|
||||||
ch := make(chan os.Signal)
|
srv.Handler = s.HTTPServer.Handler
|
||||||
<-ch
|
if err := srv.Open(); err == nil {
|
||||||
srv.Close()
|
ch := make(chan os.Signal)
|
||||||
}
|
<-ch
|
||||||
return srv, err
|
srv.Close()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}))
|
||||||
|
|
||||||
|
return srv
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue
Block a user