feat(libxce-failover): capture redirect hint in handle_reply (before free, before status return); verify endpoint-error wake (task 2.3)

This commit is contained in:
Rongsong Shen 2026-06-17 03:11:18 +00:00
parent c7e11a4e9e
commit cec2e647dc
4 changed files with 192 additions and 1 deletions

View file

@ -27,10 +27,36 @@ static int handle_sub_reply(xce_ctx_t* ctx, xce_reply_t* reply)
return 1;
}
void xce_ctx_capture_redirect_hint(xce_ctx_t* ctx, const char* host,
uint16_t port)
{
if (ctx == NULL) {
return;
}
/* No usable redirect address → leave the hint untouched (empty). The
* capnp-owned host pointer may be NULL; an empty host or a zero port is
* likewise "no address". Advisory only — correctness never depends on it. */
if ((host == NULL) || (host[0] == '\0') || (port == 0)) {
return;
}
strncpy(ctx->redirect_hint_host, host, XCE_MAXHOSTNAME_LEN - 1);
ctx->redirect_hint_host[XCE_MAXHOSTNAME_LEN - 1] = '\0';
ctx->redirect_hint_port = port;
}
static int handle_reply(xce_ctx_t* ctx, xce_reply_t* reply)
{
int rc = 0;
/* Capture the redirect address (if any) as a best-effort failover hint
* BEFORE the capnp-owned reply — including reply->redirect_host — is freed
* by the caller (Req 2.2, 8.3). The status still flows through the existing
* cbuf_tryput(&ctx->wbuf,&status) path unchanged, so xceapi.c is untouched. */
xce_ctx_capture_redirect_hint(ctx, reply->redirect_host,
reply->redirect_port);
if (reply->status < 0) {
return reply->status;
}