ARES_SET_N...E_CALLBACK(3)

πŸ“¦
version 1.34.9 Β· 2 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, nixos 26.05

✨ NAME ✨

okay so bestie, this page is for ares_set_pending_write_cb(3) and ares_process_pending_write(3), straight out of the Library Functions Manual. It's the function for setting a callback which is triggered when there is potential pending data which needs to be written. πŸ’–

🌈 SYNOPSIS 🌈

#include <ares.h>

typedef void (*ares_pending_write_cb)(void *data);

void ares_set_pending_write_cb(
  ares_channel_t        *channel,
  ares_pending_write_cb  callback,
  void                  *user_data);

void ares_process_pending_write(ares_channel_t *channel);

πŸ’… DESCRIPTION πŸ’…

okay so ares_set_pending_write_cb(3) sets a callback function callback in the given ares channel handle channel, and that callback is invoked whenever there is new pending TCP data to be written. periodt. 🫢

Since TCP is stream based, if there are multiple queries being enqueued back to back they can be sent as one large buffer. Normally a send(2) syscall operation would be triggered for each query β€” this is the glow-up that avoids that whole situation. ✨

When setting this callback, an event will be triggered when data is buffered, but not written. This event is used to wake the caller's event loop, which should call ares_process_pending_write(3) using the channel associated with the callback. πŸ‘‘

🚨 Each time the callback is triggered must result in a call to ares_process_pending_write(3) from the caller's event loop, otherwise stalls and timeouts may occur. This is not a drill, bestie. 😭
🚫 The callback must not call any c-ares function on the same channel; its only job is to wake the event loop. In particular, calling ares_process_pending_write(3) directly would invalidate any advantage of this use-case. so don't do it, okay? πŸ’€

This is considered an optimization, especially when using TLS-based connections which add additional overhead to the data stream. Due to the asynchronous nature of c-ares, there is no way to identify when a caller may be finished enqueuing queries via any of the possible public API calls such as ares_getaddrinfo(3) or ares_search_dnsrec(3), so this is an enhancement to try to group query send operations together and will rely on the signaling latency involved in waking the user's event loop. It's giving group-project energy for your queries. 🧚

If no callback is set, data will be written immediately to the socket, thus bypassing this optimization. no callback, no wait, just send. πŸ’…

⚠️ This option cannot be used with ARES_OPT_EVENT_THREAD passed to ares_init_options(3) since the user has no event loop. This optimization is automatically enabled when using the Event Thread as it sets the callback for its own internal signaling. That's the Event Thread doing its own built-in thing, iykyk. 🌈

πŸ¦‹ AVAILABILITY πŸ¦‹

This function was first introduced in c-ares version 1.34.0. iconic behavior since then. πŸŽ€

πŸŽ€ SEE ALSO πŸŽ€


okay that's the whole page. this gem comes from the Library Functions Manual and is dated 13 Aug 2024 β€” love that for us. mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from