ARES_CANCEL(3)

okay bestie, welcome to ARES_CANCEL(3) from the Library Functions Manual β€” the little page that literally says β€œcancel a resolve” and honestly? iconic 🫢

πŸŽ€ NAME πŸŽ€

ares_cancel β€” cancel a resolve πŸ’…

✨ SYNOPSIS ✨

#include <ares.h>

void ares_cancel(ares_channel_t *channel)

🌸 DESCRIPTION 🌸

So ares_cancel(3) cancels all the lookups/requests made on the name service channel identified by channel. Not some. Not a few. All of them, bestie 😭

When it does that, it invokes the callbacks for each pending query on the channel and passes them a status of ARES_ECANCELLED. This is the whole point: those calls give the callbacks a chance to clean up any state that might have been stored in their arguments. Obsessed with a graceful exit πŸ’–

One tiny but important vibe check: if one of those callback invocations adds a new request to the channel, that request will not be cancelled by the current invocation of ares_cancel(3). New request = new era, it survives this cancel ✨

πŸ” REENTRANCY πŸ”

A callback invoked by ares_cancel(3) may call c-ares functions on the same channel. Yes, fr fr β€” and here’s why it’s not chaotic: the channel lock is recursive, and each query is unlinked from the library’s internal structures before its callback runs. So a reentrant call cannot encounter a query that is part-way through being torn down. No half-torn-down query jumpscare πŸ’€

This includes starting new lookups, as described above, and reconfiguring the server list with ares_set_servers_csv(3) and related functions. Slay 🌈

πŸ“… AVAILABILITY πŸ“…

The reentrancy guarantee described above applies as of c-ares version 1.35.0, and c-ares version 1.34.9 on the 1.34 branch. Cute, specific, documented πŸŽ€

πŸ‘€ SEE ALSO πŸ‘€

πŸ“ NOTES πŸ“

  • This function was added in c-ares 1.2.0 ⭐
  • c-ares 1.6.0 and earlier pass a status of ARES_ETIMEOUT instead of ARES_ECANCELLED. Lowkey ancient lore, but important 🧚

xoxo, that was the ARES_CANCEL(3) page from the Library Functions Manual, dated 31 March 2004 β€” bye bestie, stay iconic πŸ’–πŸ«Ά

πŸ“¦ where this page comes from