ARES_SET_N...E_CALLBACK(3)
π ARES_SET_N...E_CALLBACK(3) β ares_set_pending_write_cb / ares_process_pending_write β Library Functions Manual π
π NAME π
ares_set_pending_write_cb, ares_process_pending_write β okay so this is the function for setting a callback which is triggered when there is potential pending data which needs to be written. Slay. β¨
β¨ 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 π¦
The way that ares_set_pending_write_cb(3) works is: it sets a callback function callback in the given ares channel handle channel that is invoked whenever there is new pending TCP data to be written. No cap. π
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. Itβs giving efficiency era. β¨
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. Main character event loop energy, fr fr.
π¨ Bestie, listen: each time the callback is triggered must result in a call toares_process_pending_write(3)from the caller's event loop otherwise stalls and timeouts may occur. And the callback must not call any c-ares function on the same channel; its only job is to wake the event loop. In particular, callingares_process_pending_write(3)directly would invalidate any advantage of this use-case. Periodt. π
This is considered an optimization, especially when using TLS-based connections which add additional overhead to the data stream. Obsessed with a little optimization moment. π¦
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. iykyk. β¨
If no callback is set, data will be written immediately to the socket, thus bypassing this optimization. Lowkey simple like that. π«Ά
β οΈ Vibe check / important caveat: this option cannot be used withARES_OPT_EVENT_THREADpassed toares_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. Not me warning you with love. π
πΈ AVAILABILITY πΈ
This function was first introduced in c-ares version 1.34.0. Iconic debut. β¨
π SEE ALSO π
okay bye bestie π β this cutie comes from the ARES_SET_N...E_CALLBACK(3) page, dated 13 Aug 2024, mwah π
π¦ where this page comes from
- alpine 3.22: c-ares-doc 1.34.9-r0 Β· MIT
- alpine 3.23: c-ares-doc 1.34.9-r0 Β· MIT
- alpine 3.24: c-ares-doc 1.34.9-r0 Β· MIT
- arch rolling: c-ares 1.34.9-1 Β· MIT
- centos-stream 10: c-ares-devel 1.34.9-1.el10 Β· MIT
- nixos 26.05: c-ares 1.34.9
- π the page's license: MIT
- Copyright 2024 by the c-ares project and its contributors
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms