示例#1
0
文件: acceptor.go 项目: hycxa/gommo
func (a *acceptor) Run() {
	defer a.Stopped()
	defer a.Listener.Close()

	for !a.StopRequested() {
		conn, err := a.Listener.Accept()
		if err == nil {
			a.NewAgent(conn)
		} else {
			ext.LogError(err)
			break
		}
	}
}
示例#2
0
文件: runner.go 项目: hycxa/gommo
func (r *stopper) Stop() {
	r.stopRequested = true
	timeout := make(chan bool)
	go func() {
		time.Sleep(2 * time.Second)
		timeout <- true
	}()
	select {
	case <-r.stopped:
		return
	case <-timeout:
		ext.LogError(errors.New("Timeout when stopping!"))
	}
}