diff options
author | Ondrej Fabry <ofabry@cisco.com> | 2019-04-18 02:23:48 +0200 |
---|---|---|
committer | Ondrej Fabry <ofabry@cisco.com> | 2019-04-18 02:23:48 +0200 |
commit | efdb8bcaa8d1b6124dfc8b929b3195deb0a4f08e (patch) | |
tree | 83255d7b3c819d895867f68579a56616309c2b01 /adapter | |
parent | e24215b47ad5cd6599973c3a76a375b99ad75d44 (diff) |
Check if dir ls/dump returns nil
Change-Id: I9a0a74f53825fc0255bc664c06e32eaef6c45d82
Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'adapter')
-rw-r--r-- | adapter/vppapiclient/stat_client.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/adapter/vppapiclient/stat_client.go b/adapter/vppapiclient/stat_client.go index 55705bd..24700a3 100644 --- a/adapter/vppapiclient/stat_client.go +++ b/adapter/vppapiclient/stat_client.go @@ -161,6 +161,7 @@ govpp_stat_segment_string_vector(uint8_t ** string_vector, char *string) */ import "C" import ( + "errors" "fmt" "os" "unsafe" @@ -169,6 +170,11 @@ import ( ) var ( + ErrStatDirBusy = errors.New("stat dir busy") + ErrStatDumpBusy = errors.New("stat dump busy") +) + +var ( // DefaultStatSocket is the default path for the VPP stat socket file. DefaultStatSocket = "/run/vpp/stats.sock" ) @@ -219,6 +225,9 @@ func (c *statClient) Disconnect() error { func (c *statClient) ListStats(patterns ...string) (stats []string, err error) { dir := C.govpp_stat_segment_ls(convertStringSlice(patterns)) + if dir == nil { + return nil, ErrStatDirBusy + } defer C.govpp_stat_segment_vec_free(unsafe.Pointer(dir)) l := C.govpp_stat_segment_vec_len(unsafe.Pointer(dir)) @@ -233,9 +242,15 @@ func (c *statClient) ListStats(patterns ...string) (stats []string, err error) { func (c *statClient) DumpStats(patterns ...string) (stats []*adapter.StatEntry, err error) { dir := C.govpp_stat_segment_ls(convertStringSlice(patterns)) + if dir == nil { + return nil, ErrStatDirBusy + } defer C.govpp_stat_segment_vec_free(unsafe.Pointer(dir)) dump := C.govpp_stat_segment_dump(dir) + if dump == nil { + return nil, ErrStatDumpBusy + } defer C.govpp_stat_segment_data_free(dump) l := C.govpp_stat_segment_vec_len(unsafe.Pointer(dump)) |