@@ -173,11 +173,39 @@ extern "C" {
173173 *
174174 * \returns SDL_net version.
175175 *
176+ * \threadsafety It is safe to call this function from any thread.
177+ *
176178 * \since This function is available since SDL_net 3.0.0.
177179 */
178180extern SDL_DECLSPEC int SDLCALL NET_Version (void );
179181
180182
183+ /**
184+ * A tri-state for asynchronous operations.
185+ *
186+ * Lots of tasks in SDL_net are asynchronous, as they can't complete until
187+ * data passes over a network at some murky future point in time.
188+ *
189+ * This includes sending data over a stream socket, resolving a hostname,
190+ * connecting to a remote system, and other tasks.
191+ *
192+ * The library never blocks on tasks that take time to complete, with the
193+ * exception of functions named "Wait", which are intended to do nothing but
194+ * block until a task completes. Functions that are attempting to do something
195+ * that might block, or are querying the status of a task in-progress, will
196+ * return a NET_Status, so an app can see if a task completed, and its final
197+ * outcome.
198+ *
199+ * \since This enum is available since SDL_net 3.0.0.
200+ */
201+ typedef enum NET_Status
202+ {
203+ NET_FAILURE = -1 , /**< Async operation complete, result was failure. */
204+ NET_WAITING = 0 , /**< Async operation is still in progress, check again later. */
205+ NET_SUCCESS = 1 /**< Async operation complete, result was success. */
206+ } NET_Status ;
207+
208+
181209/* init/quit functions... */
182210
183211/**
@@ -313,9 +341,10 @@ extern SDL_DECLSPEC NET_Address * SDLCALL NET_ResolveHostname(const char *host);
313341 * \param address The NET_Address object to wait on.
314342 * \param timeout Number of milliseconds to wait for resolution to complete.
315343 * -1 to wait indefinitely, 0 to check once without waiting.
316- * \returns 1 if successfully resolved, -1 if resolution failed, 0 if still
317- * resolving (this function timed out without resolution); if -1,
318- * call SDL_GetError() for details.
344+ * \returns NET_SUCCESS if successfully resolved, NET_FAILURE if resolution
345+ * failed, NET_WAITING if still resolving (this function timed out
346+ * without resolution); if NET_FAILURE, call SDL_GetError() for
347+ * details.
319348 *
320349 * \threadsafety It is safe to call this function from any thread, and several
321350 * threads can block on the same address simultaneously.
@@ -324,7 +353,7 @@ extern SDL_DECLSPEC NET_Address * SDLCALL NET_ResolveHostname(const char *host);
324353 *
325354 * \sa NET_GetAddressStatus
326355 */
327- extern SDL_DECLSPEC int SDLCALL NET_WaitUntilResolved (NET_Address * address , Sint32 timeout );
356+ extern SDL_DECLSPEC NET_Status SDLCALL NET_WaitUntilResolved (NET_Address * address , Sint32 timeout );
328357
329358/**
330359 * Check if an address is resolved, without blocking.
@@ -344,16 +373,18 @@ extern SDL_DECLSPEC int SDLCALL NET_WaitUntilResolved(NET_Address *address, Sint
344373 * host represented by the address.
345374 *
346375 * \param address The NET_Address to query.
347- * \returns 1 if successfully resolved, -1 if resolution failed, 0 if still
348- * resolving; if -1, call SDL_GetError() for details.
376+ * \returns NET_SUCCESS if successfully resolved, NET_FAILURE if resolution
377+ * failed, NET_WAITING if still resolving (this function timed out
378+ * without resolution); if NET_FAILURE, call SDL_GetError() for
379+ * details.
349380 *
350381 * \threadsafety It is safe to call this function from any thread.
351382 *
352383 * \since This function is available since SDL_net 3.0.0.
353384 *
354385 * \sa NET_WaitUntilResolved
355386 */
356- extern SDL_DECLSPEC int SDLCALL NET_GetAddressStatus (NET_Address * address );
387+ extern SDL_DECLSPEC NET_Status SDLCALL NET_GetAddressStatus (NET_Address * address );
357388
358389/**
359390 * Get a human-readable string from a resolved address.
@@ -486,7 +517,8 @@ extern SDL_DECLSPEC void SDLCALL NET_SimulateAddressResolutionLoss(int percent_l
486517 *
487518 * \param a first address to compare.
488519 * \param b second address to compare.
489- * \returns -1 if `a` is "less than" `b`, 1 if "greater than", 0 if equal.
520+ * \returns a value less than zero if `a` is "less than" `b`, a value greater than zero
521+ * if "greater than", zero if equal.
490522 *
491523 * \threadsafety It is safe to call this function from any thread.
492524 *
@@ -653,9 +685,10 @@ extern SDL_DECLSPEC NET_StreamSocket * SDLCALL NET_CreateClient(NET_Address *add
653685 * \param sock The NET_StreamSocket object to wait on.
654686 * \param timeout Number of milliseconds to wait for resolution to complete.
655687 * -1 to wait indefinitely, 0 to check once without waiting.
656- * \returns 1 if successfully connected, -1 if connection failed, 0 if still
657- * connecting (this function timed out without resolution); if -1,
658- * call SDL_GetError() for details.
688+ * \returns NET_SUCCESS if successfully connected, NET_FAILURE if connection
689+ * failed, NET_WAITING if still connecting (this function timed out
690+ * without resolution); if NET_FAILURE, call SDL_GetError() for
691+ * details.
659692 *
660693 * \threadsafety You should not operate on the same socket from multiple
661694 * threads at the same time without supplying a serialization
@@ -666,7 +699,7 @@ extern SDL_DECLSPEC NET_StreamSocket * SDLCALL NET_CreateClient(NET_Address *add
666699 *
667700 * \sa NET_GetConnectionStatus
668701 */
669- extern SDL_DECLSPEC int SDLCALL NET_WaitUntilConnected (NET_StreamSocket * sock , Sint32 timeout );
702+ extern SDL_DECLSPEC NET_Status SDLCALL NET_WaitUntilConnected (NET_StreamSocket * sock , Sint32 timeout );
670703
671704/**
672705 * The receiving end of a stream connection.
@@ -838,8 +871,9 @@ extern SDL_DECLSPEC NET_Address * SDLCALL NET_GetStreamSocketAddress(NET_StreamS
838871 * connection dropped later when your reads and writes report failures.
839872 *
840873 * \param sock the stream socket to query.
841- * \returns 1 if successfully connected, -1 if connection failed, 0 if still
842- * connecting; if -1, call SDL_GetError() for details.
874+ * \returns NET_SUCCESS if successfully connected, NET_FAILURE if connection
875+ * failed, NET_WAITING if still connecting; if NET_FAILURE, call
876+ * SDL_GetError() for details.
843877 *
844878 * \threadsafety You should not operate on the same socket from multiple
845879 * threads at the same time without supplying a serialization
@@ -850,7 +884,7 @@ extern SDL_DECLSPEC NET_Address * SDLCALL NET_GetStreamSocketAddress(NET_StreamS
850884 *
851885 * \sa NET_WaitUntilConnected
852886 */
853- extern SDL_DECLSPEC int SDLCALL NET_GetConnectionStatus (NET_StreamSocket * sock );
887+ extern SDL_DECLSPEC NET_Status SDLCALL NET_GetConnectionStatus (NET_StreamSocket * sock );
854888
855889/**
856890 * Send bytes over a stream socket to a remote system.
0 commit comments