gensio_set_sync(3)
β¨ gensio_set_sync β¨
okay bestie, welcome to the gensio library functions manual π this one's about doing I/O the synchronous way, and honestly? sometimes you just need that. let's get into it.
π NAME π
gensio_set_sync, gensio_clear_sync, gensio_read_s, gensio_write_s β synchronous I/O operations on a gensio π¦
πΈ SYNOPSIS πΈ
#include <gensio/gensio.h>
int gensio_set_sync(struct gensio *io);
int gensio_clear_sync(struct gensio *io);
int gensio_read_s(struct gensio *io, gensiods *count,
void *data, gensiods datalen,
struct gensio_time *timeout);
int gensio_read_s_intr(struct gensio *io, gensiods *count,
void *data, gensiods datalen,
struct gensio_time *timeout);
int gensio_write_s(struct gensio *io, gensiods *count,
const void *data, gensiods datalen,
struct gensio_time *timeout);
int gensio_write_s_intr(struct gensio *io, gensiods *count,
const void *data, gensiods datalen,
struct gensio_time *timeout);
π DESCRIPTION π
so normal gensio behavior is asynchronous callback based, and ngl that serves most programs so well, especially when you're listening to multiple connections at the same time. like, you would NOT want to write a compiler this way, bestie, but if you're writing something that's driven by external events, this event-driven style of programming? it just works. π«Ά
think about it β if you're using something like poll, select, etc., you almost always end up with something like:
poll(fds...)
if (fd1 read is set)
call fd1_read_handler()
if (fd1 write is set)
call fd1_write_handler()
if (fd2 read is set)
...
and the gensio handling does all of this for you. β¨ you just register a handler with the gensio to get the read and write calls. it's more efficient, neater, and you end up with less code. iconic, honestly.
but occasionally you need to do something synchronous with the program execution. for instance, in gtlsshd, if the initial certificate and password verification fails, it uses PAM to handle reading the password from the remote gensio. that requires synchronous I/O, and it uses this capability. periodt. π
π the functions π
gensio_set_syncβ sets up the gensio for synchronous I/O. if you do this, the event callback that's currently registered will no longer receive read and write callbacks. it will receive other callbacks. you must call this before doing any of the synchronous read and write operations. this function will block (while handling normal gensio events) until no callbacks are active. π§gensio_clear_syncβ returns the gensio to asynchronous I/O. the callback will be restored to the one that was set whengensio_set_sync()was called. πgensio_read_sβ waits for data from the gensio, up todatalenbytes.count(if notNULL) will be updated to the actual number of bytes read. this will wait for any read and will return whatever that read was, even if it is less thandatalen. this function waits for the amount of time intimeout.timeoutis updated to the amount of time left to wait. iftimeoutisNULL, wait forever. πgensio_write_sβ writes data to the gensio.count(if notNULL) will be updated to the actual number of bytes written. this function will wait until either the timeout occurs or all the data is written. this function waits for the amount of time intimeout.timeoutis updated to the amount of time left to wait. iftimeoutisNULL, wait forever. πgensio_read_s_intrandgensio_write_s_intrβ likegensio_read_sandgensio_write_s, but they return immediately if a signal interrupt occurs. on systems without signals, these are the same asgensio_read_sandgensio_write_s. π
fr fr, remember:gensio_set_syncis the must before any sync read/write, andNULLtimeout means you're waiting forever. no cap.
β RETURN VALUES β
zero is returned on success, or a gensio error on failure. that's it, that's the vibe check. β¨
π¦ SEE ALSO π¦
and that's the whole page, bestie!! π this was gensio_set_sync(3) from the Library Functions Manual, dated 27 Feb 2019 β go slay some synchronous I/O, you've got this ππΈπ
π¦ where this page comes from
- alpine 3.22: gensio-doc 2.8.14-r0 Β· GPL-2.0-only AND LGPL-2.1-only AND Apache-2.0
- alpine 3.23: gensio-doc 2.8.14-r0 Β· GPL-2.0-only AND LGPL-2.1-only AND Apache-2.0
- alpine 3.24: gensio-doc 2.8.14-r0 Β· GPL-2.0-only AND LGPL-2.1-only AND Apache-2.0
- arch rolling: gensio 3.0.4-1 Β· GPL
- debian bookworm: libgensio-dev 2.6.2-4 Β· GPL-2.0-only
- debian trixie: libgensio-dev 2.8.13-7 Β· GPL-2.0-only
- epel 9: libgensio-devel 2.8.15-1.el9 Β· GPL-2.0-only AND LGPL-2.1-only AND Apache-2.0
- fedora 43: libgensio-devel 2.8.15-5.fc43 Β· GPL-2.0-only AND LGPL-2.1-only AND Apache-2.0
- fedora 43: libgensio-devel 2.8.15-5.fc43 Β· GPL-2.0-only AND LGPL-2.1-only AND Apache-2.0
- fedora 43: libgensio-devel 3.0.4-1.fc43 Β· GPL-2.0-only AND LGPL-2.1-only AND Apache-2.0
- fedora 43: libgensio-devel 3.0.4-1.fc43 Β· GPL-2.0-only AND LGPL-2.1-only AND Apache-2.0
- fedora 44: libgensio-devel 3.0.2-1.fc44 Β· GPL-2.0-only AND LGPL-2.1-only AND Apache-2.0
- fedora 44: libgensio-devel 3.0.2-1.fc44 Β· GPL-2.0-only AND LGPL-2.1-only AND Apache-2.0
- fedora 44: libgensio-devel 3.0.4-1.fc44 Β· GPL-2.0-only AND LGPL-2.1-only AND Apache-2.0
- fedora 44: libgensio-devel 3.0.4-1.fc44 Β· GPL-2.0-only AND LGPL-2.1-only AND Apache-2.0
- nixos 26.05: gensio 3.0.2
- nixpkgs unstable: gensio 3.0.2
- opensuse-leap 16.0: gensio-devel 2.8.2-bp160.1.13 Β· Apache-2.0 AND GPL-2.0-only AND LGPL-2.1-only
- opensuse-leap 16.0: gensio-devel 2.8.2-bp160.1.13 Β· Apache-2.0 AND GPL-2.0-only AND LGPL-2.1-only
- opensuse-leap 16.0: gensio-devel 2.8.2-bp160.1.13 Β· Apache-2.0 AND GPL-2.0-only AND LGPL-2.1-only
- opensuse-leap 16.0: gensio-devel 2.8.2-bp160.1.13 Β· Apache-2.0 AND GPL-2.0-only AND LGPL-2.1-only
- ubuntu noble: libgensio-dev 2.8.2-6.1build1 Β· GPL-2.0-only
- ubuntu questing: libgensio-dev 2.8.13-7
- ubuntu resolute: libgensio-dev 3.0.0-1build1 Β· GPL-2.0-only
- ubuntu stonking: libgensio-dev 3.0.0-1ubuntu1 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms