Polyphase Game Engine
Loading...
Searching...
No Matches
Network.h
Go to the documentation of this file.
1#pragma once
2
4
7void NET_Update();
8
10
11SocketHandle NET_SocketCreate();
12void NET_SocketBind(SocketHandle socketHandle, uint32_t ipAddr, uint16_t port);
13int32_t NET_SocketRecv(SocketHandle socketHandle, char* buffer, uint32_t size);
14int32_t NET_SocketRecvFrom(SocketHandle socketHandle, char* buffer, uint32_t size, uint32_t& addr, uint16_t& port);
15int32_t NET_SocketSendTo(SocketHandle socketHandle, const char* buffer, uint32_t size, uint32_t addr, uint16_t port);
16void NET_SocketClose(SocketHandle socketHandle);
17void NET_SocketSetBlocking(SocketHandle socketHandle, bool blocking);
18void NET_SocketSetBroadcast(SocketHandle socketHandle, bool broadcast);
19void NET_SocketGetIpAndPort(SocketHandle socketHandle, uint32_t& ipAddr, uint16_t& port);
20
21// ---------------------------------------------------------------------------
22// TCP / stream-oriented primitives. Used by HTTP/HTTPS, websockets, and any
23// future protocol that needs reliable streaming. UDP-only platforms can leave
24// these as no-op stubs that return failure.
25// ---------------------------------------------------------------------------
27bool NET_SocketConnect(SocketHandle socketHandle, uint32_t ipAddr, uint16_t port, int32_t timeoutMs);
28int32_t NET_SocketSend(SocketHandle socketHandle, const char* buffer, uint32_t size);
29
30// Begin a non-blocking connect on a stream socket. Returns false on immediate
31// failure. Poll with NET_SocketConnectPoll each frame. The socket is left
32// non-blocking afterwards, which is what a per-frame pump (WebSocket) wants -
33// NET_SocketConnect above is the blocking-with-timeout variant and restores
34// blocking mode, so worker-thread callers should keep using that one.
35bool NET_SocketConnectAsync(SocketHandle socketHandle, uint32_t ipAddr, uint16_t port);
36
37// -1 = failed, 0 = still connecting, 1 = connected.
38int32_t NET_SocketConnectPoll(SocketHandle socketHandle);
39
40// Classify a negative NET_SocketSend / NET_SocketRecv result. A non-blocking
41// stream socket returns a negative count both when it is merely out of data
42// and when the connection is dead, and there is no portable way to tell those
43// apart from the count alone. Pass the value the call returned - libogc
44// reports the error in the return value while the BSD platforms use errno /
45// WSAGetLastError. True means "still healthy, just nothing to do".
46bool NET_SocketWouldBlock(SocketHandle socketHandle, int32_t opResult);
47
48// Synchronous DNS resolve. Returns 0 on failure. Hostname may be a literal IP.
49// NOTE: this blocks. Callers that pump per frame should either connect at a
50// moment where a stall is acceptable (menu / level load) or pass a numeric IP,
51// which bypasses the resolver on every platform.
52uint32_t NET_ResolveHost(const char* hostname);
53
54uint32_t NET_IpStringToUint32(const char* ipString);
55void NET_IpUint32ToString(uint32_t ipUint32, char* outIpString);
56
59
60// TODO: Update LAN servers on NET_Update()
61//void NET_GetLanServers();
int32_t NET_SocketSendTo(SocketHandle socketHandle, const char *buffer, uint32_t size, uint32_t addr, uint16_t port)
void NET_Initialize()
SocketHandle NET_SocketCreateStream()
int32_t NET_SocketRecvFrom(SocketHandle socketHandle, char *buffer, uint32_t size, uint32_t &addr, uint16_t &port)
int32_t NET_SocketSend(SocketHandle socketHandle, const char *buffer, uint32_t size)
void NET_Update()
void NET_SocketClose(SocketHandle socketHandle)
uint32_t NET_GetSubnetMask()
bool NET_SocketConnectAsync(SocketHandle socketHandle, uint32_t ipAddr, uint16_t port)
void NET_SocketSetBroadcast(SocketHandle socketHandle, bool broadcast)
bool NET_IsActive()
void NET_SocketSetBlocking(SocketHandle socketHandle, bool blocking)
uint32_t NET_GetIpAddress()
bool NET_SocketConnect(SocketHandle socketHandle, uint32_t ipAddr, uint16_t port, int32_t timeoutMs)
bool NET_SocketWouldBlock(SocketHandle socketHandle, int32_t opResult)
void NET_SocketGetIpAndPort(SocketHandle socketHandle, uint32_t &ipAddr, uint16_t &port)
uint32_t NET_ResolveHost(const char *hostname)
int32_t NET_SocketRecv(SocketHandle socketHandle, char *buffer, uint32_t size)
void NET_SocketBind(SocketHandle socketHandle, uint32_t ipAddr, uint16_t port)
SocketHandle NET_SocketCreate()
int32_t NET_SocketConnectPoll(SocketHandle socketHandle)
void NET_Shutdown()
void NET_IpUint32ToString(uint32_t ipUint32, char *outIpString)
uint32_t NET_IpStringToUint32(const char *ipString)