Exemple #1
0
func (rs *rodisServer) Close() {
	log6.Info("Server is closing...")
	if rs.started {
		close(rs.quit)
		rs.listener.Close()

		rs.mu.Lock()
		for _, rc := range rs.conns {
			rc.close()
		}
		rs.mu.Unlock()

		rs.started = false
	}
	log6.Info("Server is down.")
}
Exemple #2
0
func (rs *rodisServer) Run() {
	log6.Info("Server is starting, listen on %v", rs.cfg.Listen)

	listener, err := net.Listen("tcp", rs.cfg.Listen)
	if err != nil {
		log6.Fatal("Server listen on %v failure: %v", rs.cfg.Listen, err)
		return
	}

	rs.listener = listener
	rs.started = true

	for {
		conn, err := rs.listener.Accept()
		if err != nil {
			select {
			case <-rs.quit:
				return
			default:
				log6.Warn("Server accepts connection error: %v", err)
			}
			continue
		}

		go newConnection(conn, rs)
	}
}