Blame libasyncns/asyncns.h

Packit 6baad5
#ifndef fooasyncnshfoo
Packit 6baad5
#define fooasyncnshfoo
Packit 6baad5
Packit 6baad5
/***
Packit 6baad5
  This file is part of libasyncns.
Packit 6baad5
Packit 6baad5
  Copyright 2005-2008 Lennart Poettering
Packit 6baad5
Packit 6baad5
  libasyncns is free software; you can redistribute it and/or modify
Packit 6baad5
  it under the terms of the GNU Lesser General Public License as
Packit 6baad5
  published by the Free Software Foundation, either version 2.1 of the
Packit 6baad5
  License, or (at your option) any later version.
Packit 6baad5
Packit 6baad5
  libasyncns is distributed in the hope that it will be useful, but
Packit 6baad5
  WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6baad5
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Packit 6baad5
  Lesser General Public License for more details.
Packit 6baad5
Packit 6baad5
  You should have received a copy of the GNU Lesser General Public
Packit 6baad5
  License along with libasyncns. If not, see
Packit 6baad5
  <http://www.gnu.org/licenses/>.
Packit 6baad5
***/
Packit 6baad5
Packit 6baad5
#include <sys/types.h>
Packit 6baad5
#include <sys/socket.h>
Packit 6baad5
#include <netdb.h>
Packit 6baad5
Packit 6baad5
/** \mainpage
Packit 6baad5
 *
Packit 6baad5
 * \section moo Method of operation
Packit 6baad5
 *
Packit 6baad5
 * To use libasyncns allocate an asyncns_t object with
Packit 6baad5
 * asyncns_new(). This will spawn a number of worker threads (or processes, depending on what is available) which
Packit 6baad5
 * are subsequently used to process the queries the controlling
Packit 6baad5
 * program issues via asyncns_getaddrinfo() and
Packit 6baad5
 * asyncns_getnameinfo(). Use asyncns_free() to shut down the worker
Packit 6baad5
 * threads/processes.
Packit 6baad5
 *
Packit 6baad5
 * Since libasyncns may fork off new processes you have to make sure that
Packit 6baad5
 * your program is not irritated by spurious SIGCHLD signals.
Packit 6baad5
 */
Packit 6baad5
Packit 6baad5
/** \example asyncns-test.c
Packit 6baad5
 * An example program */
