@@ -24,63 +24,30 @@ const (
24
24
type Resolver map [string ]reflect.Value
25
25
26
26
func handleConnection (c net.Conn , chardev * os.File , resp chan []byte ) {
27
-
28
- fmt .Printf ("Serving %s\n " , c .RemoteAddr ().String ())
29
-
30
27
data , _ , err := msgpack .Unpack (c )
31
28
if err != nil {
32
29
fmt .Println (err )
33
30
return
34
31
}
35
32
36
- fmt .Println (data )
37
33
var buf bytes.Buffer
38
34
39
35
msgpack .Pack (& buf , data .Interface ())
40
-
41
- /*
42
- msgId := _req[1]
43
- msgName := _req[2]
44
- msgArgs := _req[3]
45
-
46
- rawdata := make([]byte, 5)
47
- rawdata[0] = byte(msgType.Int())
48
- rawdata[1] = byte(msgId.Int())
49
- rawdata[2] = byte(msgId.Int())
50
- rawdata[3] = byte(msgId.Int())
51
- rawdata[4] = byte(msgId.Int())
52
- rawdata = append(rawdata, msgName.Bytes()...)
53
-
54
- something := msgArgs.Addr().Bytes()
55
-
56
- fmt.Println(something)
57
- rawdata = append(rawdata, something...)
58
-
59
- fmt.Println(data)
60
- fmt.Println(rawdata)
61
- */
62
-
63
- fmt .Println (buf )
64
-
65
36
chardev .Write (buf .Bytes ())
66
37
67
38
msgType := buf .Bytes ()[1 ]
68
39
69
40
if msgType == REQUEST {
70
41
// wait to be unlocked by the other reading goroutine
71
42
// TODO: add timeout handling
72
- fmt .Println ("wait for response" )
73
43
select {
74
44
case response := <- resp :
75
45
//chardev.Read(response)
76
- fmt .Println ("return response to client" )
77
46
c .Write (response )
78
47
case <- time .After (1 * time .Second ):
79
48
c .Write (nil )
80
49
}
81
50
}
82
- fmt .Println ("done" )
83
-
84
51
if msgType == NOTIFICATION {
85
52
// fire and forget
86
53
}
@@ -91,9 +58,6 @@ func handleConnection(c net.Conn, chardev *os.File, resp chan []byte) {
91
58
func chardevListener (chardev * os.File , resp chan []byte ) {
92
59
93
60
for {
94
-
95
- fmt .Println ("charDevListener" )
96
-
97
61
data := make ([]byte , 1024 )
98
62
response := make ([]byte , 1024 )
99
63
@@ -102,36 +66,16 @@ func chardevListener(chardev *os.File, resp chan []byte) {
102
66
data = data [:n ]
103
67
104
68
if err != nil {
105
- fmt .Println (err )
106
69
continue
107
70
}
108
- fmt .Println ("chardev.Read returned" )
109
-
110
71
if n <= 0 {
111
72
continue
112
73
}
113
-
114
- fmt .Println ("got data from chardev" )
115
- fmt .Println (data )
116
-
117
74
start := 0
118
75
for {
119
-
120
- fmt .Println ("unpacker loop" )
121
-
122
76
copy_data := data [start :]
123
-
124
77
message , n , err := msgpack .UnpackReflected (bytes .NewReader (copy_data ))
125
-
126
78
start += n
127
-
128
- fmt .Printf ("%d bytes consumed\n " , n )
129
- fmt .Printf ("%v\n " , message )
130
- fmt .Println (message )
131
- if err != nil {
132
- fmt .Printf ("Err: %v\n " , err )
133
- }
134
-
135
79
if err == io .EOF {
136
80
break
137
81
}
@@ -142,12 +86,8 @@ func chardevListener(chardev *os.File, resp chan []byte) {
142
86
}
143
87
144
88
msgType := _req [0 ].Int ()
145
- fmt .Printf ("MsgType: %d\n " , msgType )
146
-
147
- fmt .Println ("before response" )
148
89
149
90
if msgType == RESPONSE {
150
- fmt .Println ("got response and continue" )
151
91
// unlock thread waiting on handleConnection
152
92
resp <- copy_data [:n ]
153
93
continue
@@ -163,23 +103,21 @@ func chardevListener(chardev *os.File, resp chan []byte) {
163
103
msgFunction = _req [1 ]
164
104
}
165
105
166
- fmt .Println ("before serving" )
167
106
method := string (msgFunction .Bytes ())
168
107
port := functionToPort (method )
169
108
170
- fmt .Println ("Serving function " , method , " to port " , port )
171
-
172
109
// REQUEST or NOTIFICATION
173
110
conn , err := net .Dial ("tcp" , port )
111
+ if err != nil {
112
+ continue
113
+ }
114
+ _ , err = conn .Write (copy_data [:n ])
174
115
if err != nil {
175
116
fmt .Println (err )
176
117
continue
177
118
}
178
- conn .Write (copy_data [:n ])
179
119
180
120
if msgType == REQUEST {
181
- fmt .Println ("ask for a response" )
182
-
183
121
var to_send []byte
184
122
i := 0
185
123
for {
@@ -191,12 +129,10 @@ func chardevListener(chardev *os.File, resp chan []byte) {
191
129
break
192
130
}
193
131
}
194
- fmt .Println ("sending " , to_send [:i ])
195
132
chardev .Write (to_send [:i ])
196
133
}
197
134
198
135
if msgType == NOTIFICATION {
199
- fmt .Println ("got a notification" )
200
136
// fire and forget
201
137
}
202
138
@@ -206,7 +142,6 @@ func chardevListener(chardev *os.File, resp chan []byte) {
206
142
}
207
143
208
144
func (self Resolver ) Resolve (name string , arguments []reflect.Value ) (reflect.Value , error ) {
209
- fmt .Println ("resolving " , name )
210
145
return self [name ], nil
211
146
}
212
147
@@ -215,7 +150,6 @@ func (self Resolver) Functions() []string {
215
150
for el := range self {
216
151
functions = append (functions , el )
217
152
}
218
- fmt .Println (functions )
219
153
return functions
220
154
}
221
155
@@ -238,6 +172,10 @@ func main() {
238
172
functions = make (map [string ]int )
239
173
240
174
chardev , err := os .OpenFile ("/dev/x8h7_ui" , os .O_RDWR , 0 )
175
+ if (err != nil ) {
176
+ fmt .Println (err )
177
+ return
178
+ }
241
179
242
180
chardev_reader_chan := make (chan []byte , 1024 )
243
181
0 commit comments