Example #1
0
func (o *Object) safeTick() {
	defer utils.DumpStackIfPanic("Object::OnTick")

	if o.sinker != nil {
		o.sinker.OnTick()
	}
}
Example #2
0
func (o *Object) safeStop() {
	defer utils.DumpStackIfPanic("Object::OnStop")

	if o.sinker != nil {
		o.sinker.OnStop()
	}
}
Example #3
0
func (a *WsAcceptor) start() (err error) {
	http.Handle(a.sc.Path, http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
		defer utils.DumpStackIfPanic("ws.HandlerFunc")
		if req.Method != "GET" {
			http.Error(res, "method not allowed", 405)
			return
		}
		ws, err := a.upgrader.Upgrade(res, req, nil)
		if _, ok := err.(websocket.HandshakeError); ok {
			http.Error(res, "Not a websocket handshake", 400)
			return
		} else if err != nil {
			http.Error(res, fmt.Sprintf("%v", err), 500)
			logger.Error(err)
			return
		}
		ws.SetPongHandler(func(string) error {
			ws.SetReadDeadline(time.Now().Add(readWait))
			return nil
		})
		s := newWsSession(a.idGen.NextId(), ws, a.sc, a)
		s.FireConnectEvent()
		s.start()
		a.acptChan <- s
	}))
	go func() {
		service := a.sc.Ip + ":" + strconv.Itoa(int(a.sc.Port))
		err := http.ListenAndServe(service, nil)
		if err != nil {
			logger.Error(err)
		}
	}()

	return nil
}
Example #4
0
func (o *Object) safeDone(cmd Command) {
	defer utils.DumpStackIfPanic("Object::Command::Done")
	err := cmd.Done(o)
	if err != nil {
		panic(err)
	}
}
Example #5
0
func (this *ModuleEntity) safeUpt(nowTime time.Time) {
	defer utils.DumpStackIfPanic("ModuleEntity.safeTick")

	if nowTime.Sub(this.lastTick) > this.tickInterval {
		this.module.Update()
		this.lastTick = nowTime
	}
}
Example #6
0
// Healthcheck is a http.Handler calling health checking and showing the result.
// it's in "/healthcheck" pattern in admin module.
func Healthcheck(rw http.ResponseWriter, req *http.Request) {
	defer utils.DumpStackIfPanic("Admin Healthcheck")
	for name, h := range utils.AdminCheckList {
		if err := h.Check(); err == nil {
			fmt.Fprintf(rw, "%s : ok\n", name)
		} else {
			fmt.Fprintf(rw, "%s : %s\n", name, err.Error())
		}
	}
}
Example #7
0
func (e *NetEngine) Update() {
	defer utils.DumpStackIfPanic("NetEngine.Update")

	watch := profile.TimeStatisticMgr.WatchStart(e.ModuleName())
	defer watch.Stop()

	e.clearClosedIo()

	for _, v := range e.pool {
		v.update()
	}
}
Example #8
0
func (tk *Task) Run() error {
	defer utils.DumpStackIfPanic("Task Run")
	core.CoreObject().Waitor.Add(1)
	defer core.CoreObject().Waitor.Done()

	err := tk.DoFunc()
	if err != nil {
		if tk.ErrLimit > 0 && tk.ErrLimit > len(tk.Errlist) {
			tk.Errlist = append(tk.Errlist, &taskerr{t: tk.Next, errinfo: err.Error()})
		}
	}
	return err
}
Example #9
0
func (this *action) do() {
	defer FreeAction(this)
	defer utils.DumpStackIfPanic(fmt.Sprintf("netlib.session.task.do exe error, packet type:%v", reflect.TypeOf(this.p)))

	watch := profile.TimeStatisticMgr.WatchStart(this.n)
	defer watch.Stop()

	h := GetHandler(this.packid)
	if h != nil {
		err := h.Process(this.s, this.p)
		if err != nil {
			logger.Infof("%v process error %v", this.n, err)
		}
	} else {
		logger.Infof("%v not registe handler", this.n)
	}
}
Example #10
0
func (t *Task) run() (e error) {
	defer utils.DumpStackIfPanic("Task::run")

	t.tStart = time.Now()
	ret := t.c.Call()

	if t.r != nil {
		t.r <- ret
	}

	if t.n != nil {
		SendTaskRes(t.s, t)
	}
	if t.name != "" {
		tNow := time.Now()
		logger.Info("task [", t.name, "] since createTime(", tNow.Sub(t.tCreate), ") since startTime(", tNow.Sub(t.tStart), ")")
	}
	return nil
}
Example #11
0
func (this *ModuleEntity) safeShutdown(shutWaitAck chan<- interface{}) {
	defer utils.DumpStackIfPanic("ModuleEntity.safeShutdown")
	this.module.Shutdown()
}