32 #include <sys/types.h>
34 #include <sys/socket.h>
46 #include <yaz/tcpip.h>
56 #define USE_THREADED_RESOLVER 1
71 struct addrinfo hints, *res;
77 hints.ai_family = AF_UNSPEC;
78 hints.ai_socktype = SOCK_STREAM;
79 hints.ai_protocol = 0;
82 hints.ai_canonname = NULL;
85 if (!strncmp(w->
hostport,
"http://", 7))
88 strncpy(host, w->
hostport + 7,
sizeof(host)-1);
90 else if (!strncmp(w->
hostport,
"https://", 8))
93 strncpy(host, w->
hostport + 8,
sizeof(host)-1);
97 strncpy(host, w->
hostport,
sizeof(host)-1);
99 host[
sizeof(host)-1] = 0;
100 if ((cp = strrchr(host,
':')))
105 error = getaddrinfo(host, port, &hints, &res);
108 yaz_log(YLOG_WARN,
"Failed to resolve %s: %s",
115 if (getnameinfo((
struct sockaddr *) res->ai_addr, res->ai_addrlen,
116 n_host,
sizeof(n_host)-1,
118 NI_NUMERICHOST) == 0)
120 w->
ipport = xmalloc(strlen(n_host) + (port ? strlen(port) : 0) + 2);
121 strcpy(w->
ipport, n_host);
131 yaz_log(YLOG_LOG|YLOG_ERRNO,
"getnameinfo failed for %s",
145 yaz_log(
log_level,
"waiting %d seconds", sec);
153 #if USE_THREADED_RESOLVER
178 yaz_log(YLOG_FATAL|YLOG_ERRNO,
"sel_create_create failed");
184 "getaddrinfo_socket");
195 struct work *w = xmalloc(
sizeof(*w));
203 #if USE_THREADED_RESOLVER
206 if (resolver_thread == 0)
208 assert(resolver_thread);
void iochan_add(iochan_man_t man, IOCHAN chan)
Z39.50 connection (low-level client)
IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags, const char *name)
static sel_thread_t resolver_thread
Represents a host (irrespective of databases)
#define iochan_setdata(i, d)
void iochan_handler(struct iochan *i, int event)
void sel_thread_add(sel_thread_t p, void *data)
adds work to be carried out in thread
int host_getaddrinfo(struct host *host, iochan_man_t iochan_man)
static void error(struct http_response *rs, enum pazpar2_error_code code, const char *addinfo)
sel_thread_t sel_thread_create(void(*work_handler)(void *work_data), void(*work_destroy)(void *work_data), int *read_fd, int no_of_threads)
creates select thread
#define iochan_getdata(i)
void * sel_thread_result(sel_thread_t p)
gets result of work
static void perform_getaddrinfo(struct work *w)
static void work_handler(void *vp)
static void getaddrinfo_start(iochan_man_t iochan_man)
void connect_resolver_host(struct host *host, iochan_man_t iochan_man)