wutsocket: only link in networking layer if actually used

This commit is contained in:
fincs 2021-03-07 13:36:30 +01:00
parent c377cffe13
commit efc1bd47ff
No known key found for this signature in database
GPG Key ID: 62C7609ADA219C60
4 changed files with 70 additions and 97 deletions

View File

@ -1,35 +1,31 @@
void __init_wut_malloc();
void __init_wut_newlib();
extern void __init_wut_stdcpp();
void __init_wut_stdcpp();
void __init_wut_devoptab();
void __init_wut_socket();
void __attribute__((weak)) __init_wut_socket();
void __fini_wut_malloc();
void __fini_wut_newlib();
extern void __fini_wut_stdcpp();
void __fini_wut_stdcpp();
void __fini_wut_devoptab();
void __fini_wut_socket();
void __attribute__((weak)) __fini_wut_socket();
void __attribute__((weak))
__init_wut()
{
__init_wut_malloc();
__init_wut_newlib();
//if (__init_wut_stdcpp) {
__init_wut_stdcpp();
//}
__init_wut_devoptab();
__init_wut_socket();
if (&__init_wut_socket) __init_wut_socket();
}
void __attribute__((weak))
__fini_wut()
{
__fini_wut_socket();
if (&__fini_wut_socket) __fini_wut_socket();
__fini_wut_devoptab();
//if (__fini_wut_stdcpp) {
__fini_wut_stdcpp();
//}
__fini_wut_newlib();
__fini_wut_malloc();
}

View File

@ -7,7 +7,7 @@ socket(int domain,
{
int rc, fd, dev;
dev = FindDevice("sock:");
dev = FindDevice("soc:");
if (dev == -1) {
return -1;
}

View File

@ -1,80 +0,0 @@
#include "wut_socket.h"
static devoptab_t
__wut_socket_devoptab =
{
.name = "sock",
.structSize = sizeof(int),
.open_r = __wut_socket_open,
.close_r = __wut_socket_close,
.write_r = __wut_socket_write,
.read_r = __wut_socket_read,
.seek_r = NULL,
.fstat_r = NULL,
.stat_r = NULL,
.link_r = NULL,
.unlink_r = NULL,
.chdir_r = NULL,
.rename_r = NULL,
.mkdir_r = NULL,
.dirStateSize = 0,
.diropen_r = NULL,
.dirreset_r = NULL,
.dirnext_r = NULL,
.dirclose_r = NULL,
.statvfs_r = NULL,
.ftruncate_r = NULL,
.fsync_r = NULL,
.deviceData = 0,
.chmod_r = NULL,
.fchmod_r = NULL,
.rmdir_r = NULL,
};
static BOOL
__wut_socket_initialised = FALSE;
void
__init_wut_socket()
{
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;
}
void
__fini_wut_socket()
{
if (!__wut_socket_initialised) {
return;
}
RPLWRAP(socket_lib_finish)();
ACFinalize();
__wut_socket_initialised = FALSE;
}

View File

@ -2,6 +2,20 @@
#define NSYSNET_UNKNOWN_ERROR_OFFSET 10000
static BOOL
__wut_socket_initialised = FALSE;
static devoptab_t
__wut_socket_devoptab =
{
.name = "soc",
.structSize = sizeof(int),
.open_r = __wut_socket_open,
.close_r = __wut_socket_close,
.write_r = __wut_socket_write,
.read_r = __wut_socket_read,
};
static unsigned char
__wut_nsysnet_error_code_map[] =
{
@ -59,6 +73,50 @@ __wut_nsysnet_error_code_map[] =
EMFILE,
};
void
__init_wut_socket()
{
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;
}
void
__fini_wut_socket()
{
if (!__wut_socket_initialised) {
return;
}
RPLWRAP(socket_lib_finish)();
ACFinalize();
__wut_socket_initialised = FALSE;
}
int
__wut_get_nsysnet_fd(int fd)
{
@ -67,7 +125,7 @@ __wut_get_nsysnet_fd(int fd)
errno = EBADF;
return -1;
}
if (strcmp(devoptab_list[handle->device]->name, "sock") != 0) {
if (strcmp(devoptab_list[handle->device]->name, "soc") != 0) {
errno = ENOTSOCK;
return -1;
}
@ -104,4 +162,3 @@ __wut_get_nsysnet_result(struct _reent *r,
return -1;
}