Packit 6baad5
Packit 6baad5
#ifdef  __cplusplus
Packit 6baad5
extern "C" {
Packit 6baad5
#endif
Packit 6baad5
Packit 6baad5
/** An opaque libasyncns session structure */
Packit 6baad5
typedef struct asyncns asyncns_t;
Packit 6baad5
Packit 6baad5
/** An opaque libasyncns query structure */
Packit 6baad5
typedef struct asyncns_query asyncns_query_t;
Packit 6baad5
Packit 6baad5
/** Allocate a new libasyncns session with n_proc worker processes/threads */
Packit 6baad5
asyncns_t* asyncns_new(unsigned n_proc);
Packit 6baad5
Packit 6baad5
/** Free a libasyncns session. This destroys all attached
Packit 6baad5
 * asyncns_query_t objects automatically */
Packit 6baad5
void asyncns_free(asyncns_t *asyncns);
Packit 6baad5
Packit 6baad5
/** Return the UNIX file descriptor to select() for readability
Packit 6baad5
 * on. Use this function to integrate libasyncns with your custom main
Packit 6baad5
 * loop. */
Packit 6baad5
int asyncns_fd(asyncns_t *asyncns);
Packit 6baad5
Packit 6baad5
/** Process pending responses. After this function is called you can
Packit 6baad5
 * get the next completed query object(s) using asyncns_getnext(). If
Packit 6baad5
 * block is non-zero wait until at least one response has been
Packit 6baad5
 * processed. If block is zero, process all pending responses and
Packit 6baad5
 * return. */
Packit 6baad5
int asyncns_wait(asyncns_t *asyncns, int block);
Packit 6baad5
Packit 6baad5
/** Issue a name to address query on the specified session. The
Packit 6baad5
 * arguments are compatible with the ones of libc's
Packit 6baad5
 * getaddrinfo(3). The function returns a new query object. When the
Packit 6baad5
 * query is completed you may retrieve the results using
Packit 6baad5
 * asyncns_getaddrinfo_done().*/
Packit 6baad5
asyncns_query_t* asyncns_getaddrinfo(asyncns_t *asyncns, const char *node, const char *service, const struct addrinfo *hints);
Packit 6baad5
Packit 6baad5
/** Retrieve the results of a preceding asyncns_getaddrinfo()
Packit 6baad5
 * call. Returns a addrinfo structure and a return value compatible
Packit 6baad5
 * with libc's getaddrinfo(3). The query object q is destroyed by this
Packit 6baad5
 * call and may not be used any further. Make sure to free the
Packit 6baad5
 * returned addrinfo structure with asyncns_freeaddrinfo() and not
Packit 6baad5
 * libc's freeaddrinfo(3)! If the query is not completed yet EAI_AGAIN
Packit 6baad5
 * is returned.*/
Packit 6baad5
int asyncns_getaddrinfo_done(asyncns_t *asyncns, asyncns_query_t* q, struct addrinfo **ret_res);
Packit 6baad5
Packit 6baad5
/** Issue an address to name query on the specified session. The
Packit 6baad5
 * arguments are compatible with the ones of libc's
Packit 6baad5
 * getnameinfo(3). The function returns a new query object. When the
Packit 6baad5
 * query is completed you may retrieve the results using
Packit 6baad5
 * asyncns_getnameinfo_done(). Set gethost (resp. getserv) to non-zero
Packit 6baad5
 * if you want to query the hostname (resp. the service name). */
Packit 6baad5
asyncns_query_t* asyncns_getnameinfo(asyncns_t *asyncns, const struct sockaddr *sa, socklen_t salen, int flags, int gethost, int getserv);
Packit 6baad5
Packit 6baad5
/** Retrieve the results of a preceding asyncns_getnameinfo()
Packit 6baad5
 * call. Returns the hostname and the service name in ret_host and
Packit 6baad5
 * ret_serv. The query object q is destroyed by this call and may not
Packit 6baad5
 * be used any further. If the query is not completed yet EAI_AGAIN is
Packit 6baad5
 * returned. */
Packit 6baad5
int asyncns_getnameinfo_done(asyncns_t *asyncns, asyncns_query_t* q, char *ret_host, size_t hostlen, char *ret_serv, size_t servlen);
Packit 6baad5
Packit 6baad5
/** Issue a resolver query on the specified session. The arguments are
Packit 6baad5
 * compatible with the ones of libc's res_query(3). The function returns a new
Packit 6baad5
 * query object. When the query is completed you may retrieve the results using
Packit 6baad5
 * asyncns_res_done().  */
Packit 6baad5
asyncns_query_t* asyncns_res_query(asyncns_t *asyncns, const char *dname, int class, int type);
Packit 6baad5
Packit 6baad5
/** Issue an resolver query on the specified session. The arguments are
Packit 6baad5
 * compatible with the ones of libc's res_search(3). The function returns a new
Packit 6baad5
 * query object. When the query is completed you may retrieve the results using
Packit 6baad5
 * asyncns_res_done().  */
Packit 6baad5
asyncns_query_t* asyncns_res_search(asyncns_t *asyncns, const char *dname, int class, int type);
Packit 6baad5
Packit 6baad5
/** Retrieve the results of a preceding asyncns_res_query() or
Packit 6baad5
 * asyncns_res_search call.  The query object q is destroyed by this
Packit 6baad5
 * call and may not be used any further. Returns a pointer to the
Packit 6baad5
 * answer of the res_query call. If the query is not completed yet
Packit 6baad5
 * -EAGAIN is returned, on failure -errno is returned, otherwise the
Packit 6baad5
 * length of answer is returned. Make sure to free the answer is a
Packit 6baad5
 * call to asyncns_freeanswer(). */
Packit 6baad5
int asyncns_res_done(asyncns_t *asyncns, asyncns_query_t* q, unsigned char **answer);
Packit 6baad5
Packit 6baad5
/** Return the next completed query object. If no query has been
Packit 6baad5
 * completed yet, return NULL. Please note that you need to run
Packit 6baad5
 * asyncns_wait() before this function will return sensible data.  */
Packit 6baad5
asyncns_query_t* asyncns_getnext(asyncns_t *asyncns);
Packit 6baad5
Packit 6baad5
/** Return the number of query objects (completed or not) attached to
Packit 6baad5
 * this session */
Packit 6baad5
int asyncns_getnqueries(asyncns_t *asyncns);
Packit 6baad5
Packit 6baad5
/** Cancel a currently running query. q is is destroyed by this call
Packit 6baad5
 * and may not be used any futher. */
Packit 6baad5
void asyncns_cancel(asyncns_t *asyncns, asyncns_query_t* q);
Packit 6baad5
Packit 6baad5
/** Free the addrinfo structure as returned by
Packit 6baad5
 * asyncns_getaddrinfo_done(). Make sure to use this functions instead
Packit 6baad5
 * of the libc's freeaddrinfo()! */
Packit 6baad5
void asyncns_freeaddrinfo(struct addrinfo *ai);
Packit 6baad5
Packit 6baad5
/** Free the answer data as returned by asyncns_res_done().*/
Packit 6baad5
void asyncns_freeanswer(unsigned char *answer);
Packit 6baad5
Packit 6baad5
/** Returns non-zero when the query operation specified by q has been completed */
Packit 6baad5
int asyncns_isdone(asyncns_t *asyncns, asyncns_query_t*q);
Packit 6baad5
Packit 6baad5
/** Assign some opaque userdata with a query object */
Packit 6baad5
void asyncns_setuserdata(asyncns_t *asyncns, asyncns_query_t *q, void *userdata);
Packit 6baad5
Packit 6baad5
/** Return userdata assigned to a query object. Use
Packit 6baad5
 * asyncns_setuserdata() to set this data. If no data has been set
Packit 6baad5
 * prior to this call it returns NULL. */
Packit 6baad5
void* asyncns_getuserdata(asyncns_t *asyncns, asyncns_query_t *q);
Packit 6baad5
Packit 6baad5
#ifdef  __cplusplus
Packit 6baad5
}
Packit 6baad5
#endif
Packit 6baad5
Packit 6baad5
#endif