diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2024-07-14 21:12:37 +0200 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2024-07-14 21:12:37 +0200 |
commit | 30740ca4131d1f574718262451b4410207dc8d4e (patch) | |
tree | fc88b16a216079397ad85b9c6b1a1c1c5712a814 /source/kit/sockets.h | |
parent | 5e3c99bb1cf1d03ea006300121265571f5008fd2 (diff) | |
download | saw-30740ca4131d1f574718262451b4410207dc8d4e.zip |
Reworking the build system
Diffstat (limited to 'source/kit/sockets.h')
-rw-r--r-- | source/kit/sockets.h | 107 |
1 files changed, 0 insertions, 107 deletions
diff --git a/source/kit/sockets.h b/source/kit/sockets.h deleted file mode 100644 index 276ecc5..0000000 --- a/source/kit/sockets.h +++ /dev/null @@ -1,107 +0,0 @@ -#ifndef KIT_SOCKETS_H -#define KIT_SOCKETS_H - -#include "types.h" -#include "status.h" - -#ifndef KIT_DISABLE_SYSTEM_SOCKETS -# ifdef __GNUC__ -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wunused-function" -# pragma GCC diagnostic ignored "-Wunknown-pragmas" -# endif - -# ifdef __cplusplus -extern "C" { -# endif - -# if defined(_WIN32) && !defined(__CYGWIN__) - -# define WIN32_LEAN_AND_MEAN -# include <winsock2.h> -# include <ws2tcpip.h> - -# define socket_t SOCKET -# define socklen_t i32 - -static s32 kit_sockets_init(void) { - WSADATA data; - memset(&data, 0, sizeof data); - WORD version = MAKEWORD(2, 2); - return WSAStartup(version, &data) == ERROR_SUCCESS - ? KIT_OK - : KIT_ERROR_SOCKETS_STARTUP_FAILED; -} - -static s32 kit_sockets_cleanup(void) { - WSACleanup(); - return KIT_OK; -} - -static i32 kit_socket_set_blocking(socket_t s) { - u_long flag = 0; - return ioctlsocket(s, FIONBIO, &flag) == 0 - ? KIT_OK - : KIT_ERROR_SOCKET_CONTROL_FAILED; -} - -static i32 kit_socket_set_nonblocking(socket_t s) { - u_long flag = 1; - return ioctlsocket(s, FIONBIO, &flag) == 0 - ? KIT_OK - : KIT_ERROR_SOCKET_CONTROL_FAILED; -} - -# else - -# include <arpa/inet.h> -# include <errno.h> -# include <fcntl.h> -# include <netinet/in.h> -# include <signal.h> -# include <sys/ioctl.h> -# include <sys/select.h> -# include <sys/socket.h> -# include <sys/types.h> -# include <unistd.h> -# include <netdb.h> - -# define socket_t i32 -# define closesocket close -# define INVALID_SOCKET -1 - -static s32 kit_sockets_init(void) { - signal(SIGPIPE, SIG_IGN); - return KIT_OK; -} - -static s32 kit_sockets_cleanup(void) { - return KIT_OK; -} - -static i32 kit_socket_set_blocking(socket_t s) { - i32 flags = fcntl(s, F_GETFL, 0); - return fcntl(s, F_SETFL, flags & ~O_NONBLOCK) == 0 - ? KIT_OK - : KIT_ERROR_SOCKET_CONTROL_FAILED; -} - -static i32 kit_socket_set_nonblocking(socket_t s) { - i32 flags = fcntl(s, F_GETFL, 0); - return fcntl(s, F_SETFL, flags | O_NONBLOCK) == 0 - ? KIT_OK - : KIT_ERROR_SOCKET_CONTROL_FAILED; -} - -# endif - -# ifdef __cplusplus -} -# endif - -# ifdef __GNUC__ -# pragma GCC diagnostic pop -# endif -#endif - -#endif |