SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
SDL3pp_net.h
1#ifndef SDL3PP_NET_H_
2#define SDL3PP_NET_H_
3
4#include "SDL3pp_properties.h"
5#include "SDL3pp_version.h"
6
7#ifdef SDL3PP_ENABLE_NET
8
9#include <SDL3_net/SDL_net.h>
10
11namespace SDL {
12
100
101// Forward decl
102struct AddressBase;
103
104// Forward decl
105struct Address;
106
108using AddressRaw = NET_Address*;
109
116
117// Forward decl
118struct StreamSocketBase;
119
120// Forward decl
121struct StreamSocket;
122
124using StreamSocketRaw = NET_StreamSocket*;
125
132
133// Forward decl
134struct ServerBase;
135
136// Forward decl
137struct Server;
138
140using ServerRaw = NET_Server*;
141
148
149// Forward decl
150struct DatagramSocketBase;
151
152// Forward decl
153struct DatagramSocket;
154
156using DatagramSocketRaw = NET_DatagramSocket*;
157
164
165// Forward decl
166struct DatagramBase;
167
168// Forward decl
169struct Datagram;
170
172using DatagramRaw = NET_Datagram*;
173
175using DatagramRawConst = const NET_Datagram*;
176
183
186
187#ifdef SDL3PP_DOC
188
196#define SDL_NET_MAJOR_VERSION
197
205#define SDL_NET_MINOR_VERSION
206
214#define SDL_NET_MICRO_VERSION
215
223#define SDL_NET_VERSION \
224 SDL_VERSIONNUM( \
225 SDL_NET_MAJOR_VERSION, SDL_NET_MINOR_VERSION, SDL_NET_MICRO_VERSION)
226
232#define SDL_NET_VERSION_ATLEAST(X, Y, Z) \
233 ((SDL_NET_MAJOR_VERSION >= X) && \
234 (SDL_NET_MAJOR_VERSION > X || SDL_NET_MINOR_VERSION >= Y) && \
235 (SDL_NET_MAJOR_VERSION > X || SDL_NET_MINOR_VERSION > Y || \
236 SDL_NET_MICRO_VERSION >= Z))
237
238#endif /* SDL3PP_DOC */
239
240namespace NET {
241
251inline int Version() { return NET_Version(); }
252
271inline void Init() { CheckError(NET_Init()); }
272
292inline void Quit() { NET_Quit(); }
293
294} // namespace NET
295
314using Status = NET_Status;
315
316constexpr Status FAILURE =
317 NET_FAILURE;
318
320constexpr Status WAITING = NET_WAITING;
321
322constexpr Status SUCCESS =
323 NET_SUCCESS;
324
330struct AddressBase : ResourceBaseT<AddressRaw>
331{
333
355 void Unref();
356
397
426
454 const char* GetString();
455
497 const void* GetBytes(int* num_bytes);
498
513 int Compare(AddressRef b) const;
514
519 bool operator==(const AddressBase& other) const;
520
526 auto operator<=>(const AddressBase& other) const;
527
584
647
732};
733
756{
757 using AddressBase::AddressBase;
758
766 constexpr explicit Address(AddressRaw resource) noexcept
767 : AddressBase(resource)
768 {
769 }
770
772 constexpr Address(Address&& other) noexcept
773 : Address(other.release())
774 {
775 }
776
813 Address(StringParam host);
814
851 Address(const Address& address);
852
860 static Address borrow(AddressRaw resource)
861 {
862 if (resource) {
863 NET_RefAddress(resource);
864 return Address(resource);
865 }
866 return {};
867 }
868
870 ~Address() { NET_UnrefAddress(get()); }
871
873 constexpr Address& operator=(Address&& other) noexcept
874 {
875 swap(*this, other);
876 return *this;
877 }
878
880 Address& operator=(const Address& other)
881 {
882 if (get() != other.get()) {
883 Address tmp(other);
884 swap(*this, tmp);
885 }
886 return *this;
887 }
888};
889
926inline Address ResolveHostname(StringParam host) { return Address(host); }
927
929 : Address(CheckError(NET_ResolveHostname(host)))
930{
931}
932
933inline Address::Address(const Address& address)
934 : Address(address ? NET_RefAddress(address.get()) : nullptr)
935{
936}
937
979{
980 return NET_WaitUntilResolved(address, timeout);
981}
982
984{
985 return SDL::WaitUntilResolved(get(), timeout);
986}
987
1016{
1017 return NET_GetAddressStatus(address);
1018}
1019
1021
1050inline const char* GetAddressString(AddressRef address)
1051{
1052 return CheckError(NET_GetAddressString(address));
1053}
1054
1055inline const char* AddressBase::GetString()
1056{
1057 return SDL::GetAddressString(get());
1058}
1059
1101inline const void* GetAddressBytes(AddressRef address, int* num_bytes)
1102{
1103 return CheckError(NET_GetAddressBytes(address, num_bytes));
1104}
1105
1106inline const void* AddressBase::GetBytes(int* num_bytes)
1107{
1108 return SDL::GetAddressBytes(get(), num_bytes);
1109}
1110
1146inline Address RefAddress(AddressRef address) { return Address(address); }
1147
1170inline void UnrefAddress(AddressRaw address) { NET_UnrefAddress(address); }
1171
1173
1203inline void SimulateAddressResolutionLoss(int percent_loss)
1204{
1205 NET_SimulateAddressResolutionLoss(percent_loss);
1206}
1207
1224{
1225 return NET_CompareAddresses(a, b);
1226}
1227
1229{
1230 return SDL::CompareAddresses(get(), b);
1231}
1232
1233inline bool AddressBase::operator==(const AddressBase& other) const
1234{
1235 return Compare(other) == 0;
1236}
1237
1238inline auto AddressBase::operator<=>(const AddressBase& other) const
1239{
1240 return Compare(other) <=> 0;
1241}
1242
1244struct LocalAddressesArrayDeleter
1245{
1247 static void operator()(AddressRef* addresses);
1248};
1249
1255
1284{
1285 int count;
1286 auto* addrs = CheckError(NET_GetLocalAddresses(&count));
1287 return LocalAddressesArray(reinterpret_cast<AddressRef*>(addrs), count);
1288}
1289
1311inline void FreeLocalAddresses(AddressRef* addresses)
1312{
1313 NET_FreeLocalAddresses(reinterpret_cast<AddressRaw*>(addresses));
1314}
1315
1316inline void LocalAddressesArrayDeleter::operator()(AddressRef* addresses)
1317{
1318 FreeLocalAddresses(addresses);
1319}
1320
1326struct StreamSocketBase : ResourceBaseT<StreamSocketRaw>
1327{
1329
1355 void Destroy();
1356
1399
1417
1454
1499 bool WriteTo(const void* buf, int buflen);
1500
1530 int GetPendingWrites();
1531
1569 int WaitUntilDrained(Sint32 timeout);
1570
1618 int ReadFrom(void* buf, int buflen);
1619
1656 void SimulateStreamPacketLoss(int percent_loss);
1657};
1658
1678{
1679 using StreamSocketBase::StreamSocketBase;
1680
1688 constexpr explicit StreamSocket(StreamSocketRaw resource) noexcept
1689 : StreamSocketBase(resource)
1690 {
1691 }
1692
1694 constexpr StreamSocket(StreamSocket&& other) noexcept
1695 : StreamSocket(other.release())
1696 {
1697 }
1698
1755 StreamSocket(AddressRef address, Uint16 port, PropertiesRef props);
1756
1758 ~StreamSocket() { NET_DestroyStreamSocket(get()); }
1759
1761 constexpr StreamSocket& operator=(StreamSocket&& other) noexcept
1762 {
1763 swap(*this, other);
1764 return *this;
1765 }
1766};
1767
1823 Uint16 port,
1824 PropertiesRef props)
1825{
1826 return StreamSocket(address, port, props);
1827}
1828
1830{
1831 return StreamSocket(get(), port, props);
1832}
1833
1835 Uint16 port,
1836 PropertiesRef props)
1837 : StreamSocket(CheckError(NET_CreateClient(address, port, props)))
1838{
1839}
1840
1884{
1885 return NET_WaitUntilConnected(sock, timeout);
1886}
1887
1889{
1890 return SDL::WaitUntilConnected(get(), timeout);
1891}
1892
1898struct ServerBase : ResourceBaseT<ServerRaw>
1899{
1901
1920 void Destroy();
1921
1960 void AcceptClient(NET_StreamSocket** client_stream);
1961};
1962
1980{
1981 using ServerBase::ServerBase;
1982
1990 constexpr explicit Server(ServerRaw resource) noexcept
1991 : ServerBase(resource)
1992 {
1993 }
1994
1996 constexpr Server(Server&& other) noexcept
1997 : Server(other.release())
1998 {
1999 }
2000
2063 Server(AddressRef addr, Uint16 port, PropertiesRef props);
2064
2066 ~Server() { NET_DestroyServer(get()); }
2067
2069 constexpr Server& operator=(Server&& other) noexcept
2070 {
2071 swap(*this, other);
2072 return *this;
2073 }
2074};
2075
2139{
2140 return Server(addr, port, props);
2141}
2142
2144{
2145 return Server(get(), port, props);
2146}
2147
2149 : Server(CheckError(NET_CreateServer(addr, port, props)))
2150{
2151}
2152
2153namespace prop::Server {
2154
2155constexpr auto REUSEADDR_BOOLEAN =
2156 NET_PROP_SERVER_REUSEADDR_BOOLEAN;
2157
2158} // namespace prop::Server
2159
2199inline void AcceptClient(ServerRef server, NET_StreamSocket** client_stream)
2200{
2201 CheckError(NET_AcceptClient(server, client_stream));
2202}
2203
2204inline void ServerBase::AcceptClient(NET_StreamSocket** client_stream)
2205{
2206 SDL::AcceptClient(get(), client_stream);
2207}
2208
2228inline void DestroyServer(ServerRaw server) { NET_DestroyServer(server); }
2229
2231
2250{
2251 return Address(CheckError(NET_GetStreamSocketAddress(sock)));
2252}
2253
2258
2295{
2296 return NET_GetConnectionStatus(sock);
2297}
2298
2303
2350 const void* buf,
2351 int buflen)
2352{
2353 return NET_WriteToStreamSocket(sock, buf, buflen);
2354}
2355
2356inline bool StreamSocketBase::WriteTo(const void* buf, int buflen)
2357{
2358 return SDL::WriteToStreamSocket(get(), buf, buflen);
2359}
2360
2392{
2393 return NET_GetStreamSocketPendingWrites(sock);
2394}
2395
2400
2440{
2441 return NET_WaitUntilStreamSocketDrained(sock, timeout);
2442}
2443
2445{
2446 return SDL::WaitUntilStreamSocketDrained(get(), timeout);
2447}
2448
2497inline int ReadFromStreamSocket(StreamSocketRef sock, void* buf, int buflen)
2498{
2499 return NET_ReadFromStreamSocket(sock, buf, buflen);
2500}
2501
2502inline int StreamSocketBase::ReadFrom(void* buf, int buflen)
2503{
2504 return SDL::ReadFromStreamSocket(get(), buf, buflen);
2505}
2506
2544inline void SimulateStreamPacketLoss(StreamSocketRef sock, int percent_loss)
2545{
2546 NET_SimulateStreamPacketLoss(sock, percent_loss);
2547}
2548
2550{
2551 SDL::SimulateStreamPacketLoss(get(), percent_loss);
2552}
2553
2582{
2583 NET_DestroyStreamSocket(sock);
2584}
2585
2587
2593struct DatagramSocketBase : ResourceBaseT<DatagramSocketRaw>
2594{
2596
2620 void Destroy();
2621
2701 bool SendDatagram(AddressRef address,
2702 Uint16 port,
2703 const void* buf,
2704 int buflen);
2705
2751 bool ReceiveDatagram(Datagram& dgram);
2752
2798
2828 void SimulateDatagramPacketLoss(int percent_loss);
2829};
2830
2857{
2858 using DatagramSocketBase::DatagramSocketBase;
2859
2867 constexpr explicit DatagramSocket(DatagramSocketRaw resource) noexcept
2868 : DatagramSocketBase(resource)
2869 {
2870 }
2871
2873 constexpr DatagramSocket(DatagramSocket&& other) noexcept
2874 : DatagramSocket(other.release())
2875 {
2876 }
2877
2963 DatagramSocket(AddressRef addr, Uint16 port, PropertiesRef props);
2964
2966 ~DatagramSocket() { NET_DestroyDatagramSocket(get()); }
2967
2969 constexpr DatagramSocket& operator=(DatagramSocket&& other) noexcept
2970 {
2971 swap(*this, other);
2972 return *this;
2973 }
2974};
2975
2981struct DatagramBase : ResourceBaseT<DatagramRaw, DatagramRawConst>
2982{
2984
2986 constexpr operator DatagramConstRef() const noexcept { return get(); }
2987
3006 void Destroy();
3007
3053 bool Receive(DatagramSocketRef sock);
3054};
3055
3067{
3068 using DatagramBase::DatagramBase;
3069
3077 constexpr explicit Datagram(DatagramRaw resource) noexcept
3078 : DatagramBase(resource)
3079 {
3080 }
3081
3083 constexpr Datagram(Datagram&& other) noexcept
3084 : Datagram(other.release())
3085 {
3086 }
3087
3134
3136 ~Datagram() { NET_DestroyDatagram(get()); }
3137
3139 constexpr Datagram& operator=(Datagram&& other) noexcept
3140 {
3141 swap(*this, other);
3142 return *this;
3143 }
3144};
3145
3232 Uint16 port,
3233 PropertiesRef props)
3234{
3235 return DatagramSocket(addr, port, props);
3236}
3237
3239 PropertiesRef props)
3240{
3241 return DatagramSocket(get(), port, props);
3242}
3243
3245 Uint16 port,
3246 PropertiesRef props)
3247 : DatagramSocket(CheckError(NET_CreateDatagramSocket(addr, port, props)))
3248{
3249}
3250
3251namespace prop::DatagramSocket {
3252
3253constexpr auto REUSEADDR_BOOLEAN =
3254 NET_PROP_DATAGRAM_SOCKET_REUSEADDR_BOOLEAN;
3255
3256constexpr auto ALLOW_BROADCAST_BOOLEAN =
3257 NET_PROP_DATAGRAM_SOCKET_ALLOW_BROADCAST_BOOLEAN;
3259
3260} // namespace prop::DatagramSocket
3261
3341 AddressRef address,
3342 Uint16 port,
3343 const void* buf,
3344 int buflen)
3345{
3346 return NET_SendDatagram(sock, address, port, buf, buflen);
3347}
3348
3350 Uint16 port,
3351 const void* buf,
3352 int buflen)
3353{
3354 return SDL::SendDatagram(get(), address, port, buf, buflen);
3355}
3356
3403{
3404 return dgram.Receive(sock);
3405}
3406
3452{
3453 Datagram dgram;
3454 dgram.Receive(sock);
3455 return dgram;
3456}
3457
3459{
3460 return dgram.Receive(*this);
3461}
3462
3467
3469 : Datagram(sock.ReceiveDatagram())
3470{
3471}
3472
3474{
3475 DatagramRaw dgram;
3476 if (!NET_ReceiveDatagram(sock, &dgram)) return false;
3477 *this = Datagram(dgram);
3478 return true;
3479}
3480
3501inline void DestroyDatagram(DatagramRaw dgram) { NET_DestroyDatagram(dgram); }
3502
3504
3535inline void SimulateDatagramPacketLoss(DatagramSocketRef sock, int percent_loss)
3536{
3537 NET_SimulateDatagramPacketLoss(sock, percent_loss);
3538}
3539
3541{
3542 SDL::SimulateDatagramPacketLoss(get(), percent_loss);
3543}
3544
3571{
3572 NET_DestroyDatagramSocket(sock);
3573}
3574
3576
3627inline int WaitUntilInputAvailable(void** vsockets,
3628 int numsockets,
3629 Sint32 timeout)
3630{
3631 return NET_WaitUntilInputAvailable(vsockets, numsockets, timeout);
3632}
3633
3635
3636} // namespace SDL
3637
3638#endif /* SDL3PP_ENABLE_NET */
3639
3640#endif /* SDL3PP_NET_H_ */
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:44
constexpr RawPointer release() noexcept
Definition SDL3pp_resource.h:57
friend constexpr void swap(ResourceBaseT &lhs, ResourceBaseT &rhs) noexcept
Definition SDL3pp_resource.h:65
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:54
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
Const reference wrapper for a given resource,.
Definition SDL3pp_resource.h:115
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:58
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:199
void Quit()
Clean up all initialized subsystems.
Definition SDL3pp_init.h:329
ResourceRefT< PropertiesBase > PropertiesRef
Reference for Properties.
Definition SDL3pp_properties.h:55
int WaitUntilDrained(Sint32 timeout)
Block until all of a stream socket's pending data is sent.
Definition SDL3pp_net.h:2444
int WaitUntilInputAvailable(void **vsockets, int numsockets, Sint32 timeout)
Block on multiple sockets until at least one has data available.
Definition SDL3pp_net.h:3627
const char * GetAddressString(AddressRef address)
Get a human-readable string from a resolved address.
Definition SDL3pp_net.h:1050
constexpr Status WAITING
Async operation is still in progress, check again later.
Definition SDL3pp_net.h:320
void DestroyDatagramSocket(DatagramSocketRaw sock)
Dispose of a previously-created datagram socket.
Definition SDL3pp_net.h:3570
NET_StreamSocket * StreamSocketRaw
Alias to raw representation for StreamSocket.
Definition SDL3pp_net.h:124
bool SendDatagram(DatagramSocketRef sock, AddressRef address, Uint16 port, const void *buf, int buflen)
Send a new packet over a datagram socket to a remote system.
Definition SDL3pp_net.h:3340
int ReadFromStreamSocket(StreamSocketRef sock, void *buf, int buflen)
Receive bytes that a remote system sent to a stream socket.
Definition SDL3pp_net.h:2497
void DestroyServer(ServerRaw server)
Dispose of a previously-created server.
Definition SDL3pp_net.h:2228
Address GetStreamSocketAddress(StreamSocketRef sock)
Get the remote address of a stream socket.
Definition SDL3pp_net.h:2249
Status WaitUntilResolved(AddressRef address, Sint32 timeout)
Block until an address is resolved.
Definition SDL3pp_net.h:978
ResourceRefT< StreamSocketBase > StreamSocketRef
Reference for StreamSocket.
Definition SDL3pp_net.h:131
int CompareAddresses(AddressRef a, AddressRef b)
Compare two Address objects.
Definition SDL3pp_net.h:1223
ResourceRefT< AddressBase > AddressRef
Reference for Address.
Definition SDL3pp_net.h:115
void Destroy()
Dispose of a datagram packet previously received.
Definition SDL3pp_net.h:3503
constexpr Status SUCCESS
Async operation complete, result was success.
Definition SDL3pp_net.h:322
void SimulateStreamPacketLoss(StreamSocketRef sock, int percent_loss)
Enable simulated stream socket failures.
Definition SDL3pp_net.h:2544
NET_Address * AddressRaw
Alias to raw representation for Address.
Definition SDL3pp_net.h:108
NET_DatagramSocket * DatagramSocketRaw
Alias to raw representation for DatagramSocket.
Definition SDL3pp_net.h:156
Status GetAddressStatus(AddressRef address)
Check if an address is resolved, without blocking.
Definition SDL3pp_net.h:1015
Status GetConnectionStatus()
Check if a stream socket is connected, without blocking.
Definition SDL3pp_net.h:2299
void SimulateDatagramPacketLoss(int percent_loss)
Enable simulated datagram socket failures.
Definition SDL3pp_net.h:3540
bool operator==(const AddressBase &other) const
Compares two addresses for equality.
Definition SDL3pp_net.h:1233
void DestroyStreamSocket(StreamSocketRaw sock)
Dispose of a previously-created stream socket.
Definition SDL3pp_net.h:2581
bool SendDatagram(AddressRef address, Uint16 port, const void *buf, int buflen)
Send a new packet over a datagram socket to a remote system.
Definition SDL3pp_net.h:3349
OwnArray< AddressRef, LocalAddressesArrayDeleter > LocalAddressesArray
Array of addresses returned by GetLocalAddresses.
Definition SDL3pp_net.h:1254
ResourceRefT< ServerBase > ServerRef
Reference for Server.
Definition SDL3pp_net.h:147
bool WriteTo(const void *buf, int buflen)
Send bytes over a stream socket to a remote system.
Definition SDL3pp_net.h:2356
void FreeLocalAddresses(AddressRef *addresses)
Free the results from GetLocalAddresses.
Definition SDL3pp_net.h:1311
const void * GetAddressBytes(AddressRef address, int *num_bytes)
Get the protocol-level bytes of a network address from a resolved address.
Definition SDL3pp_net.h:1101
Status GetConnectionStatus(StreamSocketRef sock)
Check if a stream socket is connected, without blocking.
Definition SDL3pp_net.h:2294
ResourceRefT< DatagramBase > DatagramRef
Reference for Datagram.
Definition SDL3pp_net.h:182
bool WriteToStreamSocket(StreamSocketRef sock, const void *buf, int buflen)
Send bytes over a stream socket to a remote system.
Definition SDL3pp_net.h:2349
Status WaitUntilConnected(StreamSocketRef sock, Sint32 timeout)
Block until a stream socket has connected to a server.
Definition SDL3pp_net.h:1883
Address GetAddress()
Get the remote address of a stream socket.
Definition SDL3pp_net.h:2254
void SimulateAddressResolutionLoss(int percent_loss)
Enable simulated address resolution failures.
Definition SDL3pp_net.h:1203
void DestroyDatagram(DatagramRaw dgram)
Dispose of a datagram packet previously received.
Definition SDL3pp_net.h:3501
const NET_Datagram * DatagramRawConst
Alias to const raw representation for Datagram.
Definition SDL3pp_net.h:175
int GetPendingWrites()
Query bytes still pending transmission on a stream socket.
Definition SDL3pp_net.h:2396
Address RefAddress(AddressRef address)
Add a reference to an Address.
Definition SDL3pp_net.h:1146
int WaitUntilStreamSocketDrained(StreamSocketRef sock, Sint32 timeout)
Block until all of a stream socket's pending data is sent.
Definition SDL3pp_net.h:2439
StreamSocket CreateClient(AddressRef address, Uint16 port, PropertiesRef props)
Begin connecting a socket as a client to a remote server.
Definition SDL3pp_net.h:1822
void AcceptClient(ServerRef server, NET_StreamSocket **client_stream)
Create a stream socket for the next pending client connection.
Definition SDL3pp_net.h:2199
LocalAddressesArray GetLocalAddresses()
Obtain a list of local addresses on the system.
Definition SDL3pp_net.h:1283
void Destroy()
Dispose of a previously-created server.
Definition SDL3pp_net.h:2230
Server CreateServer(Uint16 port, PropertiesRef props)
Create a server, which listens for connections to accept.
Definition SDL3pp_net.h:2143
const void * GetBytes(int *num_bytes)
Get the protocol-level bytes of a network address from a resolved address.
Definition SDL3pp_net.h:1106
NET_Server * ServerRaw
Alias to raw representation for Server.
Definition SDL3pp_net.h:140
bool Receive(DatagramSocketRef sock)
Receive a new packet that a remote system sent to a datagram socket.
Definition SDL3pp_net.h:3473
const char * GetString()
Get a human-readable string from a resolved address.
Definition SDL3pp_net.h:1055
Status WaitUntilResolved(Sint32 timeout)
Block until an address is resolved.
Definition SDL3pp_net.h:983
int Compare(AddressRef b) const
Compare two Address objects.
Definition SDL3pp_net.h:1228
Server CreateServer(AddressRef addr, Uint16 port, PropertiesRef props)
Create a server, which listens for connections to accept.
Definition SDL3pp_net.h:2138
auto operator<=>(const AddressBase &other) const
Compares two addresses.
Definition SDL3pp_net.h:1238
Address ResolveHostname(StringParam host)
Resolve a human-readable hostname.
Definition SDL3pp_net.h:926
void AcceptClient(NET_StreamSocket **client_stream)
Create a stream socket for the next pending client connection.
Definition SDL3pp_net.h:2204
Status WaitUntilConnected(Sint32 timeout)
Block until a stream socket has connected to a server.
Definition SDL3pp_net.h:1888
void UnrefAddress(AddressRaw address)
Drop a reference to an Address.
Definition SDL3pp_net.h:1170
void Destroy()
Dispose of a previously-created stream socket.
Definition SDL3pp_net.h:2586
int GetStreamSocketPendingWrites(StreamSocketRef sock)
Query bytes still pending transmission on a stream socket.
Definition SDL3pp_net.h:2391
void SimulateStreamPacketLoss(int percent_loss)
Enable simulated stream socket failures.
Definition SDL3pp_net.h:2549
ResourceConstRef< DatagramRaw, DatagramRawConst > DatagramConstRef
Safely wrap Datagram for non owning const parameters.
Definition SDL3pp_net.h:185
Status GetStatus()
Check if an address is resolved, without blocking.
Definition SDL3pp_net.h:1020
void Unref()
Drop a reference to an Address.
Definition SDL3pp_net.h:1172
constexpr Status FAILURE
Async operation complete, result was failure.
Definition SDL3pp_net.h:316
ResourceRefT< DatagramSocketBase > DatagramSocketRef
Reference for DatagramSocket.
Definition SDL3pp_net.h:163
void Destroy()
Dispose of a previously-created datagram socket.
Definition SDL3pp_net.h:3575
Datagram ReceiveDatagram()
Receive a new packet that a remote system sent to a datagram socket.
Definition SDL3pp_net.h:3463
int ReadFrom(void *buf, int buflen)
Receive bytes that a remote system sent to a stream socket.
Definition SDL3pp_net.h:2502
void SimulateDatagramPacketLoss(DatagramSocketRef sock, int percent_loss)
Enable simulated datagram socket failures.
Definition SDL3pp_net.h:3535
DatagramSocket CreateDatagramSocket(AddressRef addr, Uint16 port, PropertiesRef props)
Create and bind a new datagram socket.
Definition SDL3pp_net.h:3231
StreamSocket CreateClient(Uint16 port, PropertiesRef props)
Begin connecting a socket as a client to a remote server.
Definition SDL3pp_net.h:1829
NET_Datagram * DatagramRaw
Alias to raw representation for Datagram.
Definition SDL3pp_net.h:172
bool ReceiveDatagram(DatagramSocketRef sock, Datagram &dgram)
Receive a new packet that a remote system sent to a datagram socket.
Definition SDL3pp_net.h:3402
NET_Status Status
A tri-state for asynchronous operations.
Definition SDL3pp_net.h:314
DatagramSocket CreateDatagramSocket(Uint16 port, PropertiesRef props)
Create and bind a new datagram socket.
Definition SDL3pp_net.h:3238
::Sint32 Sint32
A signed 32-bit integer type.
Definition SDL3pp_stdinc.h:283
::Uint16 Uint16
An unsigned 16-bit integer type.
Definition SDL3pp_stdinc.h:270
Main include header for the SDL3pp library.
Base class to Address.
Definition SDL3pp_net.h:331
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
Opaque representation of a computer-readable network address.
Definition SDL3pp_net.h:756
constexpr Address & operator=(Address &&other) noexcept
Assignment operator.
Definition SDL3pp_net.h:873
static Address borrow(AddressRaw resource)
Safely borrows the from AddressRaw.
Definition SDL3pp_net.h:860
~Address()
Destructor.
Definition SDL3pp_net.h:870
constexpr Address(AddressRaw resource) noexcept
Constructs from raw Address.
Definition SDL3pp_net.h:766
constexpr Address(Address &&other) noexcept
Move constructor.
Definition SDL3pp_net.h:772
Address & operator=(const Address &other)
Assignment operator.
Definition SDL3pp_net.h:880
Base class to Datagram.
Definition SDL3pp_net.h:2982
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
Base class to DatagramSocket.
Definition SDL3pp_net.h:2594
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
An object that represents a datagram connection to another system.
Definition SDL3pp_net.h:2857
constexpr DatagramSocket(DatagramSocket &&other) noexcept
Move constructor.
Definition SDL3pp_net.h:2873
constexpr DatagramSocket & operator=(DatagramSocket &&other) noexcept
Assignment operator.
Definition SDL3pp_net.h:2969
~DatagramSocket()
Destructor.
Definition SDL3pp_net.h:2966
constexpr DatagramSocket(DatagramSocketRaw resource) noexcept
Constructs from raw DatagramSocket.
Definition SDL3pp_net.h:2867
The data provided for new incoming packets from ReceiveDatagram().
Definition SDL3pp_net.h:3067
constexpr Datagram & operator=(Datagram &&other) noexcept
Assignment operator.
Definition SDL3pp_net.h:3139
constexpr Datagram(Datagram &&other) noexcept
Move constructor.
Definition SDL3pp_net.h:3083
~Datagram()
Destructor.
Definition SDL3pp_net.h:3136
constexpr Datagram(DatagramRaw resource) noexcept
Constructs from raw Datagram.
Definition SDL3pp_net.h:3077
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:93
Base class to Server.
Definition SDL3pp_net.h:1899
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
The receiving end of a stream connection.
Definition SDL3pp_net.h:1980
constexpr Server & operator=(Server &&other) noexcept
Assignment operator.
Definition SDL3pp_net.h:2069
constexpr Server(Server &&other) noexcept
Move constructor.
Definition SDL3pp_net.h:1996
constexpr Server(ServerRaw resource) noexcept
Constructs from raw Server.
Definition SDL3pp_net.h:1990
~Server()
Destructor.
Definition SDL3pp_net.h:2066
Base class to StreamSocket.
Definition SDL3pp_net.h:1327
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
An object that represents a streaming connection to another system.
Definition SDL3pp_net.h:1678
~StreamSocket()
Destructor.
Definition SDL3pp_net.h:1758
constexpr StreamSocket(StreamSocketRaw resource) noexcept
Constructs from raw StreamSocket.
Definition SDL3pp_net.h:1688
constexpr StreamSocket(StreamSocket &&other) noexcept
Move constructor.
Definition SDL3pp_net.h:1694
constexpr StreamSocket & operator=(StreamSocket &&other) noexcept
Assignment operator.
Definition SDL3pp_net.h:1761