mirror of
https://github.com/lucannez64/darling-lol.git
synced 2026-10-27 19:54:38 +00:00
Wait up to 2 s for the cancellation callback instead of one 50 ms run-loop pass, count only callbacks without stored addresses so a completed lookup cannot pass as a cancellation, print the failing stage, and have the runner require the exact success line since Darling can exit zero after a trap. Co-Authored-By: Claude Opus 5.5 <[email protected]>
44 lines
1.9 KiB
C
44 lines
1.9 KiB
C
#include <CoreFoundation/CoreFoundation.h>
|
|
#include <CFNetwork/CFHost.h>
|
|
#include <stdio.h>
|
|
|
|
static unsigned callbacks, unexpected;
|
|
static void completed(CFHostRef host, CFHostInfoType type,
|
|
const CFStreamError *error, void *info) {
|
|
/* A cancellation stores no addresses; a completed lookup always does. */
|
|
Boolean resolved = false;
|
|
if (host) CFHostGetAddressing(host, &resolved);
|
|
if (host && type == kCFHostAddresses && info == &callbacks && !resolved)
|
|
++callbacks;
|
|
else
|
|
++unexpected;
|
|
}
|
|
|
|
static int fail(const char *stage, unsigned i) {
|
|
printf("CFHOST_CANCEL_CHECK fail stage=%s iteration=%u callbacks=%u unexpected=%u\n",
|
|
stage, i, callbacks, unexpected);
|
|
return 1;
|
|
}
|
|
|
|
int main(void) {
|
|
CFHostClientContext context = {0, &callbacks, NULL, NULL, NULL};
|
|
for (unsigned i = 0; i < 100; ++i) {
|
|
CFHostRef host = CFHostCreateWithName(NULL, CFSTR("localhost"));
|
|
CFStreamError error = {0};
|
|
if (!host || !CFHostSetClient(host, completed, &context)) return fail("client", i);
|
|
CFHostScheduleWithRunLoop(host, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
|
|
if (!CFHostStartInfoResolution(host, kCFHostAddresses, &error)) return fail("start", i);
|
|
CFHostCancelInfoResolution(host, kCFHostAddresses);
|
|
/* The cancel source must keep its host alive until delivery. */
|
|
if (i % 2) CFRelease(host);
|
|
CFAbsoluteTime deadline = CFAbsoluteTimeGetCurrent() + 2.0;
|
|
while (callbacks != i + 1 && !unexpected && CFAbsoluteTimeGetCurrent() < deadline)
|
|
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.05, true);
|
|
if (unexpected) return fail("unexpected-callback", i);
|
|
if (callbacks != i + 1) return fail("cancel-callback", i);
|
|
if (!(i % 2)) CFRelease(host);
|
|
}
|
|
puts("CFHOST_CANCEL_CHECK cancel callback lifetime repeated pass=1");
|
|
return 0;
|
|
}
|