NET_SIMULATESTREAMPACKETLOSS(3)
π NET_SimulateStreamPacketLoss(3) π
okay bestie, welcome to the SDL_net3 FUNCTIONS section of the manual, and today's main character is NET_SimulateStreamPacketLoss(3) β¨ she's a little chaotic, she breaks things on purpose, and honestly? iconic behavior π«Ά
β¨ NAME β¨
NET_SimulateStreamPacketLoss β turn on pretend stream socket failures π
πΈ SYNOPSIS πΈ
#include <SDL3_net/SDL_net.h>
void NET_SimulateStreamPacketLoss(NET_StreamSocket *sock, int percent_loss);
π¦ DESCRIPTION π¦
okay so here's the tea β. when you're testing a networked app on your dev machine β which is probably sitting on a wired connection to a fast, reliable network service, like, spoiled β you are NOT gonna catch the bugs that only show up when networks intermittently fail in the real world. you know, when the wifi is flakey π and firewalls get all up in your business.
so this function lets you tell the library to pretend that some percentage of stream socket data transmission will fail. no cap.
and since stream sockets are reliable, "failure" here means the library pretends packets are getting lost on the network, which makes the stream retransmit to deal with it. to simulate all that, the library introduces some amount of delay before it sends or receives data on the socket. the higher the percentage, the more delay gets introduced before bytes make their way to their final destination π’. the library may also decide to drop connections at random, to simulate disasterous network conditions π.
setting this to zero (the default) disables the simulation entirely. setting it to 100 means everything fails unconditionally and no further data will get through β and perhaps your sockets eventually fail π. at what percent the system merely borders on unusable? that's left as an exercise to the app developer, bestie, you're on your own for that one π.
fr fr, this is intended for debugging purposes, to simulate real-world conditions that are various degrees of terrible. you probably should not call this in production code, where you'll likely see real failures anyhow π .
π FUNCTION PARAMETERS π
sockβ the socket to set a failure rate on π§¦percent_lossβ a number between0and100. higher means more failures. zero to disable β¨
π THREAD SAFETY π
it is safe to call this function from any thread. go off, multithreaded queen π
π AVAILABILITY π
this function is available since SDL_net 3.0.0 β
and that's the whole page, bestie!! this lil slice of wisdom came to you straight from SDL_net 3.2.0 β NET_Simulate...amPacketLoss(3) β mwah, go break your sockets on purpose, you deserve it π
π
π¦ where this page comes from
- fedora 43: SDL3_net-devel 3.2.0-2.fc43 Β· Zlib
- fedora 43: SDL3_net-devel 3.2.0-2.fc43 Β· Zlib
- fedora 44: SDL3_net-devel 3.2.0-2.fc44 Β· Zlib
- fedora 44: SDL3_net-devel 3.2.0-2.fc44 Β· Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms