Skip to content

Commit 6aba744

Browse files
committed
include: Fill in some documentation gaps.
This should be most (or all?) of the missing docs. Fixes #132.
1 parent 7f2789b commit 6aba744

File tree

1 file changed

+113
-7
lines changed

1 file changed

+113
-7
lines changed

include/SDL3_net/SDL_net.h

Lines changed: 113 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,46 @@ extern "C" {
4141
#endif
4242

4343
/**
44-
* Printable format: "%d.%d.%d", MAJOR, MINOR, MICRO
44+
* The current major version of SDL_net headers.
45+
*
46+
* If this were SDL_net version 3.2.1, this value would be 3.
47+
*
48+
* \since This macro is available since SDL_net 3.0.0.
4549
*/
4650
#define SDL_NET_MAJOR_VERSION 3
51+
52+
/**
53+
* The current minor version of the SDL_net headers.
54+
*
55+
* If this were SDL_net version 3.2.1, this value would be 2.
56+
*
57+
* \since This macro is available since SDL_net 3.0.0.
58+
*/
4759
#define SDL_NET_MINOR_VERSION 0
60+
61+
/**
62+
* The current micro (or patchlevel) version of the SDL_net headers.
63+
*
64+
* If this were SDL_net version 3.2.1, this value would be 1.
65+
*
66+
* \since This macro is available since SDL_net 3.0.0.
67+
*/
4868
#define SDL_NET_MICRO_VERSION 0
4969

5070
/**
5171
* This is the version number macro for the current SDL_net version.
72+
*
73+
* \since This macro is available since SDL_net 3.0.0.
74+
*
75+
* \sa NET_Version
5276
*/
5377
#define SDL_NET_VERSION \
5478
SDL_VERSIONNUM(SDL_NET_MAJOR_VERSION, SDL_NET_MINOR_VERSION, SDL_NET_MICRO_VERSION)
5579

5680
/**
5781
* This macro will evaluate to true if compiled with SDL_net at least X.Y.Z.
82+
*
83+
* \since This macro is available since SDL_net 3.0.0.
5884
*/
5985
#define SDL_NET_VERSION_ATLEAST(X, Y, Z) \
6086
((SDL_NET_MAJOR_VERSION >= X) && \
@@ -118,7 +144,26 @@ extern SDL_DECLSPEC void SDLCALL NET_Quit(void);
118144

119145
/* hostname resolution API... */
120146

121-
typedef struct NET_Address NET_Address; /**< Opaque struct that deals with computer-readable addresses. */
147+
/**
148+
* Opaque representation of a computer-readable network address.
149+
*
150+
* This is an opaque datatype, to be treated by the app as a handle.
151+
*
152+
* SDL_net uses these to identify other servers; you use them to connect to a
153+
* remote machine, and you use them to find out who connected to you. They are
154+
* also used to decide what network interface to use when creating a server.
155+
*
156+
* These are intended to be protocol-independent; a given address might be for
157+
* IPv4, IPv6, or something more esoteric. SDL_Net attempts to hide the
158+
* differences.
159+
*
160+
* \since This datatype is available since SDL_Net 3.0.0.
161+
*
162+
* \sa NET_ResolveHostname
163+
* \sa NET_GetLocalAddresses
164+
* \sa NET_CompareAddresses
165+
*/
166+
typedef struct NET_Address NET_Address;
122167

123168
/**
124169
* Resolve a human-readable hostname.
@@ -426,6 +471,23 @@ extern SDL_DECLSPEC void SDLCALL NET_FreeLocalAddresses(NET_Address **addresses)
426471

427472
/* Streaming (TCP) API... */
428473

474+
/**
475+
* An object that represents a streaming connection to another system.
476+
*
477+
* This is meant to be a reliable, stream-oriented connection, such as TCP.
478+
*
479+
* Each NET_StreamSocket represents a single connection between systems.
480+
* Usually, a client app will have one connection to a server app on a
481+
* different computer, and the server app might have many connections from
482+
* different clients. Each of these connections communicate over a separate
483+
* stream socket.
484+
*
485+
* \since This datatype is available since SDL_Net 3.0.0.
486+
*
487+
* \sa NET_CreateClient
488+
* \sa NET_WriteToStreamSocket
489+
* \sa NET_ReadFromStreamSocket
490+
*/
429491
typedef struct NET_StreamSocket NET_StreamSocket; /**< a TCP socket. Reliable transmission, with the usual pros/cons. */
430492

431493
/**
@@ -526,6 +588,20 @@ extern SDL_DECLSPEC NET_StreamSocket * SDLCALL NET_CreateClient(NET_Address *add
526588
*/
527589
extern SDL_DECLSPEC int SDLCALL NET_WaitUntilConnected(NET_StreamSocket *sock, Sint32 timeout);
528590

591+
/**
592+
* The receiving end of a stream connection.
593+
*
594+
* This is an opaque datatype, to be treated by the app as a handle.
595+
*
596+
* Internally, this is what BSD sockets refers to as a "listen socket". Clients
597+
* attempt to connect to a server, and if the server accepts the connection,
598+
* will provide the app with a stream socket to send and receive data over that
599+
* connection.
600+
*
601+
* \since This datatype is available since SDL_Net 3.0.0.
602+
*
603+
* \sa NET_CreateServer
604+
*/
529605
typedef struct NET_Server NET_Server; /**< a listen socket, internally. Binds to a port, accepts connections. */
530606

531607
/**
@@ -938,14 +1014,45 @@ extern SDL_DECLSPEC void SDLCALL NET_DestroyStreamSocket(NET_StreamSocket *sock)
9381014

9391015
/* Datagram (UDP) API... */
9401016

1017+
/**
1018+
* An object that represents a datagram connection to another system.
1019+
*
1020+
* This is meant to be an unreliable, packet-oriented connection, such as UDP.
1021+
*
1022+
* Datagram sockets follow different rules than stream sockets. They are not a
1023+
* reliable stream of bytes but rather packets, they are not limited to
1024+
* talking to a single other remote system, they do not maintain a single
1025+
* "connection" that can be dropped, and they are more nimble about network
1026+
* failures at the expense of being more complex to use. What makes sense for
1027+
* your app depends entirely on what your app is trying to accomplish.
1028+
*
1029+
* Generally the idea of a datagram socket is that you send data one chunk
1030+
* ("packet") at a time to any address you want, and it arrives whenever it
1031+
* gets there, even if later packets get there first, and maybe it doesn't get
1032+
* there at all, and you don't know when anything of this happens by default.
1033+
*
1034+
* \since This datatype is available since SDL_Net 3.0.0.
1035+
*
1036+
* \sa NET_CreateDatagramSocket
1037+
* \sa NET_SendDatagram
1038+
* \sa NET_ReceiveDatagram
1039+
*/
9411040
typedef struct NET_DatagramSocket NET_DatagramSocket; /**< a UDP socket. Unreliable, packet-based transmission, with the usual pros/cons */
9421041

1042+
/**
1043+
* The data provided for new incoming packets from NET_ReceiveDatagram().
1044+
*
1045+
* \since This datatype is available since SDL_Net 3.0.0.
1046+
*
1047+
* \sa NET_ReceiveDatagram
1048+
* \sa NET_DestroyDatagram
1049+
*/
9431050
typedef struct NET_Datagram
9441051
{
9451052
NET_Address *addr; /**< this is unref'd by NET_DestroyDatagram. You only need to ref it if you want to keep it. */
946-
Uint16 port; /**< these do not have to come from the same port the receiver is bound to. */
947-
Uint8 *buf;
948-
int buflen;
1053+
Uint16 port; /**< these do not have to come from the same port the receiver is bound to. These are in host byte order, don't byteswap them! */
1054+
Uint8 *buf; /**< the payload of this datagram. */
1055+
int buflen; /**< the number of bytes available at `buf`. */
9491056
} NET_Datagram;
9501057

9511058
/**
@@ -1060,7 +1167,6 @@ extern SDL_DECLSPEC NET_DatagramSocket * SDLCALL NET_CreateDatagramSocket(NET_Ad
10601167
*/
10611168
extern SDL_DECLSPEC bool SDLCALL NET_SendDatagram(NET_DatagramSocket *sock, NET_Address *address, Uint16 port, const void *buf, int buflen);
10621169

1063-
10641170
/**
10651171
* Receive a new packet that a remote system sent to a datagram socket.
10661172
*
@@ -1070,7 +1176,7 @@ extern SDL_DECLSPEC bool SDLCALL NET_SendDatagram(NET_DatagramSocket *sock, NET_
10701176
* This call never blocks; if no new data isn't available at the time of the
10711177
* call, it returns true immediately. The caller can try again later.
10721178
*
1073-
* On a successful call to this function, it returns zero, even if no new
1179+
* On a successful call to this function, it returns true, even if no new
10741180
* packets are available, so you should check for a successful return and a
10751181
* non-NULL value in `*dgram` to decide if a new packet is available.
10761182
*

0 commit comments

Comments
 (0)