func (s *RaftServer) startServe() {
	rpcServer := rpc.NewServer()
	if err := rpcServer.Register(raftrpc.NewRaftService(s)); err != nil {
		panic(err)
	}
	listener, err := net.ListenTCP("tcp", s.ServerConf.Info.ServerAddr)
	if err != nil {
		panic("Fail to start RaftServer: " + err.Error())
	}
	//rpc.Accept(listener)
	countlog.Info(fmt.Sprintf("%s started", s))
stopServeLoop:
	for {
		select {
		case sig := <-s.sigs:
			s.handleSignal(sig)
			break stopServeLoop
		case <-s.stopSignal:
			break stopServeLoop
		default:
			conn, err := listener.Accept()
			if err != nil {
				countlog.Error("RaftServer is busy", "error", err)
				continue
			}
			countlog.Debug(fmt.Sprintf("%s localPort %s, remotePort %s", s, conn.LocalAddr(), conn.RemoteAddr()))
			go rpcServer.ServeConn(conn)
		}
	}
	if err := listener.Close(); err != nil {
		countlog.Error("event!listener close error", "err", err)
	}
	countlog.Info(fmt.Sprintf("%s stoped", s))
}
// startServe starts listening to port and handles requests
startServe starts listening to port and handles requests
// startServe starts listening to port and handles requests
func (s *RaftServer) startServe() {
	rpcServer := rpc.NewServer()
	if err := rpcServer.Register(raftrpc.NewRaftService(s)); err != nil {
		panic(err)
	}
	listener, err := net.ListenTCP("tcp", s.ServerConf.Info.ServerAddr)
	if err != nil {
		panic("Fail to start RaftServer: " + err.Error())
	}
	countlog.Info(fmt.Sprintf("%s started", s))
stopServeLoop:
	for {
		select {
		case sig := <-s.sigs:
			s.handleSignal(sig)
			break stopServeLoop
		case <-s.stopSignal:
			break stopServeLoop
		default:
			conn, err := listener.Accept()
			if err != nil {
				countlog.Error("RaftServer is busy", "error", err)
				continue
			}
			countlog.Debug(fmt.Sprintf("%s localPort %s, remotePort %s", s, conn.LocalAddr(), conn.RemoteAddr()))
			go rpcServer.ServeConn(conn)
		}
	}
	if err := listener.Close(); err != nil {
		countlog.Error("event!listener close error", "err", err)
	}
	countlog.Info(fmt.Sprintf("%s stoped", s))
}
func ( s * RaftServer ) startServe ( ) { rpcServer := rpc . NewServer ( ) if err := rpcServer . Register ( raftrpc . NewRaftService ( s ) ) ; err != nil { panic ( err ) } listener , err := net . ListenTCP ( " " , s . ServerConf . Info . ServerAddr ) if err != nil { panic ( " " + err . Error ( ) ) } countlog . Info ( fmt . Sprintf ( " " , s ) ) stopServeLoop : for { select { case sig := <- s . sigs : s . handleSignal ( sig ) break stopServeLoop case <- s . stopSignal : break stopServeLoop default : conn , err := listener . Accept ( ) if err != nil { countlog . Error ( " " , " " , err ) continue } countlog . Debug ( fmt . Sprintf ( " " , s , conn . LocalAddr ( ) , conn . RemoteAddr ( ) ) ) go rpcServer . ServeConn ( conn ) } } if err := listener . Close ( ) ; err != nil { countlog . Error ( " " , " " , err ) } countlog . Info ( fmt . Sprintf ( " " , s ) ) }
startServe starts listening to port and handles requests
startServe starts listening to port and handles requests
//rpc.Accept(listener)