More rnet review to avoid warnings/errors
This commit is contained in:
parent
2d4c2ff351
commit
e26cc01ba8
2 changed files with 1583 additions and 1593 deletions
2958
src/rnet.c
2958
src/rnet.c
File diff suppressed because it is too large
Load diff
218
src/rnet.h
218
src/rnet.h
|
@ -78,15 +78,15 @@
|
||||||
#define NOMSG // typedef MSG and associated routines
|
#define NOMSG // typedef MSG and associated routines
|
||||||
#define NOOPENFILE // OpenFile(), OemToAnsi, AnsiToOem, and OF_*
|
#define NOOPENFILE // OpenFile(), OemToAnsi, AnsiToOem, and OF_*
|
||||||
#define NOSCROLL // SB_* and scrolling routines
|
#define NOSCROLL // SB_* and scrolling routines
|
||||||
#define NOSERVICE // All Service Controller routines, SERVICE_ equates, etc.
|
#define NOSERVICE // All Service Controller routines, SERVICE_ equates, etc.
|
||||||
#define NOSOUND // Sound driver routines
|
#define NOSOUND // Sound driver routines
|
||||||
#define NOTEXTMETRIC // typedef TEXTMETRIC and associated routines
|
#define NOTEXTMETRIC // typedef TEXTMETRIC and associated routines
|
||||||
#define NOWH // SetWindowsHook and WH_*
|
#define NOWH // SetWindowsHook and WH_*
|
||||||
#define NOWINOFFSETS // GWL_*, GCL_*, associated routines
|
#define NOWINOFFSETS // GWL_*, GCL_*, associated routines
|
||||||
#define NOCOMM // COMM driver routines
|
#define NOCOMM // COMM driver routines
|
||||||
#define NOKANJI // Kanji support stuff.
|
#define NOKANJI // Kanji support stuff.
|
||||||
#define NOHELP // Help engine interface.
|
#define NOHELP // Help engine interface.
|
||||||
#define NOPROFILER // Profiler interface.
|
#define NOPROFILER // Profiler interface.
|
||||||
#define NODEFERWINDOWPOS // DeferWindowPos routines
|
#define NODEFERWINDOWPOS // DeferWindowPos routines
|
||||||
#define NOMCX // Modem Configuration Extensions
|
#define NOMCX // Modem Configuration Extensions
|
||||||
#define MMNOSOUND
|
#define MMNOSOUND
|
||||||
|
@ -101,21 +101,21 @@ typedef int socklen_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef RESULT_SUCCESS
|
#ifndef RESULT_SUCCESS
|
||||||
# define RESULT_SUCCESS 0
|
# define RESULT_SUCCESS 0
|
||||||
#endif // RESULT_SUCCESS
|
#endif // RESULT_SUCCESS
|
||||||
|
|
||||||
#ifndef RESULT_FAILURE
|
#ifndef RESULT_FAILURE
|
||||||
# define RESULT_FAILURE 1
|
# define RESULT_FAILURE 1
|
||||||
#endif // RESULT_FAILURE
|
#endif // RESULT_FAILURE
|
||||||
|
|
||||||
#ifndef htonll
|
#ifndef htonll
|
||||||
# ifdef _BIG_ENDIAN
|
# ifdef _BIG_ENDIAN
|
||||||
# define htonll(x) (x)
|
# define htonll(x) (x)
|
||||||
# define ntohll(x) (x)
|
# define ntohll(x) (x)
|
||||||
# else
|
# else
|
||||||
# define htonll(x) ((((uint64) htonl(x)) << 32) + htonl(x >> 32))
|
# define htonll(x) ((((uint64) htonl(x)) << 32) + htonl(x >> 32))
|
||||||
# define ntohll(x) ((((uint64) ntohl(x)) << 32) + ntohl(x >> 32))
|
# define ntohll(x) ((((uint64) ntohl(x)) << 32) + ntohl(x >> 32))
|
||||||
# endif // _BIG_ENDIAN
|
# endif // _BIG_ENDIAN
|
||||||
#endif // htonll
|
#endif // htonll
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
@ -124,44 +124,42 @@ typedef int socklen_t;
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Include system network headers
|
// Include system network headers
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
# pragma comment(lib, "ws2_32.lib")
|
#define __USE_W32_SOCKETS
|
||||||
# define __USE_W32_SOCKETS
|
#define WIN32_LEAN_AND_MEAN
|
||||||
# define WIN32_LEAN_AND_MEAN
|
#include <winsock2.h>
|
||||||
# include <winsock2.h>
|
#include <ws2tcpip.h>
|
||||||
# include <Ws2tcpip.h>
|
#include <io.h>
|
||||||
# include <io.h>
|
#define IPTOS_LOWDELAY 0x10
|
||||||
# define IPTOS_LOWDELAY 0x10
|
#else // Unix
|
||||||
#else /* UNIX */
|
#include <sys/types.h>
|
||||||
# include <sys/types.h>
|
#include <fcntl.h>
|
||||||
# include <fcntl.h>
|
#include <netinet/in.h>
|
||||||
# include <netinet/in.h>
|
#include <sys/ioctl.h>
|
||||||
# include <sys/ioctl.h>
|
#include <sys/time.h>
|
||||||
# include <sys/time.h>
|
#include <unistd.h>
|
||||||
# include <unistd.h>
|
#include <net/if.h>
|
||||||
# include <net/if.h>
|
#include <netdb.h>
|
||||||
# include <netdb.h>
|
#include <netinet/tcp.h>
|
||||||
# include <netinet/tcp.h>
|
#include <sys/socket.h>
|
||||||
# include <sys/socket.h>
|
#include <arpa/inet.h>
|
||||||
# include <arpa/inet.h>
|
#endif
|
||||||
#endif /* WIN32 */
|
|
||||||
|
|
||||||
#ifndef INVALID_SOCKET
|
#ifndef INVALID_SOCKET
|
||||||
# define INVALID_SOCKET ~(0)
|
#define INVALID_SOCKET ~(0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __USE_W32_SOCKETS
|
#ifndef __USE_W32_SOCKETS
|
||||||
# define closesocket close
|
#define closesocket close
|
||||||
# define SOCKET int
|
#define SOCKET int
|
||||||
# define INVALID_SOCKET -1
|
#define INVALID_SOCKET -1
|
||||||
# define SOCKET_ERROR -1
|
#define SOCKET_ERROR -1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __USE_W32_SOCKETS
|
#ifdef __USE_W32_SOCKETS
|
||||||
# ifndef EINTR
|
#ifndef EINTR
|
||||||
# define EINTR WSAEINTR
|
#define EINTR WSAEINTR
|
||||||
# endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
@ -171,9 +169,9 @@ typedef int socklen_t;
|
||||||
// Network connection related defines
|
// Network connection related defines
|
||||||
#define SOCKET_MAX_SET_SIZE (32) // Maximum sockets in a set
|
#define SOCKET_MAX_SET_SIZE (32) // Maximum sockets in a set
|
||||||
#define SOCKET_MAX_QUEUE_SIZE (16) // Maximum socket queue size
|
#define SOCKET_MAX_QUEUE_SIZE (16) // Maximum socket queue size
|
||||||
#define SOCKET_MAX_SOCK_OPTS (4) // Maximum socket options
|
#define SOCKET_MAX_SOCK_OPTS (4) // Maximum socket options
|
||||||
#define SOCKET_MAX_UDPCHANNELS (32) // Maximum UDP channels
|
#define SOCKET_MAX_UDPCHANNELS (32) // Maximum UDP channels
|
||||||
#define SOCKET_MAX_UDPADDRESSES (4) // Maximum bound UDP addresses
|
#define SOCKET_MAX_UDPADDRESSES (4) // Maximum bound UDP addresses
|
||||||
|
|
||||||
|
|
||||||
// Network address related defines
|
// Network address related defines
|
||||||
|
@ -231,97 +229,87 @@ typedef int socklen_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Network typedefs
|
// Network typedefs
|
||||||
typedef uint32_t SocketChannel;
|
typedef uint32_t SocketChannel;
|
||||||
typedef struct _AddressInformation * AddressInformation;
|
typedef struct _AddressInformation *AddressInformation;
|
||||||
typedef struct _SocketAddress * SocketAddress;
|
typedef struct _SocketAddress *SocketAddress;
|
||||||
typedef struct _SocketAddressIPv4 * SocketAddressIPv4;
|
typedef struct _SocketAddressIPv4 *SocketAddressIPv4;
|
||||||
typedef struct _SocketAddressIPv6 * SocketAddressIPv6;
|
typedef struct _SocketAddressIPv6 *SocketAddressIPv6;
|
||||||
typedef struct _SocketAddressStorage *SocketAddressStorage;
|
typedef struct _SocketAddressStorage *SocketAddressStorage;
|
||||||
|
|
||||||
// IPAddress definition (in network byte order)
|
// IPAddress definition (in network byte order)
|
||||||
typedef struct IPAddress
|
typedef struct IPAddress {
|
||||||
{
|
unsigned long host; /* 32-bit IPv4 host address */
|
||||||
unsigned long host; /* 32-bit IPv4 host address */
|
unsigned short port; /* 16-bit protocol port */
|
||||||
unsigned short port; /* 16-bit protocol port */
|
|
||||||
} IPAddress;
|
} IPAddress;
|
||||||
|
|
||||||
// An option ID, value, sizeof(value) tuple for setsockopt(2).
|
// An option ID, value, sizeof(value) tuple for setsockopt(2).
|
||||||
typedef struct SocketOpt
|
typedef struct SocketOpt {
|
||||||
{
|
int id;
|
||||||
int id;
|
void *value;
|
||||||
void *value;
|
int valueLen;
|
||||||
int valueLen;
|
|
||||||
} SocketOpt;
|
} SocketOpt;
|
||||||
|
|
||||||
typedef enum
|
typedef enum {
|
||||||
{
|
SOCKET_TCP = 0, // SOCK_STREAM
|
||||||
SOCKET_TCP = 0, // SOCK_STREAM
|
SOCKET_UDP = 1 // SOCK_DGRAM
|
||||||
SOCKET_UDP = 1 // SOCK_DGRAM
|
|
||||||
} SocketType;
|
} SocketType;
|
||||||
|
|
||||||
typedef struct UDPChannel
|
typedef struct UDPChannel {
|
||||||
{
|
int numbound; // The total number of addresses this channel is bound to
|
||||||
int numbound; // The total number of addresses this channel is bound to
|
IPAddress address[SOCKET_MAX_UDPADDRESSES]; // The list of remote addresses this channel is bound to
|
||||||
IPAddress address[SOCKET_MAX_UDPADDRESSES]; // The list of remote addresses this channel is bound to
|
|
||||||
} UDPChannel;
|
} UDPChannel;
|
||||||
|
|
||||||
typedef struct Socket
|
typedef struct Socket {
|
||||||
{
|
int ready; // Is the socket ready? i.e. has information
|
||||||
int ready; // Is the socket ready? i.e. has information
|
int status; // The last status code to have occured using this socket
|
||||||
int status; // The last status code to have occured using this socket
|
bool isServer; // Is this socket a server socket (i.e. TCP/UDP Listen Server)
|
||||||
bool isServer; // Is this socket a server socket (i.e. TCP/UDP Listen Server)
|
SocketChannel channel; // The socket handle id
|
||||||
SocketChannel channel; // The socket handle id
|
SocketType type; // Is this socket a TCP or UDP socket?
|
||||||
SocketType type; // Is this socket a TCP or UDP socket?
|
bool isIPv6; // Is this socket address an ipv6 address?
|
||||||
bool isIPv6; // Is this socket address an ipv6 address?
|
SocketAddressIPv4 addripv4; // The host/target IPv4 for this socket (in network byte order)
|
||||||
SocketAddressIPv4 addripv4; // The host/target IPv4 for this socket (in network byte order)
|
SocketAddressIPv6 addripv6; // The host/target IPv6 for this socket (in network byte order)
|
||||||
SocketAddressIPv6 addripv6; // The host/target IPv6 for this socket (in network byte order)
|
|
||||||
|
|
||||||
struct UDPChannel binding[SOCKET_MAX_UDPCHANNELS]; // The amount of channels (if UDP) this socket is bound to
|
struct UDPChannel binding[SOCKET_MAX_UDPCHANNELS]; // The amount of channels (if UDP) this socket is bound to
|
||||||
} Socket;
|
} Socket;
|
||||||
|
|
||||||
typedef struct SocketSet
|
typedef struct SocketSet {
|
||||||
{
|
int numsockets;
|
||||||
int numsockets;
|
int maxsockets;
|
||||||
int maxsockets;
|
struct Socket **sockets;
|
||||||
struct Socket **sockets;
|
|
||||||
} SocketSet;
|
} SocketSet;
|
||||||
|
|
||||||
typedef struct SocketDataPacket
|
typedef struct SocketDataPacket {
|
||||||
{
|
int channel; // The src/dst channel of the packet
|
||||||
int channel; // The src/dst channel of the packet
|
unsigned char *data; // The packet data
|
||||||
unsigned char *data; // The packet data
|
int len; // The length of the packet data
|
||||||
int len; // The length of the packet data
|
int maxlen; // The size of the data buffer
|
||||||
int maxlen; // The size of the data buffer
|
int status; // packet status after sending
|
||||||
int status; // packet status after sending
|
IPAddress address; // The source/dest address of an incoming/outgoing packet
|
||||||
IPAddress address; // The source/dest address of an incoming/outgoing packet
|
|
||||||
} SocketDataPacket;
|
} SocketDataPacket;
|
||||||
|
|
||||||
// Configuration for a socket.
|
// Configuration for a socket.
|
||||||
typedef struct SocketConfig
|
typedef struct SocketConfig {
|
||||||
{
|
char * host; // The host address in xxx.xxx.xxx.xxx form
|
||||||
char * host; // The host address in xxx.xxx.xxx.xxx form
|
char * port; // The target port/service in the form "http" or "25565"
|
||||||
char * port; // The target port/service in the form "http" or "25565"
|
bool server; // Listen for incoming clients?
|
||||||
bool server; // Listen for incoming clients?
|
SocketType type; // The type of socket, TCP/UDP
|
||||||
SocketType type; // The type of socket, TCP/UDP
|
bool nonblocking; // non-blocking operation?
|
||||||
bool nonblocking; // non-blocking operation?
|
int backlog_size; // set a custom backlog size
|
||||||
int backlog_size; // set a custom backlog size
|
SocketOpt sockopts[SOCKET_MAX_SOCK_OPTS];
|
||||||
SocketOpt sockopts[SOCKET_MAX_SOCK_OPTS];
|
|
||||||
} SocketConfig;
|
} SocketConfig;
|
||||||
|
|
||||||
// Result from calling open with a given config.
|
// Result from calling open with a given config.
|
||||||
typedef struct SocketResult
|
typedef struct SocketResult {
|
||||||
{
|
int status;
|
||||||
int status;
|
Socket *socket;
|
||||||
Socket *socket;
|
|
||||||
} SocketResult;
|
} SocketResult;
|
||||||
|
|
||||||
// Packet type
|
// Packet type
|
||||||
typedef struct Packet
|
typedef struct Packet {
|
||||||
{
|
uint32_t size; // The total size of bytes in data
|
||||||
uint32_t size; // The total size of bytes in data
|
uint32_t offs; // The offset to data access
|
||||||
uint32_t offs; // The offset to data access
|
uint32_t maxs; // The max size of data
|
||||||
uint32_t maxs; // The max size of data
|
uint8_t *data; // Data stored in network byte order
|
||||||
uint8_t *data; // Data stored in network byte order
|
|
||||||
} Packet;
|
} Packet;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue