Review rnet errors
This commit is contained in:
parent
c7907a203b
commit
2d4c2ff351
3 changed files with 68 additions and 59 deletions
|
@ -100,11 +100,6 @@
|
||||||
#define MAX_SHADER_LOCATIONS 32 // Maximum number of predefined locations stored in shader struct
|
#define MAX_SHADER_LOCATIONS 32 // Maximum number of predefined locations stored in shader struct
|
||||||
#define MAX_MATERIAL_MAPS 12 // Maximum number of texture maps stored in shader struct
|
#define MAX_MATERIAL_MAPS 12 // Maximum number of texture maps stored in shader struct
|
||||||
|
|
||||||
// Network connection related defines
|
|
||||||
#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
|
|
||||||
|
|
||||||
// NOTE: MSC C++ compiler does not support compound literals (C99 feature)
|
// NOTE: MSC C++ compiler does not support compound literals (C99 feature)
|
||||||
// Plain structures in C++ (without constructors) can be initialized from { } initializers.
|
// Plain structures in C++ (without constructors) can be initialized from { } initializers.
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
|
|
20
src/rnet.c
20
src/rnet.c
|
@ -42,10 +42,10 @@
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
#include <assert.h> // Required for: assert()
|
#include <assert.h> // Required for: assert()
|
||||||
#include <stdio.h> // Required for: FILE, fopen(), fclose(), fread()
|
#include <stdio.h> // Required for: FILE, fopen(), fclose(), fread()
|
||||||
#include <stdlib.h> // Required for: malloc(), free()
|
#include <stdlib.h> // Required for: malloc(), free()
|
||||||
#include <string.h> // Required for: strcmp(), strncmp()
|
#include <string.h> // Required for: strcmp(), strncmp()
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module defines
|
// Module defines
|
||||||
|
@ -272,7 +272,7 @@ static char *SocketErrorCodeToString(int err)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
static char gaiStrErrorBuffer[GAI_STRERROR_BUFFER_SIZE];
|
static char gaiStrErrorBuffer[GAI_STRERROR_BUFFER_SIZE];
|
||||||
sprintf(gaiStrErrorBuffer, "%ws", gai_strerror(err));
|
sprintf(gaiStrErrorBuffer, "%s", gai_strerror(err));
|
||||||
return gaiStrErrorBuffer;
|
return gaiStrErrorBuffer;
|
||||||
#else
|
#else
|
||||||
return gai_strerror(err);
|
return gai_strerror(err);
|
||||||
|
@ -386,7 +386,7 @@ static bool CreateSocket(SocketConfig *config, SocketResult *outresult)
|
||||||
char hoststr[NI_MAXHOST];
|
char hoststr[NI_MAXHOST];
|
||||||
char portstr[NI_MAXSERV];
|
char portstr[NI_MAXSERV];
|
||||||
socklen_t client_len = sizeof(struct sockaddr_storage);
|
socklen_t client_len = sizeof(struct sockaddr_storage);
|
||||||
int rc = getnameinfo((struct sockaddr *) res->ai_addr, client_len, hoststr, sizeof(hoststr), portstr, sizeof(portstr), NI_NUMERICHOST | NI_NUMERICSERV);
|
int rc = getnameinfo((struct sockaddr *) res->ai_addr, client_len, hoststr, sizeof(hoststr), portstr, sizeof(portstr), NI_NUMERICHOST | NI_NUMERICSERV);
|
||||||
TraceLog(LOG_INFO, "Successfully resolved host %s:%s", hoststr, portstr);
|
TraceLog(LOG_INFO, "Successfully resolved host %s:%s", hoststr, portstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -746,10 +746,10 @@ int ResolveHost(const char *address, const char *service, int addressType, int f
|
||||||
hints.ai_family = addressType; // Either IPv4 or IPv6 (ADDRESS_TYPE_IPV4, ADDRESS_TYPE_IPV6)
|
hints.ai_family = addressType; // Either IPv4 or IPv6 (ADDRESS_TYPE_IPV4, ADDRESS_TYPE_IPV6)
|
||||||
hints.ai_protocol = 0; // Automatically select correct protocol (IPPROTO_TCP), (IPPROTO_UDP)
|
hints.ai_protocol = 0; // Automatically select correct protocol (IPPROTO_TCP), (IPPROTO_UDP)
|
||||||
hints.ai_flags = flags;
|
hints.ai_flags = flags;
|
||||||
assert(hints.ai_addrlen == NULL || hints.ai_addrlen == 0);
|
assert((hints.ai_addrlen == NULL) || (hints.ai_addrlen == 0));
|
||||||
assert(hints.ai_canonname == NULL || hints.ai_canonname == 0);
|
assert((hints.ai_canonname == NULL) || (hints.ai_canonname == 0));
|
||||||
assert(hints.ai_addr == NULL || hints.ai_addr == 0);
|
assert((hints.ai_addr == NULL) || (hints.ai_addr == 0));
|
||||||
assert(hints.ai_next == NULL || hints.ai_next == 0);
|
assert((hints.ai_next == NULL) || (hints.ai_next == 0));
|
||||||
|
|
||||||
// When the address is NULL, populate the IP for me
|
// When the address is NULL, populate the IP for me
|
||||||
if (address == NULL)
|
if (address == NULL)
|
||||||
|
|
102
src/rnet.h
102
src/rnet.h
|
@ -38,6 +38,9 @@
|
||||||
*
|
*
|
||||||
**********************************************************************************************/
|
**********************************************************************************************/
|
||||||
|
|
||||||
|
#ifndef RNET_H
|
||||||
|
#define RNET_H
|
||||||
|
|
||||||
#include <limits.h> // Required for limits
|
#include <limits.h> // Required for limits
|
||||||
#include <inttypes.h> // Required for platform type sizes
|
#include <inttypes.h> // Required for platform type sizes
|
||||||
|
|
||||||
|
@ -168,6 +171,10 @@ 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_UDPCHANNELS (32) // Maximum UDP channels
|
||||||
|
#define SOCKET_MAX_UDPADDRESSES (4) // Maximum bound UDP addresses
|
||||||
|
|
||||||
|
|
||||||
// Network address related defines
|
// Network address related defines
|
||||||
#define ADDRESS_IPV4_ADDRSTRLEN (22) // IPv4 string length
|
#define ADDRESS_IPV4_ADDRSTRLEN (22) // IPv4 string length
|
||||||
|
@ -216,6 +223,13 @@ typedef int socklen_t;
|
||||||
// Types and Structures Definition
|
// Types and Structures Definition
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Boolean type
|
||||||
|
#if defined(__STDC__) && __STDC_VERSION__ >= 199901L
|
||||||
|
#include <stdbool.h>
|
||||||
|
#elif !defined(__cplusplus) && !defined(bool)
|
||||||
|
typedef enum { false, true } bool;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Network typedefs
|
// Network typedefs
|
||||||
typedef uint32_t SocketChannel;
|
typedef uint32_t SocketChannel;
|
||||||
typedef struct _AddressInformation * AddressInformation;
|
typedef struct _AddressInformation * AddressInformation;
|
||||||
|
@ -301,7 +315,7 @@ typedef struct SocketResult
|
||||||
Socket *socket;
|
Socket *socket;
|
||||||
} SocketResult;
|
} SocketResult;
|
||||||
|
|
||||||
//
|
// 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
|
||||||
|
@ -325,64 +339,64 @@ extern "C" { // Prevents name mangling of functions
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Initialisation and cleanup
|
// Initialisation and cleanup
|
||||||
RLAPI bool InitNetwork(void);
|
bool InitNetwork(void);
|
||||||
RLAPI void CloseNetwork(void);
|
void CloseNetwork(void);
|
||||||
|
|
||||||
// Address API
|
// Address API
|
||||||
RLAPI void ResolveIP(const char *ip, const char *service, int flags, char *outhost, char *outserv);
|
void ResolveIP(const char *ip, const char *service, int flags, char *outhost, char *outserv);
|
||||||
RLAPI int ResolveHost(const char *address, const char *service, int addressType, int flags, AddressInformation *outAddr);
|
int ResolveHost(const char *address, const char *service, int addressType, int flags, AddressInformation *outAddr);
|
||||||
RLAPI int GetAddressFamily(AddressInformation address);
|
int GetAddressFamily(AddressInformation address);
|
||||||
RLAPI int GetAddressSocketType(AddressInformation address);
|
int GetAddressSocketType(AddressInformation address);
|
||||||
RLAPI int GetAddressProtocol(AddressInformation address);
|
int GetAddressProtocol(AddressInformation address);
|
||||||
RLAPI char* GetAddressCanonName(AddressInformation address);
|
char* GetAddressCanonName(AddressInformation address);
|
||||||
RLAPI char* GetAddressHostAndPort(AddressInformation address, char *outhost, int *outport);
|
char* GetAddressHostAndPort(AddressInformation address, char *outhost, int *outport);
|
||||||
RLAPI void PrintAddressInfo(AddressInformation address);
|
void PrintAddressInfo(AddressInformation address);
|
||||||
|
|
||||||
// Address Memory API
|
// Address Memory API
|
||||||
RLAPI AddressInformation AllocAddress();
|
AddressInformation AllocAddress();
|
||||||
RLAPI void FreeAddress(AddressInformation *addressInfo);
|
void FreeAddress(AddressInformation *addressInfo);
|
||||||
RLAPI AddressInformation *AllocAddressList(int size);
|
AddressInformation *AllocAddressList(int size);
|
||||||
|
|
||||||
// Socket API
|
// Socket API
|
||||||
RLAPI bool SocketCreate(SocketConfig *config, SocketResult *result);
|
bool SocketCreate(SocketConfig *config, SocketResult *result);
|
||||||
RLAPI bool SocketBind(SocketConfig *config, SocketResult *result);
|
bool SocketBind(SocketConfig *config, SocketResult *result);
|
||||||
RLAPI bool SocketListen(SocketConfig *config, SocketResult *result);
|
bool SocketListen(SocketConfig *config, SocketResult *result);
|
||||||
RLAPI bool SocketConnect(SocketConfig *config, SocketResult *result);
|
bool SocketConnect(SocketConfig *config, SocketResult *result);
|
||||||
RLAPI Socket *SocketAccept(Socket *server, SocketConfig *config);
|
Socket *SocketAccept(Socket *server, SocketConfig *config);
|
||||||
|
|
||||||
// UDP Socket API
|
// UDP Socket API
|
||||||
RLAPI int SocketSetChannel(Socket *socket, int channel, const IPAddress *address);
|
int SocketSetChannel(Socket *socket, int channel, const IPAddress *address);
|
||||||
RLAPI void SocketUnsetChannel(Socket *socket, int channel);
|
void SocketUnsetChannel(Socket *socket, int channel);
|
||||||
|
|
||||||
// UDP DataPacket API
|
// UDP DataPacket API
|
||||||
RLAPI SocketDataPacket *AllocPacket(int size);
|
SocketDataPacket *AllocPacket(int size);
|
||||||
RLAPI int ResizePacket(SocketDataPacket *packet, int newsize);
|
int ResizePacket(SocketDataPacket *packet, int newsize);
|
||||||
RLAPI void FreePacket(SocketDataPacket *packet);
|
void FreePacket(SocketDataPacket *packet);
|
||||||
RLAPI SocketDataPacket **AllocPacketList(int count, int size);
|
SocketDataPacket **AllocPacketList(int count, int size);
|
||||||
RLAPI void FreePacketList(SocketDataPacket **packets);
|
void FreePacketList(SocketDataPacket **packets);
|
||||||
|
|
||||||
// General Socket API
|
// General Socket API
|
||||||
RLAPI int SocketSend(Socket *sock, const void *datap, int len);
|
int SocketSend(Socket *sock, const void *datap, int len);
|
||||||
RLAPI int SocketReceive(Socket *sock, void *data, int maxlen);
|
int SocketReceive(Socket *sock, void *data, int maxlen);
|
||||||
RLAPI void SocketClose(Socket *sock);
|
void SocketClose(Socket *sock);
|
||||||
RLAPI SocketAddressStorage SocketGetPeerAddress(Socket *sock);
|
SocketAddressStorage SocketGetPeerAddress(Socket *sock);
|
||||||
RLAPI char* GetSocketAddressHost(SocketAddressStorage storage);
|
char* GetSocketAddressHost(SocketAddressStorage storage);
|
||||||
RLAPI short GetSocketAddressPort(SocketAddressStorage storage);
|
short GetSocketAddressPort(SocketAddressStorage storage);
|
||||||
|
|
||||||
// Socket Memory API
|
// Socket Memory API
|
||||||
RLAPI Socket *AllocSocket();
|
Socket *AllocSocket();
|
||||||
RLAPI void FreeSocket(Socket **sock);
|
void FreeSocket(Socket **sock);
|
||||||
RLAPI SocketResult *AllocSocketResult();
|
SocketResult *AllocSocketResult();
|
||||||
RLAPI void FreeSocketResult(SocketResult **result);
|
void FreeSocketResult(SocketResult **result);
|
||||||
RLAPI SocketSet *AllocSocketSet(int max);
|
SocketSet *AllocSocketSet(int max);
|
||||||
RLAPI void FreeSocketSet(SocketSet *sockset);
|
void FreeSocketSet(SocketSet *sockset);
|
||||||
|
|
||||||
// Socket I/O API
|
// Socket I/O API
|
||||||
RLAPI bool IsSocketReady(Socket *sock);
|
bool IsSocketReady(Socket *sock);
|
||||||
RLAPI bool IsSocketConnected(Socket *sock);
|
bool IsSocketConnected(Socket *sock);
|
||||||
RLAPI int AddSocket(SocketSet *set, Socket *sock);
|
int AddSocket(SocketSet *set, Socket *sock);
|
||||||
RLAPI int RemoveSocket(SocketSet *set, Socket *sock);
|
int RemoveSocket(SocketSet *set, Socket *sock);
|
||||||
RLAPI int CheckSockets(SocketSet *set, unsigned int timeout);
|
int CheckSockets(SocketSet *set, unsigned int timeout);
|
||||||
|
|
||||||
// Packet API
|
// Packet API
|
||||||
void PacketSend(Packet *packet);
|
void PacketSend(Packet *packet);
|
||||||
|
@ -400,4 +414,4 @@ uint64_t PacketRead64(Packet *packet);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // RNET_H
|
#endif // RNET_H
|
Loading…
Add table
Add a link
Reference in a new issue