This repository has been archived by the owner on Sep 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
105 lines (90 loc) · 1.87 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package main
import (
"flag"
"io"
"log"
"net"
"os"
"os/signal"
"syscall"
"github.com/rrlinker/go-librlcom"
)
const (
listenProtocol string = "unix"
)
var (
flagListenPath = flag.String("addr", "/usr/local/rrlinker/svcrlsymres.sock", "listen path")
flagLibsPath = flag.String("libs", "/usr/local/rrlinker/libs", "path to directory with .lib files")
)
var SymRes *SymbolResolver
func main() {
var err error
flag.Parse()
SymRes, err = NewSymbolResolver(*flagLibsPath)
if err != nil {
log.Fatalln(err)
}
listener, err := net.Listen(listenProtocol, *flagListenPath)
if err != nil {
log.Fatalln(err)
}
exitSignal := make(chan os.Signal)
signal.Notify(exitSignal,
syscall.SIGINT,
syscall.SIGTERM,
)
go handleClients(listener)
s := <-exitSignal
log.Printf("received signal `%s`, exitting...\n", s.String())
listener.Close()
}
func handleClients(listener net.Listener) {
for {
conn, err := listener.Accept()
if err != nil {
log.Printf("Error occured on `listener.Accept`\nError: %v\n", err)
}
go handleClient(conn)
}
}
func handleClient(conn net.Conn) {
c := librlcom.NewCourier(conn)
loop:
for {
msg, err := c.Receive()
switch err {
case nil:
case librlcom.ErrUnknownMessage:
header := msg.(*librlcom.Header)
log.Println(err, header)
break loop
case io.EOF:
break loop
default:
log.Println(err, msg)
break loop
}
switch m := msg.(type) {
case *librlcom.GetSymbolLibrary:
library, err := SymRes.Resolve(m.String.String())
if err == nil {
err = c.Send(&librlcom.ResolvedSymbolLibrary{
String: librlcom.String(library),
})
if err != nil {
log.Println(err)
}
} else {
err = c.Send(&librlcom.ResolvedSymbolLibrary{
String: librlcom.String(""),
})
if err != nil {
log.Println(err)
}
}
default:
log.Println(librlcom.ErrUnknownMessage, m)
}
}
conn.Close()
}