Topology queries (7)
xsServerFind returns a lease with a reference, which must be paired with xsServerRelease; enumeration callback parameters are borrowed for the callback only — xsServerRetain before storing them. A host is jointly protected by its server lease.xsServerFind query
Find a server by its globally unique name; returns a retained lease.
XS_ServerInfo* pSrv = xsServerFind("demo");
if ( pSrv != NULL ) {
/* use the topology info ... */
xsServerRelease(pSrv);
}
xsServerRetain / xsServerRelease query
Extend a server lease / return the reference. Retain for the lifetime of a connection, and before storing anything beyond an enumeration callback.
xsHostFind query
Find a host by name within a server; the result is jointly protected by the passed-in server lease (no separate release needed).
xsEnumServers / xsEnumHosts query
Enumerate all servers / all hosts of a server. Parameters are borrowed for the callback only.
static bool PrintServer(XS_ServerInfo* pServer, void* pUserData)
{
printf("server: %s (%s)\n", pServer->Name, pServer->Class);
return true; /* keep enumerating */
}
xsEnumServers(PrintServer, NULL);
xsConfigRoot query
Returns xs.json's top-level Custom (everything beyond the preset fields), for the application to read its custom knobs.
Hot reload (7)
reload is a desired-state reconciliation task, not a synchronous command. The terminal-state machine: ACCEPTED → PREPARING → SUCCEEDED / FAILED / SUPERSEDED / CANCELLED; a new intent on the same server overrides unexecuted older ones; the pending cap is 64.
xsReloadHostSubmit reload
Submit a reload intent for one host (its owning server is the publishing unit).
xsReloadServerSubmit reload
Submit a reload intent for a whole server, by name.
xsReloadAllSubmit reload
A batch transaction: candidates of every server are precompiled; any failure rolls the whole thing back.
xsReloadQuery reload
Query an intent's terminal state; the result carries the content fingerprint Revision and the target description.
| XS_ReloadResult field | Notes |
|---|---|
Id / State | the intent ID and one of the seven states |
Revision | content fingerprint of the immutable input snapshot (includes the script fingerprint when there is no config input) |
Target[160] / Message[256] | target description and result message (the failure reason) |
XS_ReloadId iId = xsReloadHostSubmit(pHost);
XS_ReloadResult tRes;
if ( iId != 0 && xsReloadQuery(iId, &tRes) )
printf("reload #%llu: %d\n",
(unsigned long long)tRes.Id, (int)tRes.State);
xsReloadHost / xsReloadServer / xsReloadAll reload
bool-compatible wrappers — they only report whether Submit returned non-zero; they do not wait for a terminal state.
Timers (2)
xsTimerAfter timer
A one-shot timer, bound to the owner's generation — a generation swap invalidates the old generation's timers; they never fire into the new one.
static void OnTick(void* pUserData)
{
printf("tick: %s\n", (const char*)pUserData);
}
/* inside ServiceInit: fire once after 5 s */
(void)xsTimerAfter(pHost, 5000, OnTick, "hello");
xsTimerCancel timer
Cancel a timer. IDs that already fired or were invalidated by a generation swap return false.
Deploy & nesting (3)
xsAppPath deploy
The application (executable) directory, UTF-8 — identical to the config directory; the anchor for resolving relative paths.
xsExtensionEnabled deploy
Runtime probe: is an optional library compiled into this variant, by registry name (= the build argument, matching the startup banner and --version). Case-insensitive; dependencies pulled in via requires are visible too; unknown names, empty strings and NULL return false without setting an error. The compile-time equivalent is #ifdef XS_USE_<name>.
if ( xsExtensionEnabled("sqlite") ) {
/* this host carries sqlite — use it directly */
db_open(&db);
} /* not compiled in: take the alternate path */
xsExtensionCount / xsExtensionName deploy
Enumerate the extensions compiled into this variant: count returns the number, name returns the name by index (= the build argument, same data source as the startup banner and --version). The returned pointer borrows a static constant — valid for the process lifetime, no release needed; out-of-range indexes return NULL without setting an error. Under the default variant count is 0; every enumerated name fed to xsExtensionEnabled is true.
for ( uint32 i = 0; i < xsExtensionCount(); i++ ) {
printf("%u: %s
", i, xsExtensionName(i));
}
xsCreateTCC / xsDestroyTCC nesting
Create a nested compiler with the standard include/lib paths and symbol imports preset — the foundation of the application-level plugin system.
State handover (1)
xsSwapTake handover
Valid only inside the new generation's ServiceInit: take the snapshot exported by the old generation's ServiceSwap. Returns NULL when there is no handover data.
static void ServiceInit(XS_HostInfo* pHost)
{
xvalue* pState = xsSwapTake(pHost);
if ( pState != NULL ) {
G_iCounter = xrtValueInt64(
xrtValueObjectGet(pState, "counter"));
xrtValueRelease(pState); /* taken: release it yourself */
}
}