wutsocket: Revise automatic initialization, see details:

- socket_lib_init/exit wrappers are no longer stubs; they now perform
  refcounting & automatically register/deregister the socket devoptab
- Similarly, WHBInitialize/DeinitializeSocketLibrary are now aliased
  to socket_lib_init/exit
- WHBLogUdp now references socket_lib_init/finish again
- __init/fini_wut_socket have been simplified and are now weak,
  this is intended to allow users to customize their behaviour
This commit is contained in:
fincs 2021-04-25 21:08:20 +02:00
parent 9174f415ed
commit f78363be81
No known key found for this signature in database
GPG Key ID: 62C7609ADA219C60
5 changed files with 40 additions and 57 deletions

View File

@ -18,18 +18,6 @@ extern "C" {
#define NSN_EAGAIN EAGAIN #define NSN_EAGAIN EAGAIN
#define NSN_EWOULDBLOCK EWOULDBLOCK #define NSN_EWOULDBLOCK EWOULDBLOCK
__attribute__ ((deprecated))
static inline void
socket_lib_init()
{
}
__attribute__ ((deprecated))
static inline void
socket_lib_finish()
{
}
__attribute__ ((deprecated)) __attribute__ ((deprecated))
static inline int static inline int
socketclose(int sockfd) socketclose(int sockfd)

View File

@ -69,6 +69,14 @@ struct linger
extern "C" { extern "C" {
#endif #endif
// Wii U "extension"
void
socket_lib_init();
// Wii U "extension"
void
socket_lib_finish();
int int
accept(int sockfd, accept(int sockfd,
struct sockaddr *addr, struct sockaddr *addr,

View File

@ -1,9 +0,0 @@
void
WHBInitializeSocketLibrary()
{
}
void
WHBDeinitializeSocketLibrary()
{
}

View File

@ -6,7 +6,6 @@
#include <string.h> #include <string.h>
#include <whb/log.h> #include <whb/log.h>
#include <whb/log_udp.h> #include <whb/log_udp.h>
#include <whb/libmanager.h>
static int static int
sSocket = -1; sSocket = -1;
@ -31,6 +30,7 @@ BOOL
WHBLogUdpInit() WHBLogUdpInit()
{ {
int broadcastEnable = 1; int broadcastEnable = 1;
socket_lib_init();
sSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); sSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (sSocket < 0) { if (sSocket < 0) {
@ -54,5 +54,6 @@ WHBLogUdpDeinit()
return FALSE; return FALSE;
} }
socket_lib_finish();
return WHBRemoveLogHandler(udpLogHandler); return WHBRemoveLogHandler(udpLogHandler);
} }

View File

@ -4,8 +4,8 @@
int h_errno; int h_errno;
static BOOL static uint32_t
__wut_socket_initialised = FALSE; __wut_socket_refcount = 0;
static devoptab_t static devoptab_t
__wut_socket_devoptab = __wut_socket_devoptab =
@ -76,47 +76,42 @@ __wut_nsysnet_error_code_map[] =
}; };
void void
__init_wut_socket() socket_lib_init()
{ {
BOOL connected = FALSE; if (0 == __wut_socket_refcount++) {
int dev; RPLWRAP(socket_lib_init)();
AddDevice(&__wut_socket_devoptab);
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;
} }
void void
socket_lib_finish()
{
if (0 == --__wut_socket_refcount) {
RemoveDevice("soc:");
RPLWRAP(socket_lib_finish)();
}
}
void
WHBInitializeSocketLibrary() __attribute__((alias("socket_lib_init")));
void
WHBDeinitializeSocketLibrary() __attribute__((alias("socket_lib_finish")));
void __attribute__((weak))
__init_wut_socket()
{
socket_lib_init();
ACInitialize();
ACConnect();
}
void __attribute__((weak))
__fini_wut_socket() __fini_wut_socket()
{ {
if (!__wut_socket_initialised) {
return;
}
RPLWRAP(socket_lib_finish)();
ACFinalize(); ACFinalize();
socket_lib_finish();
__wut_socket_initialised = FALSE;
} }
int int