+static void process_async(int signum, void *arg)
+{
+ struct afb_xreq *xreq = arg;
+ struct afb_api api;
+
+ if (signum != 0) {
+ afb_xreq_fail_f(xreq, "aborted", "signal %s(%d) caught", strsignal(signum), signum);
+ } else {
+ /* init hooking */
+ afb_hook_init_xreq(xreq);
+ if (xreq->hookflags)
+ afb_hook_xreq_begin(xreq);
+
+ /* search the api */
+ if (afb_apiset_get(xreq->apiset, xreq->api, &api) < 0) {
+ afb_xreq_fail_f(xreq, "unknown-api", "api %s not found", xreq->api);
+ } else {
+ xreq->context.api_key = api.closure;
+ api.itf->call(api.closure, xreq);
+ }
+ }
+ afb_xreq_unref(xreq);
+}
+
+void afb_xreq_process(struct afb_xreq *xreq, struct afb_apiset *apiset)
+{
+ xreq->apiset = apiset;
+
+ afb_xreq_addref(xreq);
+ if (jobs_queue(NULL, afb_apiset_timeout_get(apiset), process_async, xreq) < 0) {
+ /* TODO: allows or not to proccess it directly as when no threading? (see above) */
+ ERROR("can't process job with threads: %m");
+ afb_xreq_fail_f(xreq, "cancelled", "not able to create a job for the task");
+ afb_xreq_unref(xreq);
+ }
+ afb_xreq_unref(xreq);
+}