Final commit of some WIP work, parking the project for the moment until i have time to work on this properly
Signed-off-by: Jak Barnes <contact@jakbarnes.co.uk>
This commit is contained in:
parent
739f951fba
commit
0464a8aaf4
1 changed files with 784 additions and 418 deletions
93
src/raylib.h
93
src/raylib.h
|
|
@ -479,7 +479,7 @@ typedef struct VrStereoConfig {
|
|||
} VrStereoConfig;
|
||||
|
||||
// Network typedefs
|
||||
typedef uint32_t SocketChannel;
|
||||
typedef uint32_t SocketChannel;
|
||||
typedef struct _AddressInformation * AddressInformation;
|
||||
typedef struct _SocketAddress * SocketAddress;
|
||||
typedef struct _SocketAddressIPv4 * SocketAddressIPv4;
|
||||
|
|
@ -487,81 +487,89 @@ typedef struct _SocketAddressIPv6 * SocketAddressIPv6;
|
|||
typedef struct _SocketAddressStorage *SocketAddressStorage;
|
||||
|
||||
// IPAddress definition (in network byte order)
|
||||
typedef struct IPAddress {
|
||||
typedef struct IPAddress
|
||||
{
|
||||
unsigned long host; /* 32-bit IPv4 host address */
|
||||
unsigned short port; /* 16-bit protocol port */
|
||||
} IPAddress;
|
||||
} IPAddress;
|
||||
|
||||
// An option ID, value, sizeof(value) tuple for setsockopt(2).
|
||||
typedef struct SocketOpt {
|
||||
typedef struct SocketOpt
|
||||
{
|
||||
int id;
|
||||
void *value;
|
||||
int valueLen;
|
||||
} SocketOpt;
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
SOCKET_TCP = 1, // SOCK_STREAM
|
||||
SOCKET_UDP = 2 // SOCK_DGRAM
|
||||
} SocketType;
|
||||
|
||||
typedef struct UDPChannel {
|
||||
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 {
|
||||
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)
|
||||
bool isIPv6;
|
||||
SocketChannel channel; // The socket handle id
|
||||
SocketType type; // Is this socket a TCP or UDP socket?
|
||||
IPAddress address; // The host/target IPv4 for this socket (in network byte order)
|
||||
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 {
|
||||
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. Not all of these fields need to
|
||||
// be set, and ones omitted from a C99-style "designated initializer"
|
||||
// struct literal will be zeroed out and replaced with defaults.
|
||||
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;
|
||||
bool nonblocking; // non-blocking operation?
|
||||
int backlog_size; // set a custom backlog size
|
||||
SocketOpt sockopts[SOCKET_MAX_SOCK_OPTS];
|
||||
} SocketConfig;
|
||||
// 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];
|
||||
} SocketConfig;
|
||||
|
||||
// Result from calling open with a given config.
|
||||
typedef struct SocketResult {
|
||||
typedef struct SocketResult
|
||||
{
|
||||
int status;
|
||||
Socket *socket;
|
||||
Socket *socket;
|
||||
} SocketResult;
|
||||
|
||||
//
|
||||
typedef struct Packet {
|
||||
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
|
||||
uint8_t *data; // Data stored in network byte order
|
||||
} Packet;
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
@ -1539,6 +1547,8 @@ RLAPI int GetAddressProtocol(AddressInformation address);
|
|||
RLAPI char* GetAddressCanonName(AddressInformation address);
|
||||
RLAPI char *GetAddressHostAndPort(AddressInformation address, char *outhost, int *outport);
|
||||
RLAPI void PrintAddressInfo(AddressInformation address);
|
||||
|
||||
// Address Memory API
|
||||
RLAPI AddressInformation AllocAddress();
|
||||
RLAPI void FreeAddress(AddressInformation* addressInfo);
|
||||
RLAPI AddressInformation *AllocAddressList(int size);
|
||||
|
|
@ -1553,14 +1563,23 @@ RLAPI Socket *SocketAccept(Socket *server, SocketConfig *config);
|
|||
// UDP Socket API
|
||||
RLAPI int SocketSetChannel(Socket *socket, int channel, const IPAddress *address);
|
||||
RLAPI void SocketUnsetChannel(Socket *socket, int channel);
|
||||
RLAPI IPAddress* SocketGetPeerAddress(Socket *socket, int channel);
|
||||
|
||||
// UDP DataPacket API
|
||||
RLAPI SocketDataPacket *AllocPacket(int size);
|
||||
RLAPI int ResizePacket(SocketDataPacket *packet, int newsize);
|
||||
RLAPI void FreePacket(SocketDataPacket *packet);
|
||||
RLAPI SocketDataPacket** AllocPacketList(int count, int size);
|
||||
RLAPI void FreePacketList(SocketDataPacket **packets);
|
||||
|
||||
// General Socket API
|
||||
RLAPI int SocketSend(Socket *sock, const void *datap, int len);
|
||||
RLAPI int SocketReceive(Socket *sock, void *data, int maxlen);
|
||||
RLAPI void SocketClose(Socket* sock);
|
||||
RLAPI int SocketReady(Socket* sock);
|
||||
RLAPI SocketAddressStorage SocketGetPeerAddress(Socket* sock);
|
||||
RLAPI char* GetSocketAddressHost(SocketAddressStorage storage);
|
||||
RLAPI short GetSocketAddressPort(SocketAddressStorage storage);
|
||||
|
||||
// Socket Memory API
|
||||
RLAPI Socket *AllocSocket();
|
||||
RLAPI void FreeSocket(Socket **sock);
|
||||
RLAPI SocketResult *AllocSocketResult();
|
||||
|
|
@ -1576,8 +1595,8 @@ RLAPI int RemoveSocket(SocketSet *set, Socket *sock);
|
|||
RLAPI int CheckSockets(SocketSet *set, unsigned int timeout);
|
||||
|
||||
// Packet API
|
||||
Packet * AllocPacket(int size);
|
||||
void FreePacket(Packet *packet);
|
||||
// Packet * AllocPacket(int size);
|
||||
// void FreePacket(Packet *packet);
|
||||
void PacketSend(Packet *packet);
|
||||
void PacketReceive(Packet *packet);
|
||||
void PacketWrite8(Packet *packet, uint16_t value);
|
||||
|
|
|
|||
Loading…
Reference in a new issue