From cdc07cac2362faf74d0a457349ef9230faefa48d Mon Sep 17 00:00:00 2001 From: James Benton Date: Mon, 10 Apr 2017 23:18:04 +0100 Subject: [PATCH] nsysnet: Update socket.h to use sys/time.h and sys/types.h --- include/nsysnet/socket.h | 52 ++++++++++++---------------------------- include/sys/select.h | 3 --- include/sys/socket.h | 3 --- 3 files changed, 15 insertions(+), 43 deletions(-) delete mode 100644 include/sys/select.h delete mode 100644 include/sys/socket.h diff --git a/include/nsysnet/socket.h b/include/nsysnet/socket.h index c37e375..6102143 100644 --- a/include/nsysnet/socket.h +++ b/include/nsysnet/socket.h @@ -2,12 +2,15 @@ #include #include +#define FD_SETSIZE 32 +#include +#include + /** * \defgroup nsysnet_socket Socket * \ingroup nsysnet * @{ */ - #define SOL_SOCKET -1 #define INADDR_ANY 0 @@ -20,19 +23,13 @@ #define AF_INET PF_INET #define AF_INET6 PF_INET6 -#define EAGAIN 6 -#define EWOULDBLOCK 6 - #define SOCK_STREAM 1 #define SOCK_DGRAM 2 #define MSG_OOB 0x0001 #define MSG_PEEK 0x0002 -#define MSG_DONTWAIT 0x0004 -#define MSG_DONTROUTE 0x0000 // ??? -#define MSG_WAITALL 0x0000 // ??? -#define MSG_MORE 0x0000 // ??? -#define MSG_NOSIGNAL 0x0000 // there are no signals +#define MSG_DONTROUTE 0x0004 +#define MSG_DONTWAIT 0x0020 #define SHUT_RD 0 #define SHUT_WR 1 @@ -58,34 +55,26 @@ #define SO_BIO 0x1015 // set socket to blocking mode #define SO_NONBLOCK 0x1016 // set/get blocking mode via optval param -#define FD_SETSIZE (32) -#define FD_CLR(n, set) \ - ((set)->fd_bits &= ~(1 << (n))) -#define FD_COPY(src, set) \ - ((set)->fd_bits = (src)->fd_bits) -#define FD_ISSET(n, set) \ - ((set)->fd_bits & (1 << (n))) -#define FD_SET(n, set) \ - ((set)->fd_bits |= (1 << (n))) -#define FD_ZERO(n, set) \ - ((set)->fd_bits = 0) +/* + * Errors returned by nsysnet socket functions + * WARNING: these do not match with sys/errno.h (where EAGAIN is 11 for example). + */ +#define NSN_EAGAIN 6 +#define NSN_EWOULDBLOCK 6 typedef uint32_t socklen_t; typedef uint16_t sa_family_t; -typedef uint32_t fd_mask; - -typedef struct fd_set fd_set; struct sockaddr { sa_family_t sa_family; - char sa_data[]; + char sa_data[]; }; struct sockaddr_storage { sa_family_t ss_family; - char __ss_padding[26]; + char __ss_padding[32]; }; struct linger @@ -101,23 +90,12 @@ struct in_addr struct sockaddr_in { - short sin_family; + unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; char sin_zero[8]; }; -struct timeval -{ - long tv_sec; - long tv_usec; -}; - -struct fd_set -{ - fd_mask fd_bits; -}; - #ifdef __cplusplus extern "C" { #endif diff --git a/include/sys/select.h b/include/sys/select.h deleted file mode 100644 index 5d49dd8..0000000 --- a/include/sys/select.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include diff --git a/include/sys/socket.h b/include/sys/socket.h deleted file mode 100644 index 5d49dd8..0000000 --- a/include/sys/socket.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include