/
comet.go
51 lines (43 loc) · 1.05 KB
/
comet.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright © 2014 Alienero. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"flag"
"os"
"runtime"
"runtime/pprof"
"github.com/Alienero/quick-know/signal"
"github.com/golang/glog"
)
func main() {
glog.Info("Comet Server:Loading...")
b := flag.Bool("benchmark", false, "")
runtime.GOMAXPROCS(runtime.NumCPU())
flag.Parse()
if *b {
glog.Info("Benchmark Mode")
// Creat a file
f, err := os.Create("pprof")
if err != nil {
glog.Fatal(err)
}
if err = pprof.StartCPUProfile(f); err != nil {
glog.Fatal(err)
}
defer pprof.StopCPUProfile()
}
defer glog.Flush()
glog.Info("Read the config.")
if err := InitConf(); err != nil {
glog.Fatal(err)
}
// Open the RPC listener.
glog.Infof("Comet RPC Listen at:%v", Conf.RPC_addr)
go listenRPC()
// Open the cliens's server
glog.Infof("Comet listen at: %v", Conf.Listen_addr)
go startListen(CLIENT, Conf.Listen_addr)
signal.HandleSignal(signal.InitSignal())
glog.Info("System exit.")
}