mirror of
https://github.com/wiiu-env/wut.git
synced 2024-12-04 19:44:16 +01:00
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:
parent
9174f415ed
commit
f78363be81
@ -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)
|
||||
|
@ -69,6 +69,14 @@ struct linger
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Wii U "extension"
|
||||
void
|
||||
socket_lib_init();
|
||||
|
||||
// Wii U "extension"
|
||||
void
|
||||
socket_lib_finish();
|
||||
|
||||
int
|
||||
accept(int sockfd,
|
||||
struct sockaddr *addr,
|
||||
|
@ -1,9 +0,0 @@
|
||||
void
|
||||
WHBInitializeSocketLibrary()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
WHBDeinitializeSocketLibrary()
|
||||
{
|
||||
}
|
@ -6,7 +6,6 @@
|
||||
#include <string.h>
|
||||
#include <whb/log.h>
|
||||
#include <whb/log_udp.h>
|
||||
#include <whb/libmanager.h>
|
||||
|
||||
static int
|
||||
sSocket = -1;
|
||||
@ -31,6 +30,7 @@ BOOL
|
||||
WHBLogUdpInit()
|
||||
{
|
||||
int broadcastEnable = 1;
|
||||
socket_lib_init();
|
||||
|
||||
sSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if (sSocket < 0) {
|
||||
@ -54,5 +54,6 @@ WHBLogUdpDeinit()
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
socket_lib_finish();
|
||||
return WHBRemoveLogHandler(udpLogHandler);
|
||||
}
|
||||
|
@ -4,8 +4,8 @@
|
||||
|
||||
int h_errno;
|
||||
|
||||
static BOOL
|
||||
__wut_socket_initialised = FALSE;
|
||||
static uint32_t
|
||||
__wut_socket_refcount = 0;
|
||||
|
||||
static devoptab_t
|
||||
__wut_socket_devoptab =
|
||||
@ -76,47 +76,42 @@ __wut_nsysnet_error_code_map[] =
|
||||
};
|
||||
|
||||
void
|
||||
__init_wut_socket()
|
||||
socket_lib_init()
|
||||
{
|
||||
BOOL connected = FALSE;
|
||||
int dev;
|
||||
|
||||
if (__wut_socket_initialised) {
|
||||
return;
|
||||
if (0 == __wut_socket_refcount++) {
|
||||
RPLWRAP(socket_lib_init)();
|
||||
AddDevice(&__wut_socket_devoptab);
|
||||
}
|
||||
|
||||
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
|
||||
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()
|
||||
{
|
||||
if (!__wut_socket_initialised) {
|
||||
return;
|
||||
}
|
||||
|
||||
RPLWRAP(socket_lib_finish)();
|
||||
ACFinalize();
|
||||
|
||||
__wut_socket_initialised = FALSE;
|
||||
socket_lib_finish();
|
||||
}
|
||||
|
||||
int
|
||||
|
Loading…
Reference in New Issue
Block a user