author | nemo |
Mon, 09 Dec 2013 23:13:47 -0500 | |
changeset 9774 | 65cfbf379bdf |
parent 8083 | 2edbd01a04a0 |
child 10017 | de822cd3df3a |
permissions | -rw-r--r-- |
8083
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
1 |
/* |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
2 |
SDL_net: An example cross-platform network library for use with SDL |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
3 |
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org> |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
4 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
5 |
This software is provided 'as-is', without any express or implied |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
6 |
warranty. In no event will the authors be held liable for any damages |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
7 |
arising from the use of this software. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
8 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
9 |
Permission is granted to anyone to use this software for any purpose, |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
10 |
including commercial applications, and to alter it and redistribute it |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
11 |
freely, subject to the following restrictions: |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
12 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
13 |
1. The origin of this software must not be misrepresented; you must not |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
14 |
claim that you wrote the original software. If you use this software |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
15 |
in a product, an acknowledgment in the product documentation would be |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
16 |
appreciated but is not required. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
17 |
2. Altered source versions must be plainly marked as such, and must not be |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
18 |
misrepresented as being the original software. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
19 |
3. This notice may not be removed or altered from any source distribution. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
20 |
*/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
21 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
22 |
/* $Id$ */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
23 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
24 |
#ifndef _SDL_NET_H |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
25 |
#define _SDL_NET_H |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
26 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
27 |
#include "SDL.h" |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
28 |
#include "SDL_endian.h" |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
29 |
#include "SDL_version.h" |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
30 |
#include "begin_code.h" |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
31 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
32 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
33 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
34 |
/* Set up for C function definitions, even when using C++ */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
35 |
#ifdef __cplusplus |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
36 |
extern "C" { |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
37 |
#endif |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
38 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
39 |
/* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
40 |
*/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
41 |
#define SDL_NET_MAJOR_VERSION 1 |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
42 |
#define SDL_NET_MINOR_VERSION 2 |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
43 |
#define SDL_NET_PATCHLEVEL 8 |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
44 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
45 |
/* This macro can be used to fill a version structure with the compile-time |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
46 |
* version of the SDL_net library. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
47 |
*/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
48 |
#define SDL_NET_VERSION(X) \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
49 |
{ \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
50 |
(X)->major = SDL_NET_MAJOR_VERSION; \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
51 |
(X)->minor = SDL_NET_MINOR_VERSION; \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
52 |
(X)->patch = SDL_NET_PATCHLEVEL; \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
53 |
} |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
54 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
55 |
/* This function gets the version of the dynamically linked SDL_net library. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
56 |
it should NOT be used to fill a version structure, instead you should |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
57 |
use the SDL_NET_VERSION() macro. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
58 |
*/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
59 |
extern DECLSPEC const SDL_version * SDLCALL SDLNet_Linked_Version(void); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
60 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
61 |
/* Initialize/Cleanup the network API |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
62 |
SDL must be initialized before calls to functions in this library, |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
63 |
because this library uses utility functions from the SDL library. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
64 |
*/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
65 |
extern DECLSPEC int SDLCALL SDLNet_Init(void); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
66 |
extern DECLSPEC void SDLCALL SDLNet_Quit(void); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
67 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
68 |
/***********************************************************************/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
69 |
/* IPv4 hostname resolution API */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
70 |
/***********************************************************************/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
71 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
72 |
typedef struct { |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
73 |
Uint32 host; /* 32-bit IPv4 host address */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
74 |
Uint16 port; /* 16-bit protocol port */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
75 |
} IPaddress; |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
76 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
77 |
/* Resolve a host name and port to an IP address in network form. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
78 |
If the function succeeds, it will return 0. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
79 |
If the host couldn't be resolved, the host portion of the returned |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
80 |
address will be INADDR_NONE, and the function will return -1. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
81 |
If 'host' is NULL, the resolved host will be set to INADDR_ANY. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
82 |
*/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
83 |
#ifndef INADDR_ANY |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
84 |
#define INADDR_ANY 0x00000000 |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
85 |
#endif |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
86 |
#ifndef INADDR_NONE |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
87 |
#define INADDR_NONE 0xFFFFFFFF |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
88 |
#endif |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
89 |
#ifndef INADDR_BROADCAST |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
90 |
#define INADDR_BROADCAST 0xFFFFFFFF |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
91 |
#endif |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
92 |
extern DECLSPEC int SDLCALL SDLNet_ResolveHost(IPaddress *address, const char *host, Uint16 port); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
93 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
94 |
/* Resolve an ip address to a host name in canonical form. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
95 |
If the ip couldn't be resolved, this function returns NULL, |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
96 |
otherwise a pointer to a static buffer containing the hostname |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
97 |
is returned. Note that this function is not thread-safe. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
98 |
*/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
99 |
extern DECLSPEC const char * SDLCALL SDLNet_ResolveIP(const IPaddress *ip); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
100 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
101 |
/* Get the addresses of network interfaces on this system. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
102 |
This returns the number of addresses saved in 'addresses' |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
103 |
*/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
104 |
extern DECLSPEC int SDLCALL SDLNet_GetLocalAddresses(IPaddress *addresses, int maxcount); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
105 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
106 |
/***********************************************************************/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
107 |
/* TCP network API */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
108 |
/***********************************************************************/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
109 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
110 |
typedef struct _TCPsocket *TCPsocket; |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
111 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
112 |
/* Open a TCP network socket |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
113 |
If ip.host is INADDR_NONE or INADDR_ANY, this creates a local server |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
114 |
socket on the given port, otherwise a TCP connection to the remote |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
115 |
host and port is attempted. The address passed in should already be |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
116 |
swapped to network byte order (addresses returned from |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
117 |
SDLNet_ResolveHost() are already in the correct form). |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
118 |
The newly created socket is returned, or NULL if there was an error. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
119 |
*/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
120 |
extern DECLSPEC TCPsocket SDLCALL SDLNet_TCP_Open(IPaddress *ip); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
121 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
122 |
/* Accept an incoming connection on the given server socket. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
123 |
The newly created socket is returned, or NULL if there was an error. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
124 |
*/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
125 |
extern DECLSPEC TCPsocket SDLCALL SDLNet_TCP_Accept(TCPsocket server); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
126 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
127 |
/* Get the IP address of the remote system associated with the socket. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
128 |
If the socket is a server socket, this function returns NULL. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
129 |
*/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
130 |
extern DECLSPEC IPaddress * SDLCALL SDLNet_TCP_GetPeerAddress(TCPsocket sock); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
131 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
132 |
/* Send 'len' bytes of 'data' over the non-server socket 'sock' |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
133 |
This function returns the actual amount of data sent. If the return value |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
134 |
is less than the amount of data sent, then either the remote connection was |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
135 |
closed, or an unknown socket error occurred. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
136 |
*/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
137 |
extern DECLSPEC int SDLCALL SDLNet_TCP_Send(TCPsocket sock, const void *data, |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
138 |
int len); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
139 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
140 |
/* Receive up to 'maxlen' bytes of data over the non-server socket 'sock', |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
141 |
and store them in the buffer pointed to by 'data'. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
142 |
This function returns the actual amount of data received. If the return |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
143 |
value is less than or equal to zero, then either the remote connection was |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
144 |
closed, or an unknown socket error occurred. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
145 |
*/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
146 |
extern DECLSPEC int SDLCALL SDLNet_TCP_Recv(TCPsocket sock, void *data, int maxlen); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
147 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
148 |
/* Close a TCP network socket */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
149 |
extern DECLSPEC void SDLCALL SDLNet_TCP_Close(TCPsocket sock); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
150 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
151 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
152 |
/***********************************************************************/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
153 |
/* UDP network API */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
154 |
/***********************************************************************/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
155 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
156 |
/* The maximum channels on a a UDP socket */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
157 |
#define SDLNET_MAX_UDPCHANNELS 32 |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
158 |
/* The maximum addresses bound to a single UDP socket channel */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
159 |
#define SDLNET_MAX_UDPADDRESSES 4 |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
160 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
161 |
typedef struct _UDPsocket *UDPsocket; |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
162 |
typedef struct { |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
163 |
int channel; /* The src/dst channel of the packet */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
164 |
Uint8 *data; /* The packet data */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
165 |
int len; /* The length of the packet data */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
166 |
int maxlen; /* The size of the data buffer */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
167 |
int status; /* packet status after sending */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
168 |
IPaddress address; /* The source/dest address of an incoming/outgoing packet */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
169 |
} UDPpacket; |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
170 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
171 |
/* Allocate/resize/free a single UDP packet 'size' bytes long. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
172 |
The new packet is returned, or NULL if the function ran out of memory. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
173 |
*/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
174 |
extern DECLSPEC UDPpacket * SDLCALL SDLNet_AllocPacket(int size); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
175 |
extern DECLSPEC int SDLCALL SDLNet_ResizePacket(UDPpacket *packet, int newsize); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
176 |
extern DECLSPEC void SDLCALL SDLNet_FreePacket(UDPpacket *packet); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
177 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
178 |
/* Allocate/Free a UDP packet vector (array of packets) of 'howmany' packets, |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
179 |
each 'size' bytes long. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
180 |
A pointer to the first packet in the array is returned, or NULL if the |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
181 |
function ran out of memory. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
182 |
*/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
183 |
extern DECLSPEC UDPpacket ** SDLCALL SDLNet_AllocPacketV(int howmany, int size); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
184 |
extern DECLSPEC void SDLCALL SDLNet_FreePacketV(UDPpacket **packetV); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
185 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
186 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
187 |
/* Open a UDP network socket |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
188 |
If 'port' is non-zero, the UDP socket is bound to a local port. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
189 |
The 'port' should be given in native byte order, but is used |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
190 |
internally in network (big endian) byte order, in addresses, etc. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
191 |
This allows other systems to send to this socket via a known port. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
192 |
*/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
193 |
extern DECLSPEC UDPsocket SDLCALL SDLNet_UDP_Open(Uint16 port); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
194 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
195 |
/* Set the percentage of simulated packet loss for packets sent on the socket. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
196 |
*/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
197 |
extern DECLSPEC void SDLCALL SDLNet_UDP_SetPacketLoss(UDPsocket sock, int percent); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
198 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
199 |
/* Bind the address 'address' to the requested channel on the UDP socket. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
200 |
If the channel is -1, then the first unbound channel will be bound with |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
201 |
the given address as it's primary address. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
202 |
If the channel is already bound, this new address will be added to the |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
203 |
list of valid source addresses for packets arriving on the channel. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
204 |
If the channel is not already bound, then the address becomes the primary |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
205 |
address, to which all outbound packets on the channel are sent. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
206 |
This function returns the channel which was bound, or -1 on error. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
207 |
*/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
208 |
extern DECLSPEC int SDLCALL SDLNet_UDP_Bind(UDPsocket sock, int channel, const IPaddress *address); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
209 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
210 |
/* Unbind all addresses from the given channel */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
211 |
extern DECLSPEC void SDLCALL SDLNet_UDP_Unbind(UDPsocket sock, int channel); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
212 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
213 |
/* Get the primary IP address of the remote system associated with the |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
214 |
socket and channel. If the channel is -1, then the primary IP port |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
215 |
of the UDP socket is returned -- this is only meaningful for sockets |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
216 |
opened with a specific port. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
217 |
If the channel is not bound and not -1, this function returns NULL. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
218 |
*/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
219 |
extern DECLSPEC IPaddress * SDLCALL SDLNet_UDP_GetPeerAddress(UDPsocket sock, int channel); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
220 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
221 |
/* Send a vector of packets to the the channels specified within the packet. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
222 |
If the channel specified in the packet is -1, the packet will be sent to |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
223 |
the address in the 'src' member of the packet. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
224 |
Each packet will be updated with the status of the packet after it has |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
225 |
been sent, -1 if the packet send failed. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
226 |
This function returns the number of packets sent. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
227 |
*/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
228 |
extern DECLSPEC int SDLCALL SDLNet_UDP_SendV(UDPsocket sock, UDPpacket **packets, int npackets); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
229 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
230 |
/* Send a single packet to the specified channel. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
231 |
If the channel specified in the packet is -1, the packet will be sent to |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
232 |
the address in the 'src' member of the packet. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
233 |
The packet will be updated with the status of the packet after it has |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
234 |
been sent. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
235 |
This function returns 1 if the packet was sent, or 0 on error. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
236 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
237 |
NOTE: |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
238 |
The maximum size of the packet is limited by the MTU (Maximum Transfer Unit) |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
239 |
of the transport medium. It can be as low as 250 bytes for some PPP links, |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
240 |
and as high as 1500 bytes for ethernet. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
241 |
*/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
242 |
extern DECLSPEC int SDLCALL SDLNet_UDP_Send(UDPsocket sock, int channel, UDPpacket *packet); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
243 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
244 |
/* Receive a vector of pending packets from the UDP socket. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
245 |
The returned packets contain the source address and the channel they arrived |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
246 |
on. If they did not arrive on a bound channel, the the channel will be set |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
247 |
to -1. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
248 |
The channels are checked in highest to lowest order, so if an address is |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
249 |
bound to multiple channels, the highest channel with the source address |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
250 |
bound will be returned. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
251 |
This function returns the number of packets read from the network, or -1 |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
252 |
on error. This function does not block, so can return 0 packets pending. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
253 |
*/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
254 |
extern DECLSPEC int SDLCALL SDLNet_UDP_RecvV(UDPsocket sock, UDPpacket **packets); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
255 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
256 |
/* Receive a single packet from the UDP socket. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
257 |
The returned packet contains the source address and the channel it arrived |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
258 |
on. If it did not arrive on a bound channel, the the channel will be set |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
259 |
to -1. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
260 |
The channels are checked in highest to lowest order, so if an address is |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
261 |
bound to multiple channels, the highest channel with the source address |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
262 |
bound will be returned. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
263 |
This function returns the number of packets read from the network, or -1 |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
264 |
on error. This function does not block, so can return 0 packets pending. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
265 |
*/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
266 |
extern DECLSPEC int SDLCALL SDLNet_UDP_Recv(UDPsocket sock, UDPpacket *packet); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
267 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
268 |
/* Close a UDP network socket */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
269 |
extern DECLSPEC void SDLCALL SDLNet_UDP_Close(UDPsocket sock); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
270 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
271 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
272 |
/***********************************************************************/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
273 |
/* Hooks for checking sockets for available data */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
274 |
/***********************************************************************/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
275 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
276 |
typedef struct _SDLNet_SocketSet *SDLNet_SocketSet; |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
277 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
278 |
/* Any network socket can be safely cast to this socket type */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
279 |
typedef struct _SDLNet_GenericSocket { |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
280 |
int ready; |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
281 |
} *SDLNet_GenericSocket; |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
282 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
283 |
/* Allocate a socket set for use with SDLNet_CheckSockets() |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
284 |
This returns a socket set for up to 'maxsockets' sockets, or NULL if |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
285 |
the function ran out of memory. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
286 |
*/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
287 |
extern DECLSPEC SDLNet_SocketSet SDLCALL SDLNet_AllocSocketSet(int maxsockets); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
288 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
289 |
/* Add a socket to a set of sockets to be checked for available data */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
290 |
#define SDLNet_TCP_AddSocket(set, sock) \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
291 |
SDLNet_AddSocket(set, SDL_reinterpret_cast(SDLNet_GenericSocket, sock)) |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
292 |
#define SDLNet_UDP_AddSocket(set, sock) \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
293 |
SDLNet_AddSocket(set, SDL_reinterpret_cast(SDLNet_GenericSocket, sock)) |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
294 |
extern DECLSPEC int SDLCALL SDLNet_AddSocket(SDLNet_SocketSet set, SDLNet_GenericSocket sock); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
295 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
296 |
/* Remove a socket from a set of sockets to be checked for available data */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
297 |
#define SDLNet_TCP_DelSocket(set, sock) \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
298 |
SDLNet_DelSocket(set, SDL_reinterpret_cast(SDLNet_GenericSocket, sock)) |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
299 |
#define SDLNet_UDP_DelSocket(set, sock) \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
300 |
SDLNet_DelSocket(set, SDL_reinterpret_cast(SDLNet_GenericSocket, sock)) |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
301 |
extern DECLSPEC int SDLCALL SDLNet_DelSocket(SDLNet_SocketSet set, SDLNet_GenericSocket sock); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
302 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
303 |
/* This function checks to see if data is available for reading on the |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
304 |
given set of sockets. If 'timeout' is 0, it performs a quick poll, |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
305 |
otherwise the function returns when either data is available for |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
306 |
reading, or the timeout in milliseconds has elapsed, which ever occurs |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
307 |
first. This function returns the number of sockets ready for reading, |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
308 |
or -1 if there was an error with the select() system call. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
309 |
*/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
310 |
extern DECLSPEC int SDLCALL SDLNet_CheckSockets(SDLNet_SocketSet set, Uint32 timeout); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
311 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
312 |
/* After calling SDLNet_CheckSockets(), you can use this function on a |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
313 |
socket that was in the socket set, to find out if data is available |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
314 |
for reading. |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
315 |
*/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
316 |
#define SDLNet_SocketReady(sock) \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
317 |
((sock != NULL) && SDL_reinterpret_cast(SDLNet_GenericSocket, sock)->ready) |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
318 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
319 |
/* Free a set of sockets allocated by SDL_NetAllocSocketSet() */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
320 |
extern DECLSPEC void SDLCALL SDLNet_FreeSocketSet(SDLNet_SocketSet set); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
321 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
322 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
323 |
/***********************************************************************/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
324 |
/* Platform-independent data conversion functions */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
325 |
/***********************************************************************/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
326 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
327 |
/* Write a 16/32 bit value to network packet buffer */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
328 |
extern DECLSPEC void SDLCALL SDLNet_Write16(Uint16 value, void *area); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
329 |
extern DECLSPEC void SDLCALL SDLNet_Write32(Uint32 value, void *area); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
330 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
331 |
/* Read a 16/32 bit value from network packet buffer */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
332 |
extern DECLSPEC Uint16 SDLCALL SDLNet_Read16(void *area); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
333 |
extern DECLSPEC Uint32 SDLCALL SDLNet_Read32(void *area); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
334 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
335 |
/***********************************************************************/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
336 |
/* Error reporting functions */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
337 |
/***********************************************************************/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
338 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
339 |
/* We'll use SDL's functions for error reporting */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
340 |
#define SDLNet_SetError SDL_SetError |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
341 |
#define SDLNet_GetError SDL_GetError |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
342 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
343 |
/* I'm eventually going to try to disentangle SDL_net from SDL, thus making |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
344 |
SDL_net an independent X-platform networking toolkit. Not today though.... |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
345 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
346 |
extern no_parse_DECLSPEC void SDLCALL SDLNet_SetError(const char *fmt, ...); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
347 |
extern no_parse_DECLSPEC char * SDLCALL SDLNet_GetError(void); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
348 |
*/ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
349 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
350 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
351 |
/* Inline macro functions to read/write network data */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
352 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
353 |
/* Warning, some systems have data access alignment restrictions */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
354 |
#if defined(sparc) || defined(mips) |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
355 |
#define SDL_DATA_ALIGNED 1 |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
356 |
#endif |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
357 |
#ifndef SDL_DATA_ALIGNED |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
358 |
#define SDL_DATA_ALIGNED 0 |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
359 |
#endif |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
360 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
361 |
/* Write a 16 bit value to network packet buffer */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
362 |
#if !SDL_DATA_ALIGNED |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
363 |
#define SDLNet_Write16(value, areap) \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
364 |
(*SDL_reinterpret_cast(Uint16 *, areap) = SDL_SwapBE16(value)) |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
365 |
#else |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
366 |
#if SDL_BYTEORDER == SDL_BIG_ENDIAN |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
367 |
#define SDLNet_Write16(value, areap) \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
368 |
do \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
369 |
{ \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
370 |
Uint8 *area = SDL_reinterpret_cast(Uint8 *, areap); \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
371 |
area[0] = (value >> 8) & 0xFF; \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
372 |
area[1] = value & 0xFF; \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
373 |
} while ( 0 ) |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
374 |
#else |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
375 |
#define SDLNet_Write16(value, areap) \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
376 |
do \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
377 |
{ \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
378 |
Uint8 *area = SDL_reinterpret_cast(Uint8 *, areap); \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
379 |
area[1] = (value >> 8) & 0xFF; \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
380 |
area[0] = value & 0xFF; \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
381 |
} while ( 0 ) |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
382 |
#endif |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
383 |
#endif /* !SDL_DATA_ALIGNED */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
384 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
385 |
/* Write a 32 bit value to network packet buffer */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
386 |
#if !SDL_DATA_ALIGNED |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
387 |
#define SDLNet_Write32(value, areap) \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
388 |
*SDL_reinterpret_cast(Uint32 *, areap) = SDL_SwapBE32(value); |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
389 |
#else |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
390 |
#if SDL_BYTEORDER == SDL_BIG_ENDIAN |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
391 |
#define SDLNet_Write32(value, areap) \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
392 |
do \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
393 |
{ \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
394 |
Uint8 *area = SDL_reinterpret_cast(Uint8 *, areap); \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
395 |
area[0] = (value >> 24) & 0xFF; \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
396 |
area[1] = (value >> 16) & 0xFF; \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
397 |
area[2] = (value >> 8) & 0xFF; \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
398 |
area[3] = value & 0xFF; \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
399 |
} while ( 0 ) |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
400 |
#else |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
401 |
#define SDLNet_Write32(value, areap) \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
402 |
do \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
403 |
{ \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
404 |
Uint8 *area = SDL_reinterpret_cast(Uint8 *, areap); \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
405 |
area[3] = (value >> 24) & 0xFF; \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
406 |
area[2] = (value >> 16) & 0xFF; \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
407 |
area[1] = (value >> 8) & 0xFF; \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
408 |
area[0] = value & 0xFF; \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
409 |
} while ( 0 ) |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
410 |
#endif |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
411 |
#endif /* !SDL_DATA_ALIGNED */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
412 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
413 |
/* Read a 16 bit value from network packet buffer */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
414 |
#if !SDL_DATA_ALIGNED |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
415 |
#define SDLNet_Read16(areap) \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
416 |
(SDL_SwapBE16(*SDL_reinterpret_cast(Uint16 *, areap))) |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
417 |
#else |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
418 |
#if SDL_BYTEORDER == SDL_BIG_ENDIAN |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
419 |
#define SDLNet_Read16(areap) \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
420 |
(((SDL_reinterpret_cast(Uint8 *, areap))[0] << 8) | (SDL_reinterpret_cast(Uint8 *, areap))[1] << 0) |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
421 |
#else |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
422 |
#define SDLNet_Read16(areap) \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
423 |
(((SDL_reinterpret_cast(Uint8 *, areap))[1] << 8) | (SDL_reinterpret_cast(Uint8 *, areap))[0] << 0) |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
424 |
#endif |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
425 |
#endif /* !SDL_DATA_ALIGNED */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
426 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
427 |
/* Read a 32 bit value from network packet buffer */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
428 |
#if !SDL_DATA_ALIGNED |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
429 |
#define SDLNet_Read32(areap) \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
430 |
(SDL_SwapBE32(*SDL_reinterpret_cast(Uint32 *, areap))) |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
431 |
#else |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
432 |
#if SDL_BYTEORDER == SDL_BIG_ENDIAN |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
433 |
#define SDLNet_Read32(areap) \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
434 |
(((SDL_reinterpret_cast(Uint8 *, areap))[0] << 24) | ((SDL_reinterpret_cast(Uint8 *, areap))[1] << 16) | \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
435 |
((SDL_reinterpret_cast(Uint8 *, areap))[2] << 8) | (SDL_reinterpret_cast(Uint8 *, areap))[3] << 0) |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
436 |
#else |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
437 |
#define SDLNet_Read32(areap) \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
438 |
(((SDL_reinterpret_cast(Uint8 *, areap))[3] << 24) | ((SDL_reinterpret_cast(Uint8 *, areap))[2] << 16) | \ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
439 |
((SDL_reinterpret_cast(Uint8 *, areap))[1] << 8) | (SDL_reinterpret_cast(Uint8 *, areap))[0] << 0) |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
440 |
#endif |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
441 |
#endif /* !SDL_DATA_ALIGNED */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
442 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
443 |
/* Ends C function definitions when using C++ */ |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
444 |
#ifdef __cplusplus |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
445 |
} |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
446 |
#endif |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
447 |
#include "close_code.h" |
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
448 |
|
2edbd01a04a0
added sdl_net headers and def lib for windows, fix frontlib compilation on windows
koda
parents:
diff
changeset
|
449 |
#endif /* _SDL_NET_H */ |