mirror of
https://github.com/devkitPro/wut.git
synced 2026-08-28 05:45:03 -05:00
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
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user