KNET_HAND...CK_NOTIFY(3)

πŸ’– KNET_HAND...CK_NOTIFY(3) πŸ’–

okay bestie, welcome to the Kronosnet Programmer's Manual β€” this is the page for knet_handle_enable_sock_notify, and it's lowkey one of the most important ones bc it's literally how you find out your sockets are having a moment 🫢


✨ NAME ✨

knet_handle_enable_sock_notify β€” register a callback so you can get notified about socket events, no cap πŸ“£


🌸 SYNOPSIS 🌸

#include <libknet.h>

int knet_handle_enable_sock_notify(
    knet_handle_t  knet_h,
    void          *sock_notify_fn_private_data,
    void(*)(void *private_data, int datafd, int8_t channel, uint8_t tx_rx, int error, int errorno)  sock_notify_fn
);

πŸ¦‹ DESCRIPTION πŸ¦‹

So the function is knet_handle_enable_sock_notify, and here's the whole vibe:

  • knet_h β€” pointer to knet_handle_t πŸ’… that's your handle, your main character, the whole thing.
  • sock_notify_fn_private_data β€” a void pointer to data you can use to identify the callback. like a little name tag for your callback so you know who's who at the party πŸŽ€
  • sock_notify_fn β€” a callback function that gets invoked every single time a socket in the datafd pool reports an error (-1) or an end of read (0) (see socket.7).
⚠️ This function MUST NEVER block or add substantial delays. Not even a little. It's giving "quick check-in", not "let me think about it". 😭

The callback is invoked in an internal unlocked area β€” that's on purpose, bestie β€” so that calls to knet_handle_add_datafd/knet_handle_remove_datafd are allowed to swap/replace the bad fd. ✨

And here's the detail that trips people up: if both err and errno are 0, that means the socket has received a 0 byte packet (EOF?). πŸ‘€

The callback function must either remove the fd from knet (by calling knet_handle_remove_fd()) or dup a new fd in its place. Failure to do this can cause problems. like, actual problems. don't skip this step fr fr πŸ’€


⭐ RETURN VALUE ⭐

knet_handle_enable_sock_notify returns 0 on success, -1 on error, and errno is set. periodt. πŸ‘‘


πŸ’œ SEE ALSO πŸ’œ

the whole friend group showed up, and we are obsessed:


Copyright (C) 2010-2026 Red Hat, Inc. All rights reserved.


and that's the page bestie!! πŸ’– this lil manual page is from kronosnet, dated 2026-07-20 β€” slay, go forth and never block in your callback 🧚✨

πŸ“¦ where this page comes from