gensio_set_callback(3)

πŸ’– gensio_set_callback(3) β€” Library Functions Manual πŸ’–

okay bestie, welcome to the gensio callback page πŸ’… this one lives in the Library Functions Manual, and it's short but it's important, so grab your strawberry drink πŸ“ and let's get into it.


✨ NAME ✨

gensio_set_callback, gensio_get_user_data, gensio_set_user_data β€” set the event callback and user data for a gensio

the way these three are literally the trio that makes your gensio actually talk back to you 🫢


🌸 SYNOPSIS 🌸

#include <gensio/gensio.h>

void gensio_set_callback(struct gensio *io,
                    gensio_event cb, void *user_data)

void gensio_set_user_data(struct gensio *io, void *user_data);

void *gensio_get_user_data(struct gensio *io)

no cap, that's the whole vibe. three little functions. iconic.


πŸ¦‹ DESCRIPTION πŸ¦‹

gensio_set_callback β€” the main character πŸ‘‘

gensio_set_callback sets the event handler and data for the gensio.

okay this is the part you CANNOT skip, fr fr. this must be done in the GENSIO_ACC_EVENT_NEW_CONNECTION event from a gensio_accepter before any other operation is done on the gensio.

the only exception is that gensio_close may be called with callbacks not set. that's the one lil loophole πŸ™ˆ

you can call this function again if the gensio cannot generate any callbacks, generally after it has been closed. otherwise race conditions may occur. so like... don't be chaotic about it bestie 😭


gensio_set_user_data β€” the lowkey one πŸ’œ

gensio_set_user_data Just sets the user_data field in the gensio.

heads up: if this is called when the gensio is running, race conditions may occur. that's it, that's the warning. respect it πŸ’€

gensio_get_user_data β€” the giving-back one πŸŽ€

gensio_get_user_data Return the user data passed in with the gensio was created or set by one of the above two functions.

so it hands you back whatever you stashed in there when you made the gensio, or whatever one of the two functions above put in there. cute, right? ✨


🌈 SEE ALSO 🌈

like obviously go read those too, iykyk 🧚


and that's the page, bestie!! this one's from the Library Functions Manual, it's the gensio_set_callback(3) page, dated 23 Feb 2019 β€” stay safe out there with your callbacks and your user_data, mwah πŸ’–πŸ’…βœ¨

πŸ“¦ where this page comes from