diff options
| -rw-r--r-- | include/nnwt/net.h | 3 | ||||
| -rw-r--r-- | src/common.c | 10 | ||||
| -rw-r--r-- | src/curl/websocket.c | 2 | ||||
| -rw-r--r-- | src/socket/net.h | 13 | ||||
| -rw-r--r-- | src/socket/socket.h | 12 | ||||
| -rw-r--r-- | src/socket/socket_linux.c | 4 | ||||
| -rw-r--r-- | src/socket/socket_windows.c | 1 | ||||
| -rw-r--r-- | src/winwrap.h | 1 |
8 files changed, 31 insertions, 15 deletions
diff --git a/include/nnwt/net.h b/include/nnwt/net.h new file mode 100644 index 0000000..04dace7 --- /dev/null +++ b/include/nnwt/net.h @@ -0,0 +1,3 @@ +#pragma once + +#include "../../src/socket/net.h" diff --git a/src/common.c b/src/common.c index 7b2a958..3c97a7a 100644 --- a/src/common.c +++ b/src/common.c @@ -25,9 +25,9 @@ static inline const char *get_color_for_level(u8 level) #define CYAN "\x1B[36m" #define WHITE "\x1B[37m" switch (level) { - case AL_LOG_ERROR: return RED; - case AL_LOG_WARN: return YELLOW; - default: return ""; + case AL_LOG_ERROR: return RED; + case AL_LOG_WARN: return YELLOW; + default: return ""; } } @@ -62,7 +62,11 @@ static void malloc_unlock(void) bool nn_common_init(void) { +#ifdef NAUNET_ON_WINDOWS + if (!setlocale(LC_ALL, ".UTF8")) { +#else if (!setlocale(LC_ALL, "")) { +#endif return false; } diff --git a/src/curl/websocket.c b/src/curl/websocket.c index 0bfcb9e..0030d16 100644 --- a/src/curl/websocket.c +++ b/src/curl/websocket.c @@ -1,6 +1,6 @@ #include <al/log.h> -#include "../socket/socket.h" +#include "../socket/net.h" #include "websocket.h" diff --git a/src/socket/net.h b/src/socket/net.h new file mode 100644 index 0000000..6091bdc --- /dev/null +++ b/src/socket/net.h @@ -0,0 +1,13 @@ +#pragma once + +#ifdef NAUNET_ON_WINDOWS +#include "../winwrap.h" +#else +#include <al/macros.h> +#include <arpa/inet.h> +#endif + +#define nn_htons htons +#define nn_htonl htonl +#define nn_ntohs ntohs +#define nn_ntohl ntohl diff --git a/src/socket/socket.h b/src/socket/socket.h index bb1fa3f..57e3212 100644 --- a/src/socket/socket.h +++ b/src/socket/socket.h @@ -8,12 +8,8 @@ #else #include <unistd.h> #include <sys/un.h> -#include <sys/eventfd.h> -#include <arpa/inet.h> -#include <sys/fcntl.h> -#include <netinet/tcp.h> -#include <netdb.h> #include <poll.h> +#include <sys/eventfd.h> #endif enum { @@ -48,14 +44,10 @@ struct nn_socket { #define nn_write write #endif -#define nn_htons htons -#define nn_htonl htonl -#define nn_ntohs ntohs -#define nn_ntohl ntohl - #ifndef NAUNET_ON_WINDOWS // Posix-only helpers. #define nn_pollfd pollfd #define nn_nfds nfds_t +#define nn_eventfd eventfd void nn_fd_set_blocking(s32 fd, bool blocking); s32 nn_poll_fds(struct nn_pollfd *fds, nn_nfds nfds, s64 timeout_ns); #endif diff --git a/src/socket/socket_linux.c b/src/socket/socket_linux.c index 2d032f3..b8980be 100644 --- a/src/socket/socket_linux.c +++ b/src/socket/socket_linux.c @@ -1,4 +1,8 @@ #include <al/log.h> +#include <arpa/inet.h> +#include <netdb.h> +#include <netinet/tcp.h> +#include <sys/fcntl.h> #include "../util/error.h" diff --git a/src/socket/socket_windows.c b/src/socket/socket_windows.c index ef7f3bd..85c2853 100644 --- a/src/socket/socket_windows.c +++ b/src/socket/socket_windows.c @@ -2,6 +2,7 @@ #include "socket.h" #include "socket_internal.h" +#include "net.h" bool nn_socket_init(struct nn_socket *sock, s32 flags) { diff --git a/src/winwrap.h b/src/winwrap.h index 430d196..60179a9 100644 --- a/src/winwrap.h +++ b/src/winwrap.h @@ -1,7 +1,6 @@ #pragma once // https://kirkshoop.github.io/2011/09/20/ntstatus.html -#define NOMINMAX #include <winsock2.h> #include <ws2tcpip.h> #include <io.h> |