From eb0306184d46a63d929aede352f54109701b7112 Mon Sep 17 00:00:00 2001 From: fincs Date: Sun, 25 Apr 2021 21:08:20 +0200 Subject: [PATCH] wutsocket: Revise automatic initialization, see details: - __init/fini_wut_socket have been simplified and are now weak, this is intended to allow users to customize their behaviour - socket_lib_init/exit have been restored as regular imports and are no longer using RPLWRAP - __wut_socket_init/fini_devoptab are now exposed as global symbols, intended to be used in custom socket init/deinit logic --- cafe/nsysnet.def | 4 +- include/nsysnet/_socket.h | 4 +- include/nsysnet/socket.h | 12 ------ libraries/wutsocket/wut_socket_common.c | 57 +++++++++---------------- 4 files changed, 24 insertions(+), 53 deletions(-) diff --git a/cafe/nsysnet.def b/cafe/nsysnet.def index 8d6e8e75..7f1ad8a0 100644 --- a/cafe/nsysnet.def +++ b/cafe/nsysnet.def @@ -77,6 +77,8 @@ inet_ntoa inet_ntoa_r ntohl ntohs +socket_lib_finish +socket_lib_init :TEXT_WRAP NSSLCreateConnection @@ -169,8 +171,6 @@ simple_ping simple_ping_result socket socket_lib_decode_error -socket_lib_finish -socket_lib_init socketclose socketclose_all socketlasterr diff --git a/include/nsysnet/_socket.h b/include/nsysnet/_socket.h index f8848f29..03ac0383 100644 --- a/include/nsysnet/_socket.h +++ b/include/nsysnet/_socket.h @@ -42,10 +42,10 @@ struct nsysnet_timeval }; void -RPLWRAP(socket_lib_init)(); +socket_lib_init(); void -RPLWRAP(socket_lib_finish)(); +socket_lib_finish(); int RPLWRAP(accept)(int sockfd, diff --git a/include/nsysnet/socket.h b/include/nsysnet/socket.h index 182185cc..0d7c04bf 100644 --- a/include/nsysnet/socket.h +++ b/include/nsysnet/socket.h @@ -18,18 +18,6 @@ extern "C" { #define NSN_EAGAIN EAGAIN #define NSN_EWOULDBLOCK EWOULDBLOCK -__attribute__ ((deprecated)) -static inline void -socket_lib_init() -{ -} - -__attribute__ ((deprecated)) -static inline void -socket_lib_finish() -{ -} - __attribute__ ((deprecated)) static inline int socketclose(int sockfd) diff --git a/libraries/wutsocket/wut_socket_common.c b/libraries/wutsocket/wut_socket_common.c index b1744999..f558b3f4 100644 --- a/libraries/wutsocket/wut_socket_common.c +++ b/libraries/wutsocket/wut_socket_common.c @@ -4,9 +4,6 @@ int h_errno; -static BOOL -__wut_socket_initialised = FALSE; - static devoptab_t __wut_socket_devoptab = { @@ -76,47 +73,33 @@ __wut_nsysnet_error_code_map[] = }; void -__init_wut_socket() +__wut_socket_init_devoptab() { - BOOL connected = FALSE; - int dev; - - if (__wut_socket_initialised) { - return; - } - - ACInitialize(); - ACConnect(); - - ACIsApplicationConnected(&connected); - if (!connected) { - ACFinalize(); - return; - } - - RPLWRAP(socket_lib_init)(); - - dev = AddDevice(&__wut_socket_devoptab); - if (dev == -1) { - RPLWRAP(socket_lib_finish)(); - ACFinalize(); - return; - } - - __wut_socket_initialised = TRUE; + AddDevice(&__wut_socket_devoptab); } void +__wut_socket_fini_devoptab() +{ + RemoveDevice("soc:"); +} + +void __attribute__((weak)) +__init_wut_socket() +{ + socket_lib_init(); + __wut_socket_init_devoptab(); + ACInitialize(); + ACConnectAsync(); +} + +void __attribute__((weak)) __fini_wut_socket() { - if (!__wut_socket_initialised) { - return; - } - - RPLWRAP(socket_lib_finish)(); + ACClose(); ACFinalize(); - - __wut_socket_initialised = FALSE; + __wut_socket_fini_devoptab(); + socket_lib_finish(); } int