-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SDL3_net redesign #79
Conversation
Added a test program that does group voice chat over UDP. 374 lines of C code covers both client and server, so this is pretty nice, for just using SDL3_net and SDL3. This let me fix a few mistakes and bugs in the proposed SDL3_net library. It was also nice to flex the new SDL3 audio system; each person speaking just gets their own audio stream bound to the output device. You just queue audio on them when it comes in, and it mixes whatever's available. :) |
This looks great! |
I fixed the mingw build errors, expanded the cmake script a bit, and added minimum ci. |
I want it all. :) It's pulled into this PR, thanks! |
Should we move this into src/ and include/SDL3/ to match other libraries? Right now this all fits in one source file cleanly, but if I lose my mind and implement TLS 1.3 from scratch, I might use more source files. :) |
Getting this error with gcc-4.4 or gcc-4.9: $ gcc49 -I/home/sezero/SDL/include -O3 -Wall -W -std=gnu99 -c SDL_net.c
SDL_net.c: In function 'SDLNet_Init':
SDL_net.c:268:5: error: a label can only be part of a statement and a declaration is not a statement
char *origerrstr = SDL_strdup(SDL_GetError());
^ Similar with clang-3.4:
Moving origerrstr to top fixes it for me: diff --git a/SDL_net.c b/SDL_net.c
index 488073f..cd2c510 100644
--- a/SDL_net.c
+++ b/SDL_net.c
@@ -228,6 +228,8 @@ static void DestroyAddress(SDLNet_Address *addr)
int SDLNet_Init(void)
{
+ char *origerrstr;
+
#ifdef __WINDOWS__
WSADATA data;
if (WSAStartup(MAKEWORD(1, 1), &data) != 0) {
@@ -265,7 +267,7 @@ int SDLNet_Init(void)
return 0; // good to go.
failed:
- char *origerrstr = SDL_strdup(SDL_GetError());
+ origerrstr = SDL_strdup(SDL_GetError());
SDLNet_Quit();
|
Probably. I did the minimum to get it building on mingw and ci. |
I pulled your fix in, thanks! |
I think supporting blocking reads (with a timeout) might make sense, especially if you're doing networking (or at least reading) in a separate thread (=> after a failed read you don't have much to do, so you'd either busy-loop on Kinda related, probably |
We probably should add a poll()-style interface, to check multiple sockets at once (but they can still remain non-blocking). DNS resolution waits on a condition variable internal, so we can definitely add a timeout on that. |
Yeah, explicit poll might be even better, otherwise it'd probably use poll under the hood (but with only one socket at a time) anyway.. Though for convenience you could still offer |
BTW, just noticed, |
I removed SDLNet_WaitForServerIncoming completely, there's now SDLNet_WaitUntilInputAvailable which can take an array of sockets and sleep the thread until any of them have new input (which in the case of a listen socket, means there's a new connection to accept). This is implemented with poll(). If there's pending data to send, it'll wake up when we can write more and then go right back to poll(). All the Wait functions now accept a timeout (0 to not block at all, -1 for infinite timeout, milliseconds otherwise), and are named better, I think. |
(Also, this compiles but wasn't tested yet because it's 1:30am. I'll do it in the morning.) |
By the way, you may wanna look at https://gist.github.com/DanielGibson/bf6bd299c50c1ac1aff4cd063472cbe4 and maybe steal some of its code (it's public domain, though of course I wouldn't mind credit if you end up using bigger parts of it), it documents several differences between Winsock and BSD sockets and has a crossplatform |
I ended up wrapping error string management in a few functions in 786aaa7 ... in the Windows case, it eventually boils down to a FormatMessage() win32 API call that generates a string in the end-user's language. The WinSock docs say you can FormatMessage any error code that you would get from WSAGetLastError, which covers both the things you'd want from strerror(errno) and gai_strerror(). |
Some of this will come back. But for now: clean slate!
…ocking. This way the error string is set correctly.
This is generally useful for "are these two addresses the same thing?" but also suitable for using as a compare callback for SDL_qsort.
These might come in with IPPROTO_TCP and then get used for a UDP packet, so it gets upset when it sees a socktype of SOCK_DGRAM with TCP. It can figure it out for now, at least for IPv4 and IPv6.
Please don't use this for anything serious. :)
It only causes the program to fail to start, as it's the only DNS lookup, so it becomes a pain to get the example running at all at high packet-loss rates, when what you _really_ want to see here is what it sounds like when packets go missing.
7e51776
to
a3e8f14
Compare
Apparently some common routers will drop packets that are larger than 1278 bytes...gave myself a little wiggle room here.
Compiler warnings are fixed, and voipchat picks a more router-friendly maximum packet size now. What else is still pending? |
…ot `char`. Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>
Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>
We should do something about the following? Appears in SDL_image CI logs too (probably in others' as well.)
|
I assumed this is the wikiheaders script trying to figure out the current revision (but I haven't looked into why it fails). |
I've fixed these warnings in the Perl script of SDL, but have not replicated it to all satellite libraries. |
Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>
Ok, |
The question should be: "is the world ready for this library?" 😉 There is something wrong with the man pages. Nothing gets installed. edit: Never mind I did not know the perl error was fatal on Windows. |
And also, as a game developer, why do I want to use this library? |
One small step for SDL_net, but just wait until I lose my mind and implement all the bonkers bonus features, later. :) |
As long as the bonkers bonus features include support for encrypted websockets... ;) |
All SDL3 satellite libraries now have an updated perl script. |
I fixed and verified the VisualC project builds binaries.
Also, is this expected?
|
We'll mess with the last few Windows details (and encrypted WebSockets, lol) later. For now, I'm merging! |
This is a complete redesign and rewrite of SDL_net for a 3.0 release. It has different goals and functionality than SDL2_net, of which I have retained no pieces.
See discussion in #77 for details.
Some things that are still pending before we can merge this: