-
Notifications
You must be signed in to change notification settings - Fork 0
/
go2o-tcpserve.go
66 lines (59 loc) · 1.43 KB
/
go2o-tcpserve.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* Copyright 2015 @ z3q.net.
* name : go2o-tcpserve.go
* author : jarryliu
* date : 2015-11-23 15:52
* description :
* history :
*/
package main
import (
"flag"
"fmt"
"github.com/jsix/gof"
"go2o/src/app/cache"
"go2o/src/app/tcpserve"
"go2o/src/core"
"go2o/src/core/service/dps"
"log"
"os"
"os/signal"
"syscall"
"go2o/src/fix"
)
func main() {
var (
port int
ch chan bool = make(chan bool)
logOutput bool
conf string
)
flag.IntVar(&port, "port", 14197, "")
flag.StringVar(&conf, "conf", "app.conf", "")
flag.BoolVar(&logOutput, "l", false, "log output")
flag.Parse()
log.SetOutput(os.Stdout)
log.SetFlags(log.LstdFlags | log.Ltime | log.Ldate | log.Lshortfile)
gof.CurrentApp = core.NewMainApp(conf)
dps.Init(gof.CurrentApp)
cache.Initialize(gof.CurrentApp.Storage())
fix.CustomFix()
ts := tcpserve.NewServe(logOutput)
ts.RegisterJob(tcpserve.MemberSummaryNotifyJob) //注册会员信息通知
ts.RegisterJob(tcpserve.AccountNotifyJob) //注册账户通知任务
go ts.Listen(fmt.Sprintf(":%d", port)) //启动服务
// 检测退出信号
go func(mainCh chan bool) {
ch := make(chan os.Signal)
signal.Notify(ch, syscall.SIGTERM, syscall.SIGKILL)
for {
switch <-ch {
case syscall.SIGKILL, syscall.SIGTERM:
log.Println("[ Tcp][ Term] - tcp serve has term!")
close(mainCh)
}
}
}(ch)
log.Println("[ TCP][ SERVE] - socket is serve on port :", port)
<-ch
}