sample-async.c revision d7201de09b85929a86b157f4b2d91667c68c6b52
/*
* Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
*
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: sample-async.c,v 1.4 2009/09/02 23:48:02 tbox Exp $ */
#include <config.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <isc/sockaddr.h>
#include <dns/fixedname.h>
#include <dns/rdataset.h>
#include <dns/rdatatype.h>
#define MAX_SERVERS 10
#define MAX_QUERIES 100
static unsigned int outstanding_queries = 0;
static const char *def_server = "127.0.0.1";
struct query_trans {
int id;
};
static void
{
if (*socketmgrp != NULL)
}
static isc_result_t
{
if (result != ISC_R_SUCCESS)
goto fail;
if (result != ISC_R_SUCCESS)
goto fail;
if (result != ISC_R_SUCCESS)
goto fail;
if (result != ISC_R_SUCCESS)
goto fail;
if (result != ISC_R_SUCCESS)
goto fail;
return (ISC_R_SUCCESS);
fail:
return (result);
}
static isc_result_t
isc_region_t r;
char t[4096];
isc_buffer_init(&target, t, sizeof(t));
return (ISC_R_SUCCESS);
&target);
if (result != ISC_R_SUCCESS)
return (result);
isc_buffer_usedregion(&target, &r);
return (ISC_R_SUCCESS);
}
static void
REQUIRE(outstanding_queries > 0);
}
}
#if 0 /* for cancel test */
if (result == ISC_R_SUCCESS) {
static int count = 0;
if ((++count) % 10 == 0)
}
#endif
}
static isc_result_t
isc_buffer_t b;
char *cp;
/* Construct qname */
return (ISC_R_NOMORE);
/* zap NL if any */
*cp = '\0';
isc_buffer_add(&b, namelen);
if (result != ISC_R_SUCCESS)
goto cleanup;
/* Start resolution */
if (result != ISC_R_SUCCESS)
goto cleanup;
return (ISC_R_SUCCESS);
return (result);
}
static void
usage() {
"input_file\n");
exit(1);
}
int
int ch;
int nservers = 0;
const char *serveraddr[MAX_SERVERS];
int i;
switch (ch) {
case 't':
if (result != ISC_R_SUCCESS) {
"invalid RRtype: %s\n", optarg);
exit(1);
}
break;
case 's':
if (nservers == MAX_SERVERS) {
"too many servers (up to %d)\n",
exit(1);
}
break;
default:
usage();
}
}
if (argc < 1)
usage();
if (nservers == 0) {
nservers = 1;
serveraddr[0] = def_server;
}
for (i = 0; i < MAX_QUERIES; i++) {
query_array[i].id = i;
}
result = dns_lib_init();
if (result != ISC_R_SUCCESS) {
exit(1);
}
&timermgr);
if (result != ISC_R_SUCCESS) {
exit(1);
}
if (result != ISC_R_SUCCESS) {
exit(1);
}
/* Set nameservers */
for (i = 0; i < nservers; i++) {
serveraddr[i]);
exit(1);
}
}
&servers);
if (result != ISC_R_SUCCESS) {
exit(1);
}
/* Create the main task */
query_task = NULL;
if (result != ISC_R_SUCCESS) {
exit(1);
}
/* Open input file */
exit(1);
}
/* Dispatch initial queries */
for (i = 0; i < MAX_QUERIES; i++) {
if (result == ISC_R_NOMORE)
break;
}
/* Start event loop */
/* Sanity check */
for (i = 0; i < MAX_QUERIES; i++)
/* Cleanup */
exit(0);
}