@@ -41,20 +41,46 @@ extern "C" {
41
41
#endif
42
42
43
43
/**
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.
45
49
*/
46
50
#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
+ */
47
59
#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
+ */
48
68
#define SDL_NET_MICRO_VERSION 0
49
69
50
70
/**
51
71
* 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
52
76
*/
53
77
#define SDL_NET_VERSION \
54
78
SDL_VERSIONNUM(SDL_NET_MAJOR_VERSION, SDL_NET_MINOR_VERSION, SDL_NET_MICRO_VERSION)
55
79
56
80
/**
57
81
* 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.
58
84
*/
59
85
#define SDL_NET_VERSION_ATLEAST (X , Y , Z ) \
60
86
((SDL_NET_MAJOR_VERSION >= X) && \
@@ -118,7 +144,26 @@ extern SDL_DECLSPEC void SDLCALL NET_Quit(void);
118
144
119
145
/* hostname resolution API... */
120
146
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 ;
122
167
123
168
/**
124
169
* Resolve a human-readable hostname.
@@ -426,6 +471,23 @@ extern SDL_DECLSPEC void SDLCALL NET_FreeLocalAddresses(NET_Address **addresses)
426
471
427
472
/* Streaming (TCP) API... */
428
473
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
+ */
429
491
typedef struct NET_StreamSocket NET_StreamSocket ; /**< a TCP socket. Reliable transmission, with the usual pros/cons. */
430
492
431
493
/**
@@ -526,6 +588,20 @@ extern SDL_DECLSPEC NET_StreamSocket * SDLCALL NET_CreateClient(NET_Address *add
526
588
*/
527
589
extern SDL_DECLSPEC int SDLCALL NET_WaitUntilConnected (NET_StreamSocket * sock , Sint32 timeout );
528
590
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
+ */
529
605
typedef struct NET_Server NET_Server ; /**< a listen socket, internally. Binds to a port, accepts connections. */
530
606
531
607
/**
@@ -938,14 +1014,45 @@ extern SDL_DECLSPEC void SDLCALL NET_DestroyStreamSocket(NET_StreamSocket *sock)
938
1014
939
1015
/* Datagram (UDP) API... */
940
1016
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
+ */
941
1040
typedef struct NET_DatagramSocket NET_DatagramSocket ; /**< a UDP socket. Unreliable, packet-based transmission, with the usual pros/cons */
942
1041
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
+ */
943
1050
typedef struct NET_Datagram
944
1051
{
945
1052
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`. */
949
1056
} NET_Datagram ;
950
1057
951
1058
/**
@@ -1060,7 +1167,6 @@ extern SDL_DECLSPEC NET_DatagramSocket * SDLCALL NET_CreateDatagramSocket(NET_Ad
1060
1167
*/
1061
1168
extern SDL_DECLSPEC bool SDLCALL NET_SendDatagram (NET_DatagramSocket * sock , NET_Address * address , Uint16 port , const void * buf , int buflen );
1062
1169
1063
-
1064
1170
/**
1065
1171
* Receive a new packet that a remote system sent to a datagram socket.
1066
1172
*
@@ -1070,7 +1176,7 @@ extern SDL_DECLSPEC bool SDLCALL NET_SendDatagram(NET_DatagramSocket *sock, NET_
1070
1176
* This call never blocks; if no new data isn't available at the time of the
1071
1177
* call, it returns true immediately. The caller can try again later.
1072
1178
*
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
1074
1180
* packets are available, so you should check for a successful return and a
1075
1181
* non-NULL value in `*dgram` to decide if a new packet is available.
1076
1182
*
0 commit comments