From b70473ad3084fe968bbfaa50eb54cc248b79e02a Mon Sep 17 00:00:00 2001 From: zhangmeng <775834166@qq.com> Date: 星期二, 28 七月 2020 16:10:50 +0800 Subject: [PATCH] 添加dgram socket接口 --- libcsoftbus.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 102 insertions(+), 0 deletions(-) diff --git a/libcsoftbus.c b/libcsoftbus.c index 9058cfe..1c02eaf 100644 --- a/libcsoftbus.c +++ b/libcsoftbus.c @@ -257,3 +257,105 @@ return fn_socket_port(s); } +//////////////////////////////////////////// +// dgram socket mode +//////////////////////////////////////////// +void *wrap_fn_dgram_socket_open(hcsoftbus lib){ + if (!fn_dgram_socket_open){ + fn_dgram_socket_open = (tfn_dgram_socket_open)dlsym(lib , l_dgram_socket_open); + check_with_ret(fn_dgram_socket_open, lib, NULL); + } + return fn_dgram_socket_open(); +} + +int wrap_fn_dgram_socket_close(hcsoftbus lib, void *s){ + if (!fn_dgram_socket_close){ + fn_dgram_socket_close = (tfn_dgram_socket_close)dlsym(lib, l_dgram_socket_close); + check_with_ret(fn_dgram_socket_close, lib, -1); + } + return fn_dgram_socket_close(s); +} + +int wrap_fn_dgram_socket_bind(hcsoftbus lib, void *s, int port){ + if (!fn_dgram_socket_bind){ + fn_dgram_socket_bind = (tfn_dgram_socket_bind)dlsym(lib, l_dgram_socket_bind); + check_with_ret(fn_dgram_socket_bind, lib, -1); + } + return fn_dgram_socket_bind(s, port); +} + +int wrap_fn_dgram_socket_force_bind(hcsoftbus lib, void *s, int port){ + if (!fn_dgram_socket_force_bind){ + fn_dgram_socket_force_bind = (tfn_dgram_socket_force_bind)dlsym(lib, l_dgram_socket_force_bind); + check_with_ret(fn_dgram_socket_force_bind, lib, -1); + } + return fn_dgram_socket_force_bind(s, port); +} + +int wrap_fn_dgram_socket_sendto(hcsoftbus lib, void *s, const void *buf, const int size, const int port){ + if (!fn_dgram_socket_sendto){ + fn_dgram_socket_sendto = (tfn_dgram_socket_sendto)dlsym(lib, l_dgram_socket_sendto); + check_with_ret(fn_dgram_socket_sendto, lib, -1); + } + return fn_dgram_socket_sendto(s, buf, size, port); +} + +int wrap_fn_dgram_socket_recvfrom(hcsoftbus lib, void *s, void **buf, int *size, int *port){ + if (!fn_dgram_socket_recvfrom){ + fn_dgram_socket_recvfrom = (tfn_dgram_socket_recvfrom)dlsym(lib, l_dgram_socket_recvfrom); + check_with_ret(fn_dgram_socket_recvfrom, lib, -1); + } + return fn_dgram_socket_recvfrom(s, buf, size, port); +} + +int wrap_fn_dgram_socket_sendandrecv(hcsoftbus lib, void *s, const void *sbuf, const int ssize, const int port, void **rbuf, int *rsize){ + if (!fn_dgram_socket_sendandrecv){ + fn_dgram_socket_sendandrecv = (tfn_dgram_socket_sendandrecv)dlsym(lib, l_dgram_socket_sendandrecv); + check_with_ret(fn_dgram_socket_sendandrecv, lib, -1); + } + return fn_dgram_socket_sendandrecv(s, sbuf, ssize, port, rbuf, rsize); +} + +int wrap_fn_dgram_socket_start_bus(hcsoftbus lib, void *s){ + if (!fn_dgram_socket_start_bus){ + fn_dgram_socket_start_bus = (tfn_dgram_socket_start_bus)dlsym(lib, l_dgram_socket_start_bus); + check_with_ret(fn_dgram_socket_start_bus, lib, -1); + } + return fn_dgram_socket_start_bus(s); +} + +int wrap_fn_dgram_socket_sub(hcsoftbus lib, void *s, void *topic, int size, int port){ + if (!fn_dgram_socket_sub){ + fn_dgram_socket_sub = (tfn_dgram_socket_sub)dlsym(lib, l_dgram_socket_sub); + check_with_ret(fn_dgram_socket_sub, lib, -1); + } + return fn_dgram_socket_sub(s, topic, size, port); +} + +int wrap_fn_dgram_socket_pub(hcsoftbus lib, void *s, void *topic, int tsize, void *content, int csize, int port){ + if (!fn_dgram_socket_pub){ + fn_dgram_socket_pub = (tfn_dgram_socket_pub)dlsym(lib, l_dgram_socket_pub); + check_with_ret(fn_dgram_socket_pub, lib, -1); + } + return fn_dgram_socket_pub(s, topic, tsize, content, csize, port); +} + +int wrap_fn_dgram_socket_port(hcsoftbus lib, void *s){ + if (!fn_dgram_socket_port){ + fn_dgram_socket_port = (tfn_dgram_socket_port)dlsym(lib, l_dgram_socket_port); + check_with_ret(fn_dgram_socket_port, lib, -1); + } + return fn_dgram_socket_port(s); +} + +void wrap_fn_dgram_socket_free(hcsoftbus lib, void *buf){ + if (!fn_dgram_socket_free){ + fn_dgram_socket_free = (tfn_dgram_socket_free)dlsym(lib, l_dgram_socket_free); + } + if (fn_dgram_socket_free){ + fn_dgram_socket_free(buf); + }else{ + free(buf); + } +} + -- Gitblit v1.8.0