Closed icculus closed 11 months ago
+1 for retire
Yeah, I think retiring the library at this point is the right call. I don't mind if someone wants to come along and pick it up, but I don't think there's enough value from a simple sockets wrapper to have a whole library based around it at this point.
Just for the intellectual exercise, this is what I would probably make a revised API look like. It's a little easier to use than BSD Sockets but more or less the same level of usefulness, never blocks (except a few WaitFor* functions), and does most of the heavy lifting of memory management.
Ok, as a weekend project, I knocked out something sort of like what I proposed above, and stuck it in a pull request.
The question is, I think, "does SDL_net provide value in a world where everything is BSD sockets anyway?" and having done the intellectual exercise here, the answer is--to my surprise--actually yes.
Where I landed was a simple API that is non-blocking by default, since this is what game developers need, and has a few optional functions to wait for sockets to connect/get more incoming data/write their pending buffers, since we can put these to sleep at the OS level until events occur, instead polling+SDL_Delay in a loop, for the times when that might be appropriate.
Data to be sent queues internally when necessary, so if you want to write more than the socket can eat at the moment, we'll take care of it for you and let it drain through over time.
I've also built in ways to say "pretend this is failing a little (or a lot)" which will throw away UDP packets as if the network lost them, stall stream writes and DNS lookups, maybe drop connections, etc, so you can see how your game fares when it isn't running on your wired connection to a gigabit fiber line, and instead smacks into the real world of flakey wifi connections, etc.
Backwards compat with SDL2_net is not at all on the table. That being said, I assume SDL2_net will compile against SDL3 (or can be made to work relatively quickly) because there isn't much about it that requires SDL at all. But if we're doing this, I'm leaving it in the dust, and not building an SDL2_net-compat library.
This is at the "it works on my Linux machine" state. I have a few Windows #ifdefs
filled in, but we would need to compile and test this elsewhere.
If we want to get more ambitious in the future, a zero-dependency library that offers NAT punching, encryption, WebSockets and WebRTC on top of these primitives would make this an absolutely must-have piece of tech, but that would be a massive undertaking and I'm mostly concerned with offering a humble library that's a modern improvement over SDL2_net at the moment.
To be clear, this isn't something I plan to work on any time soon, but it would be nice if we had an idea of what to aim towards if we're finally breaking API/ABI for SDL_net.
SDL_net is not my favorite thing in the world, but I'm willing to be optimistic and say with the correct changes, I could certainly learn to love it.
Here are some wishlist items.
127.0.0.1
or2259:1700:2760:bab8:2a20:562b:e796:143d
).90% of the reason SDL_net exists at all was to manage differences between BSD Sockets, Winsock, and a few other wierdo platforms, but BSD Sockets won out, modulo a few WinSock differences that can be papered over with a handful of
#define
s, so that need doesn't really exist any more.So the only reason for an SDL3_net to exist, if we're going to do an SDL3_net, is to make it easier to do these common socket things from a programming point of view, or add features that are less trivial to slot into an app, like encryption or NAT hole punching. There really isn't anything that integrates with SDL3 that needs to be updated from an SDL2 interface, etc.
All I'm talking about here is how to streamline what's there to be a better API, but the question still lingers: is this worth doing? Or should we retire this with SDL2 and tell people to use BSD Sockets?