2 * $Id: zoomtst3.c,v 1.1 2001-10-23 21:00:20 adam Exp $
4 * Asynchronous multi-target client doing search and piggyback retrieval
10 #include <yaz/xmalloc.h>
14 int main(int argc, char **argv)
18 Z3950_connection z[500]; /* allow at most 500 connections */
19 Z3950_resultset r[500]; /* and result sets .. */
20 Z3950_options o = Z3950_options_create ();
24 fprintf (stderr, "usage:\n%s target1 target2 ... targetN query\n",
32 Z3950_options_set (o, "async", "1");
34 /* get first 10 records of result set (using piggyback) */
35 Z3950_options_set (o, "count", "10");
37 /* preferred record syntax */
38 Z3950_options_set (o, "preferredRecordSyntax", "usmarc");
39 Z3950_options_set (o, "elementSetName", "F");
42 for (i = 0; i<no; i++)
44 /* create connection - pass options (they are the same for all) */
45 z[i] = Z3950_connection_create (o);
47 /* connect and init */
48 Z3950_connection_connect (z[i], argv[1+i], 0);
51 for (i = 0; i<no; i++)
52 r[i] = Z3950_connection_search_pqf (z[i], argv[argc-1]);
54 /* network I/O. pass number of connections and array of connections */
55 while (Z3950_event (no, z))
58 /* no more to be done. Inspect results */
59 for (i = 0; i<no; i++)
62 const char *errmsg, *addinfo;
63 /* display errors if any */
64 if ((error = Z3950_connection_error(z[i], &errmsg, &addinfo)))
65 fprintf (stderr, "%s error: %s (%d) %s\n", argv[i+1], errmsg,
69 /* OK, no major errors. Look at the result count */
71 printf ("%s: %d hits\n", argv[i+1], Z3950_resultset_size(r[i]));
72 /* go through all records at target */
73 for (pos = 0; pos < 10; pos++)
75 int len; /* length of buffer rec */
77 Z3950_resultset_get (r[i], pos, "render", &len);
78 /* if rec is non-null, we got a record for display */
81 printf ("%d\n", pos+1);
83 fwrite (rec, 1, len, stdout);
89 /* destroy and exit */
90 for (i = 0; i<no; i++)
92 Z3950_resultset_destroy (r[i]);
93 Z3950_connection_destroy (z[i]);
95 Z3950_options_destroy(o);