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