int host_getaddrinfo(struct host *host, iochan_man_t iochan_man) { struct work *w = xmalloc(sizeof(*w)); int use_thread = 0; /* =0 to disable threading entirely */ w->hostport = host->tproxy ? host->tproxy : host->proxy; w->ipport = 0; w->host = host; w->iochan_man = iochan_man; #if USE_THREADED_RESOLVER if (use_thread) { if (resolver_thread == 0) getaddrinfo_start(iochan_man); assert(resolver_thread); sel_thread_add(resolver_thread, w); return 0; } #endif perform_getaddrinfo(w); host->ipport = w->ipport; xfree(w); if (!host->ipport) return -1; return 0; }
static void run_fun(iochan_man_t man, IOCHAN p) { if (p->this_event) { if (man->sel_thread) { yaz_log(man->log_level, "eventl: work add chan=%p name=%s event=%d", p, p->name ? p->name : "", p->this_event); p->thread_users++; sel_thread_add(man->sel_thread, p); } else work_handler(p); } }
void iochan_handler(struct iochan *i, int event) { static int number = 0; sel_thread_t p = iochan_getdata(i); if (event & EVENT_INPUT) { struct my_work_data *work; work = sel_thread_result(p); YAZ_CHECK(work); if (work) { YAZ_CHECK_EQ(work->x * 2, work->y); /* stop work after a couple of iterations */ if (work->x > 10) iochan_destroy(i); xfree(work); } } if (event & EVENT_TIMEOUT) { struct my_work_data *work; work = xmalloc(sizeof(*work)); work->x = number; sel_thread_add(p, work); work = xmalloc(sizeof(*work)); work->x = number+1; sel_thread_add(p, work); number += 10; } }