From f87b7233a94131a5fd1b3dfb1595226e2779fffa Mon Sep 17 00:00:00 2001 From: zhangmeng <775834166@qq.com> Date: 星期四, 06 八月 2020 17:52:29 +0800 Subject: [PATCH] add remove key(s) and RequestWithTimeout --- softbusDgram.go | 68 ++++++++++++++++++++++++++++++++++ 1 files changed, 68 insertions(+), 0 deletions(-) diff --git a/softbusDgram.go b/softbusDgram.go index 68d0a29..23db1c1 100644 --- a/softbusDgram.go +++ b/softbusDgram.go @@ -3,6 +3,8 @@ /* #include <stdlib.h> #include "libcsoftbus.h" +extern void *get_array(const int size); +extern void set_array(void *arr, const int index, const int value); */ import "C" import ( @@ -263,6 +265,45 @@ return int(r) } +// Desub remove sub +func (d *DgramSocket) Desub(topic string, port int) int { + if libsoftbus == nil { + return RETVAL + } + + ct := C.CString(topic) + defer C.free(unsafe.Pointer(ct)) + + r := C.wrap_fn_dgram_socket_desub(libsoftbus, d.dgram, unsafe.Pointer(ct), C.int(len(topic)), C.int(port)) + return int(r) +} + +// DesubTimeout timeout +func (d *DgramSocket) DesubTimeout(topic string, port int, sec, usec int) int { + if libsoftbus == nil { + return RETVAL + } + + ct := C.CString(topic) + defer C.free(unsafe.Pointer(ct)) + + r := C.wrap_fn_dgram_socket_desub_timeout(libsoftbus, d.dgram, unsafe.Pointer(ct), C.int(len(topic)), C.int(port), C.int(sec), C.int(usec)) + return int(r) +} + +// DesubNoWait remove sub +func (d *DgramSocket) DesubNoWait(topic string, port int) int { + if libsoftbus == nil { + return RETVAL + } + + ct := C.CString(topic) + defer C.free(unsafe.Pointer(ct)) + + r := C.wrap_fn_dgram_socket_desub_nowait(libsoftbus, d.dgram, unsafe.Pointer(ct), C.int(len(topic)), C.int(port)) + return int(r) +} + // Pub bus func (d *DgramSocket) Pub(topic, msg string, port int) int { if libsoftbus == nil { @@ -317,3 +358,30 @@ r := C.wrap_fn_dgram_socket_port(libsoftbus, d.dgram) return int(r) } + +// RemoveKey rm key +func (d *DgramSocket) RemoveKey(key int) int { + if libsoftbus == nil { + return RETVAL + } + + r := C.wrap_fn_dgram_remove_key(libsoftbus, C.int(key)) + return int(r) +} + +// RemoveKeys rm key +func (d *DgramSocket) RemoveKeys(keys []int) int { + if libsoftbus == nil { + return RETVAL + } + + l := len(keys) + ca := C.get_array(C.int(l)) + defer C.free(ca) + for k, v := range keys { + C.set_array(ca, C.int(k), C.int(v)) + } + + r := C.wrap_fn_dgram_remove_keys(libsoftbus, ca, C.int(l)) + return int(r) +} -- Gitblit v1.8.0