MCPcopy
hub / github.com/q191201771/lal / RunLoop

Method RunLoop

pkg/logic/server_manager__.go:164–353  ·  view source on GitHub ↗

----- implement ILalServer interface --------------------------------------------------------------------------------

()

Source from the content-addressed store, hash-verified

162// ----- implement ILalServer interface --------------------------------------------------------------------------------
163
164func (sm *ServerManager) RunLoop() error {
165 // TODO(chef): 作为阻塞函数,外部只能获取失败或结束的信息,没法获取到启动成功的信息
166
167 sm.nhOnServerStart(sm.StatLalInfo())
168
169 if sm.pprofServer != nil {
170 go func() {
171 //Log.Warn("start fgprof.")
172 //http.DefaultServeMux.Handle("/debug/fgprof", fgprof.Handler())
173 Log.Infof("start web pprof listen. addr=%s", sm.config.PprofConfig.Addr)
174 if err := sm.pprofServer.ListenAndServe(); err != nil {
175 Log.Error(err)
176 }
177 }()
178 }
179
180 go base.RunSignalHandler(func() {
181 sm.Dispose()
182 })
183
184 var addMux = func(config CommonHttpServerConfig, handler base.Handler, name string) error {
185 if config.Enable {
186 err := sm.httpServerManager.AddListen(
187 base.LocalAddrCtx{Addr: config.HttpListenAddr},
188 config.UrlPattern,
189 handler,
190 )
191 if err != nil {
192 Log.Errorf("add http listen for %s failed. addr=%s, pattern=%s, err=%+v", name, config.HttpListenAddr, config.UrlPattern, err)
193 return err
194 }
195 Log.Infof("add http listen for %s. addr=%s, pattern=%s", name, config.HttpListenAddr, config.UrlPattern)
196 }
197 if config.EnableHttps {
198 err := sm.httpServerManager.AddListen(
199 base.LocalAddrCtx{IsHttps: true, Addr: config.HttpsListenAddr, CertFile: config.HttpsCertFile, KeyFile: config.HttpsKeyFile},
200 config.UrlPattern,
201 handler,
202 )
203 if err != nil {
204 Log.Errorf("add https listen for %s failed. addr=%s, pattern=%s, err=%+v", name, config.HttpsListenAddr, config.UrlPattern, err)
205 } else {
206 Log.Infof("add https listen for %s. addr=%s, pattern=%s", name, config.HttpsListenAddr, config.UrlPattern)
207 }
208 }
209 return nil
210 }
211
212 if err := addMux(sm.config.HttpflvConfig.CommonHttpServerConfig, sm.httpServerHandler.ServeSubSession, "httpflv"); err != nil {
213 return err
214 }
215 if err := addMux(sm.config.HttptsConfig.CommonHttpServerConfig, sm.httpServerHandler.ServeSubSession, "httpts"); err != nil {
216 return err
217 }
218 if err := addMux(sm.config.HlsConfig.CommonHttpServerConfig, sm.serveHls, "hls"); err != nil {
219 return err
220 }
221

Callers 1

entryFunction · 0.95

Calls 15

nhOnServerStartMethod · 0.95
StatLalInfoMethod · 0.95
DisposeMethod · 0.95
StatAllGroupMethod · 0.95
nhOnUpdateMethod · 0.95
RunSignalHandlerFunction · 0.92
AddListenMethod · 0.80
IsInactiveMethod · 0.80
TickMethod · 0.80
StringifyDebugStatsMethod · 0.80
RunLoopMethod · 0.65
IterateMethod · 0.65

Tested by

no test coverage detected