NET_SIMULATEDATAGRAMPACKETLOSS(3)

πŸ“¦
version 3.2.0 Β· 2 versions
, in fedora 43, fedora 44

πŸ’– NET_SimulateDatagramPacketLoss πŸ’–

okay bestie, welcome to the SDL_net3 manual, page for NET_SimulateDatagramPacketLoss(3). yes the title got chopped to NET_Simulate...amPacketLoss(3) in your terminal's header bar, that's just how man pages do, don't worry about it 🫢


✨ NAME ✨

NET_SimulateDatagramPacketLoss β€” Enable simulated datagram socket failures.

like. it makes your socket pretend to be bad at its job. on purpose. for science. πŸ’…


✨ SYNOPSIS ✨

#include <SDL3_net/SDL_net.h>

void NET_SimulateDatagramPacketLoss(NET_DatagramSocket *sock, int percent_loss);

✨ DESCRIPTION ✨

okay so here's the tea, and it's actually kind of a big deal 🍡

when you're testing a networked app on your own dev machine, that machine probably has a wired connection to a fast, reliable network service. and that's lovely for you, truly, but it means you will NOT catch the bugs that only show up when networks intermittently fail out in the real world β€” when the wifi is flakey and firewalls get in the way. your perfect little localhost setup is not giving real-world conditions, bestie, it's giving fantasy ✨

so this function lets you tell the library to pretend that some percentage of datagram socket data transmission will fail.

the library will randomly lose packets β€” both incoming and outgoing β€” at an average matching percent_loss. setting it to zero (which is the default, fyi) disables the simulation entirely. setting it to 100 means everything fails unconditionally and no further data will get through. as for at what percent the system merely borders on unusable… that is left as an exercise to the app developer 😭 good luck with that one.

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 you want to set a failure rate on. the victim, basically.
  • percent_loss β€” a number between 0 and 100. higher means more failures. zero to disable.

✨ THREAD SAFETY ✨

it is safe to call this function from any thread. yes queen, go wild, thread it up 🧚


✨ AVAILABILITY ✨

this function is available since SDL_net 3.0.0. so if you're on something older… no it isn't πŸ™ˆ


reminder bestie: 0 = off (default), 100 = total blackout, in between = chaos dial. don't ship it, just vibe with it while debugging. πŸŽ€

and that's the page!! this was SDL_net 3.2.0 of the SDL_net manual, page NET_Simulate...amPacketLoss(3) (yes the header truncated it again, iconic behavior honestly). mwah, go break your own network on purpose πŸ’œπŸ¦‹

πŸ“¦ where this page comes from