NET_SIMULATESTREAMPACKETLOSS(3)

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

πŸ’– 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 between 0 and 100. 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