SDL_hid_set_nonblocking(3)

πŸ’– SDL_hid_set_nonblocking πŸ’–

okay bestie, so this one lives in the SDL3 FUNCTIONS manual, and it's lowkey one of those tiny functions that changes your whole vibe. Let's get into it πŸ¦‹


✨ NAME ✨

SDL_hid_set_nonblocking β€” set the device handle to be non-blocking. that's it, that's the job πŸ’…


✨ SYNOPSIS ✨

#include <SDL3/SDL_hidapi.h>

int SDL_hid_set_nonblocking(SDL_hid_device *dev, int nonblock);

like yes, two args, one int back. no drama πŸŽ€


✨ DESCRIPTION ✨

so here's the tea, bestie β˜•

When you're in non-blocking mode, calls to SDL_hid_read() will return immediately with a value of 0 if there is no data to be read. no waiting, no standing around, she simply checks and dips πŸƒβ€β™€οΈ

When you're in blocking mode, SDL_hid_read() will wait (block) until there is data to read before returning. she is committed, she will stand there until the data shows up 😭

and the best part? Nonblocking can be turned on and off at any time. no reload, no restart, just vibes. iconic behavior fr fr πŸ’…


✨ FUNCTION PARAMETERS ✨

  • dev β€” a device handle returned from SDL_hid_open(). this is your main character, your little device bestie 🫢
  • nonblock β€” enable or not the nonblocking reads. 1 to enable nonblocking, 0 to disable nonblocking. binary queen, no in-between πŸ‘‘

✨ RETURN VALUE ✨

Returns 0 on success, or a negative error code on failure 😭 β€” and if it fails, call SDL_GetError() for more information. she will tell you what went wrong, just ask her.

ngl a negative return here is your cue to go read SDL_GetError(). don't just sit there guessing, bestie πŸ’€

✨ AVAILABILITY ✨

This function is available since SDL 3.2.0. so if you're on something older... yeah, that's a no from her πŸ™ˆ


and that's the whole page, bestie! every flag, every value, nothing skipped, we ate and left no crumbs πŸ“

this was brought to you by the Simple Directmedia Layer girlies, running SDL 3.4.18 β€” mwah, go make your HID reads non-blocking, ily πŸ’œπŸ§šβ€β™€οΈ

πŸ“¦ where this page comes from