package main import ( "io/ioutil" "os" "rocommon" "rocommon/service" _ "rocommon/socket" _ "rocommon/socket/tcp" "roserver/baseserver" "roserver/baseserver/model" _ "roserver/social/model" _ "roserver/social/msg" "runtime" "strconv" "syscall" ) func main() { //记录gate pid用来做关闭操作 sysType := runtime.GOOS if sysType != "windows" { if pid := syscall.Getpid(); pid != 1 { fileName := "social_server.pid" + strconv.Itoa(pid) ioutil.WriteFile(fileName, []byte(strconv.Itoa(pid)), 0777) defer os.Remove(fileName) } } //prof := profile.Start(profile.CPUProfile, profile.ProfilePath("./pprof/social.pprof"), profile.NoShutdownHook) baseserver.Init(model.SERVICE_NODE_TYPE_SOCIAL_STR, nil, nil) //先建立服务器对应的连接,在监听客户端 sConfig := service.GetServiceConfig() //创建监听器 var acceptorNode rocommon.ServerNode = nil if sConfig.Node.Addr != "" { acceptorNode = baseserver.CreateAcceptor(baseserver.ServiceParam{ ServiceType: "tcpAcceptor", ServiceName: model.SERVICE_NODE_TYPE_SOCIAL_STR, ProcName: "common.backend", LisAddr: sConfig.Node.Addr, }, sConfig) } for _, concern := range sConfig.Node.Concern { //建立需要链接的服务器,通过服务器发现etcd来处理(包含在了CreateConnector中) baseserver.CreateConnector(baseserver.ServiceParam{ DiscoveryServiceName: concern, DiscoveryServiceZone: sConfig.Node.Zone, ServiceType: "tcpConnector", ServiceName: model.SERVICE_NODE_TYPE_SOCIAL_STR, ProcName: "social.backend", }) } baseserver.Wait() //prof.Stop() baseserver.Exit(acceptorNode) }