-
Notifications
You must be signed in to change notification settings - Fork 2
/
tmq.go
56 lines (42 loc) · 1.13 KB
/
tmq.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
package main
import (
"log"
"Q"
"web"
"os"
"runtime"
"flag"
"runtime/pprof"
"os/signal"
)
func main () {
if len (os.Args) < 2 {
log.Fatal("Not enough argument")
return
}
runtime.GOMAXPROCS(runtime.NumCPU())
var tport, wport, pfile string
Q.Init()
flag.BoolVar (&(Q.IsVerbose), "v", false, "User This for Trace message")
flag.StringVar ( &tport, "port", "6161", "Port number to start the tcp server")
flag.StringVar ( &wport, "web", "6060", "Port number of the web server")
flag.StringVar ( &pfile, "proffile", "", "Profiling filename")
flag.Parse ()
qsig := make (chan os.Signal, 1)
signal.Notify (qsig, os.Interrupt, os.Kill)
if pfile != "" {
/* This means we want to profile the server */
pfd, err := os.Create(pfile)
if err != nil {
log.Fatal ("unaable to create the profile file:", err)
}
pprof.StartCPUProfile (pfd)
defer pprof.StopCPUProfile ()
}
go web.StartHTTP (wport)
Q.Trace (log.Printf, "Web server is up http://localhost:%s\n", wport)
Q.Trace (log.Printf, "Q TCP server started at port:%s\n",tport)
go Q.StartTCP (tport)
gsig := <-qsig
log.Println ("Q finished signal:",gsig)
}