Exemple #1
0
func main() {
	flag.Parse()
	if err := InitConfig(); err != nil {
		panic(err)
	}
	log.LoadConfiguration(Conf.Log)
	runtime.GOMAXPROCS(runtime.NumCPU())
	//comet
	if err := InitComet(Conf.Comets); err != nil {
		log.Warn("comet rpc current can't connect, retry")
	}
	//round
	round := NewRound(RoundOptions{
		Timer:     Conf.Timer,
		TimerSize: Conf.TimerSize,
	})
	//room
	InitRoomBucket(round,
		RoomOptions{
			BatchNum:   Conf.RoomBatch,
			SignalTime: Conf.RoomSignal,
		})
	//room info
	MergeRoomServers()
	go SyncRoomServers()
	InitPush()
	if err := InitKafka(); err != nil {
		panic(err)
	}
	// block until a signal is received.
	InitSignal()
}
Exemple #2
0
func main() {
	flag.Parse()
	if err := InitConfig(); err != nil {
		panic(err)
	}
	runtime.GOMAXPROCS(Conf.MaxProc)
	log.LoadConfiguration(Conf.Log)
	defer log.Close()
	if Conf.Type == ProtoTCP {
		initTCP()
	} else if Conf.Type == ProtoWebsocket {
		initWebsocket()
	} else if Conf.Type == ProtoWebsocketTLS {
		initWebsocketTLS()
	}
}
Exemple #3
0
func main() {
	flag.Parse()
	if err := InitConfig(); err != nil {
		panic(err)
	}
	Debug = Conf.Debug
	runtime.GOMAXPROCS(Conf.MaxProc)
	log.LoadConfiguration(Conf.Log)
	defer log.Close()
	log.Info("comet[%s] start", Ver)
	perf.Init(Conf.PprofBind)
	// init slow log
	// TODO need to performance optimizition, so stop to use slow log
	/*if err := initSlowLog(Conf.SlowLog); err != nil {
		panic(err)
	}*/
	// logic rpc
	if err := InitLogicRpc(Conf.LogicAddr); err != nil {
		log.Warn("logic rpc current can't connect, retry")
	}
	// new server
	buckets := make([]*Bucket, Conf.Bucket)
	for i := 0; i < Conf.Bucket; i++ {
		buckets[i] = NewBucket(BucketOptions{
			ChannelSize:   Conf.BucketChannel,
			RoomSize:      Conf.BucketRoom,
			RoutineAmount: Conf.RoutineAmount,
			RoutineSize:   Conf.RoutineSize,
		}, RoomOptions{
			ChannelSize: Conf.RoomChannel,
		})
	}
	round := NewRound(RoundOptions{
		Reader:       Conf.TCPReader,
		ReadBuf:      Conf.TCPReadBuf,
		ReadBufSize:  Conf.TCPReadBufSize,
		Writer:       Conf.TCPWriter,
		WriteBuf:     Conf.TCPWriteBuf,
		WriteBufSize: Conf.TCPWriteBufSize,
		Timer:        Conf.Timer,
		TimerSize:    Conf.TimerSize,
	})
	operator := new(DefaultOperator)
	DefaultServer = NewServer(buckets, round, operator, ServerOptions{
		CliProto:         Conf.CliProto,
		SvrProto:         Conf.SvrProto,
		HandshakeTimeout: Conf.HandshakeTimeout,
		TCPKeepalive:     Conf.TCPKeepalive,
		TCPRcvbuf:        Conf.TCPRcvbuf,
		TCPSndbuf:        Conf.TCPSndbuf,
	})
	// tcp comet
	if err := InitTCP(Conf.TCPBind, Conf.MaxProc); err != nil {
		panic(err)
	}
	// websocket comet
	if err := InitWebsocket(Conf.WebsocketBind); err != nil {
		panic(err)
	}
	// flash safe policy
	if Conf.FlashPolicyOpen {
		if err := InitFlashPolicy(); err != nil {
			panic(err)
		}
	}
	// wss comet
	if Conf.WebsocketTLSOpen {
		if err := InitWebsocketWithTLS(Conf.WebsocketTLSBind, Conf.WebsocketCertFile, Conf.WebsocketPrivateFile); err != nil {
			panic(err)
		}
	}
	// start rpc
	if err := InitRPCPush(Conf.RPCPushAddrs); err != nil {
		panic(err)
	}
	// block until a signal is received.
	InitSignal()
}