@@ -20,7 +20,7 @@ type Client struct {
20
20
func Connect (addr string ) (* Client , error ) {
21
21
client , err := rpc .DialHTTP ("tcp" , addr )
22
22
if err != nil {
23
- log . Fatal ( "Connection error: " , err )
23
+ return nil , fmt . Errorf ( "connection error:%v " , err )
24
24
}
25
25
c := & Client {
26
26
serverAddr : addr ,
@@ -50,33 +50,56 @@ type StatsClient struct {
50
50
}
51
51
52
52
func (s * StatsClient ) GetSystemStats (sysStats * api.SystemStats ) error {
53
+ // we need to start with a clean, zeroed item before decoding
54
+ // 'cause if the new values are 'zero' for the type, they will be ignored
55
+ // by the decoder. (i.e the old values will be left unchanged).
53
56
req := StatsRequest {StatsType : "system" }
54
- resp := StatsResponse {SysStats : sysStats }
55
- return s .rpc .Call ("StatsRPC.GetStats" , req , & resp )
57
+ resp := StatsResponse {SysStats : new (api.SystemStats )}
58
+ if err := s .rpc .Call ("StatsRPC.GetStats" , req , & resp ); err != nil {
59
+ return err
60
+ }
61
+ * sysStats = * resp .SysStats
62
+ return nil
56
63
}
57
64
58
65
func (s * StatsClient ) GetNodeStats (nodeStats * api.NodeStats ) error {
59
66
req := StatsRequest {StatsType : "node" }
60
- resp := StatsResponse {NodeStats : nodeStats }
61
- return s .rpc .Call ("StatsRPC.GetStats" , req , & resp )
67
+ resp := StatsResponse {NodeStats : new (api.NodeStats )}
68
+ if err := s .rpc .Call ("StatsRPC.GetStats" , req , & resp ); err != nil {
69
+ return err
70
+ }
71
+ * nodeStats = * resp .NodeStats
72
+ return nil
62
73
}
63
74
64
75
func (s * StatsClient ) GetInterfaceStats (ifaceStats * api.InterfaceStats ) error {
65
76
req := StatsRequest {StatsType : "interface" }
66
- resp := StatsResponse {IfaceStats : ifaceStats }
67
- return s .rpc .Call ("StatsRPC.GetStats" , req , & resp )
77
+ resp := StatsResponse {IfaceStats : new (api.InterfaceStats )}
78
+ if err := s .rpc .Call ("StatsRPC.GetStats" , req , & resp ); err != nil {
79
+ return err
80
+ }
81
+ * ifaceStats = * resp .IfaceStats
82
+ return nil
68
83
}
69
84
70
85
func (s * StatsClient ) GetErrorStats (errStats * api.ErrorStats ) error {
71
86
req := StatsRequest {StatsType : "error" }
72
- resp := StatsResponse {ErrStats : errStats }
73
- return s .rpc .Call ("StatsRPC.GetStats" , req , & resp )
87
+ resp := StatsResponse {ErrStats : new (api.ErrorStats )}
88
+ if err := s .rpc .Call ("StatsRPC.GetStats" , req , & resp ); err != nil {
89
+ return err
90
+ }
91
+ * errStats = * resp .ErrStats
92
+ return nil
74
93
}
75
94
76
95
func (s * StatsClient ) GetBufferStats (bufStats * api.BufferStats ) error {
77
96
req := StatsRequest {StatsType : "buffer" }
78
- resp := StatsResponse {BufStats : bufStats }
79
- return s .rpc .Call ("StatsRPC.GetStats" , req , & resp )
97
+ resp := StatsResponse {BufStats : new (api.BufferStats )}
98
+ if err := s .rpc .Call ("StatsRPC.GetStats" , req , & resp ); err != nil {
99
+ return err
100
+ }
101
+ * bufStats = * resp .BufStats
102
+ return nil
80
103
}
81
104
82
105
type BinapiClient struct {
@@ -166,11 +189,25 @@ func (b *BinapiClient) SubscribeNotification(notifChan chan api.Message, event a
166
189
}
167
190
168
191
func (b * BinapiClient ) SetReplyTimeout (timeout time.Duration ) {
169
- panic ("implement me" )
192
+ req := BinapiTimeoutRequest {Timeout : timeout }
193
+ resp := BinapiTimeoutResponse {}
194
+ if err := b .rpc .Call ("BinapiRPC.SetTimeout" , req , & resp ); err != nil {
195
+ log .Println (err )
196
+ }
170
197
}
171
198
172
199
func (b * BinapiClient ) CheckCompatiblity (msgs ... api.Message ) error {
173
- return nil // TODO: proxy this
200
+ for _ , msg := range msgs {
201
+ req := BinapiCompatibilityRequest {
202
+ MsgName : msg .GetMessageName (),
203
+ Crc : msg .GetCrcString (),
204
+ }
205
+ resp := BinapiCompatibilityResponse {}
206
+ if err := b .rpc .Call ("BinapiRPC.Compatibility" , req , & resp ); err != nil {
207
+ return err
208
+ }
209
+ }
210
+ return nil
174
211
}
175
212
176
213
func (b * BinapiClient ) Close () {
0 commit comments