LC_CHANNE...TECT_GAPS(3)
π lc_channel_detect_gaps, lc_channel_check_seqno β Librecast Programmer's Manual, section 3 π
okay bestie, sit down, hydrate, and let me tell you about lc_channel_detect_gaps and lc_channel_check_seqno β two little functions whose whole job is catching the messages that ghosted you and asking for them back. this is page 3 of the Librecast Programmer's Manual, so you know it's giving "reference material but make it cute". β¨
πΈ NAME πΈ
lc_channel_detect_gaps, lc_channel_check_seqno β check for missing incoming messages and send NACK messages if required π«Ά
π LIBRARY π
Librecast library (liblibrecast, -llibrecast)
β¨ SYNOPSIS β¨
#include <librecast/net.h>
int lc_channel_detect_gaps(lc_channel_t *chan);
int lc_channel_check_seqno(lc_channel_t *chan, lc_seq_t seq);
and like, compile and link it with -llibrecast, obviously π
π DESCRIPTION π
so lc_channel_detect_gaps() sets things up so that a channel starts checking the message sequence numbers of the messages it just received, and fires off NACK messages the second it spots a gap. those NACKs make the sender resend the missing messages, and then they just show up like nothing happened. π for this to work, your app needs to be receiving messages with lc_msg_recv() or lc_socket_listen() β those decode the incoming messages and pull the sequence numbers out, and then gap detection just... happens. automatic. main character behaviour, no cap. π
then there's lc_channel_check_seqno(), which takes the sequence number you hand it, compares it against the sequence numbers of recent messages, and sends NACKs for anything it decides is missing. you have to call this one if your application rolls its own message format and receives messages with functions other than lc_msg_recv() or lc_socket_listen() β because in that case the library has no way to get the sequence numbers out of your messages. but don't worry bestie, the library is still handling gap detection and the NACK messages for you. π the second argument must be the sequence number from the message, as decoded by your application.
β οΈ and listen β you must calllc_channel_detect_gaps()before usinglc_channel_check_seqno(), otherwise the function literally won't do anything. like, nothing. π
this is lowkey useful if gap detection and NACKs are optional for you: your app can conditionally call lc_channel_detect_gaps() during initialisation, and then just unconditionally call lc_channel_check_seqno() after decoding every incoming message. no branching, no stress, we love a clean call site. π
π«Ά RETURN VALUE π«Ά
lc_channel_detect_gaps() returns 0 on success, and -1 to indicate an error, setting the global variable errno to an appropriate code β most likely ENOMEM, which means there wasn't enough memory to set up the required data structures. π
lc_channel_detect_gaps() returns 0 if the message is new, 1 if it's a duplicate (the sequence number has already been seen), and -1 to indicate an error transmitting a NACK message, setting errno to an appropriate code. (yes, that's exactly how the page says it β I'm just the messenger π«‘)
π ERRORS π
lc_channel_detect_gaps() can fail with any of the errors the malloc() library function can produce, plus any errors produced by the lc_channel_sidehash() or lc_socket_new() functions.
lc_channel_check_seqno() can fail with any of the errors the lc_socket_send() function can produce.
π EXAMPLE π
π Program source π
lc_ctx_t *lctx;
lc_channel_t *chan;
lctx = lc_ctx_new();
chan = lc_channel_new(lctx, "channel name");
if (lc_channel_detect_gaps(chan) == -1) {
/* handle this error */
}
/* your program goes here, likely calling lc_msg_recv(chan, ...) or lc_socket_listen(...) */
lc_channel_free(chan);
lc_ctx_free(lctx);
π SEE ALSO π
lc_channel_nack_handler(3), lc_channel_free(3), lc_msg_recv(3), lc_socket_listen(3), lc_socket_send(3)
and that's the whole page, bestie!! this one comes to you from LIBRECAST, dated 2022-10-29, and it lives in the section 3 pages of the Librecast Programmer's Manual. go forth and catch those gaps. πβ¨π¦π§π
π¦ where this page comes from
- debian trixie: liblibrecast-dev 0.9.1-1 Β· GPL-2.0-only OR GPL-3.0-only
- nixos 26.05: librecast 0.11.2
- nixpkgs unstable: librecast 0.11.2
- ubuntu noble: liblibrecast-dev 0.8.0-1.1build1 Β· GPL-2.0-only OR GPL-3.0-only
- ubuntu questing: liblibrecast-dev 0.9.1-1
- ubuntu resolute: liblibrecast-dev 0.11.2-2 Β· GPL-2.0-only OR GPL-3.0-only
- ubuntu stonking: liblibrecast-dev 0.11.2-2build1 Β· GPL-2.0-only OR GPL-3.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms