Пример #1
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)
	}
}
Пример #2
0
func (rc *rodisConn) handle() {
	for {
		respType, respValue, err := resp.Parse(rc.reader)
		if err != nil {
			select {
			case <-rc.server.quit: // Server is quit, rc.close() is called.
				return
			default:
				break
			}

			if err == io.EOF { // Client close the connection
				log6.Debug("Client close connection %v.", rc.uuid)
				rc.close()
				return
			} else {
				log6.Warn("Connection %v error: %v", rc.uuid, err)
				continue // Other error, should continue the connection
			}
		}

		rc.response(respType, respValue)
	}
}