DEADSOFTWARE

Изменены физические константы
[netwar.git] / network.h
1 #ifndef NETWORK_H_INCLUDED
2 #define NETWORK_H_INCLUDED
4 #include <SDL2/SDL_net.h>
5 #include <stdbool.h>
7 #include "protocol.h"
9 static inline UDPsocket OpenPort(uint16_t port) {
10 UDPsocket sock = SDLNet_UDP_Open(SDL_SwapLE16(port));
11 if(!sock) {
12 SDL_Log("SDLNet_UDP_Open: %s\n", SDLNet_GetError());
13 exit(1);
14 }
15 return sock;
16 }
18 static inline void ClosePort(UDPsocket sock) {
19 SDLNet_UDP_Close(sock);
20 }
22 void SendMessage(UDPsocket sock, IPaddress address, ProtocolMessage m);
23 bool RecvMessage(UDPsocket sock, IPaddress * address, ProtocolMessage * m);
24 bool WaitMessage(UDPsocket sock, IPaddress * address, ProtocolMessage * m, uint32_t timeout);
26 #endif /* NETWORK_H_INCLUDED */