2 * $Id: zoomtst3.c,v 1.2 2001-10-24 12:24:43 adam Exp $
4 * Asynchronous multi-target client doing search and piggyback retrieval
11 #include <yaz/xmalloc.h>
15 int main(int argc, char **argv)
19 Z3950_connection z[500]; /* allow at most 500 connections */
20 Z3950_resultset r[500]; /* and result sets .. */
21 Z3950_options o = Z3950_options_create ();
25 fprintf (stderr, "usage:\n%s target1 target2 ... targetN query\n",
33 Z3950_options_set (o, "async", "1");
35 /* get first 10 records of result set (using piggyback) */
36 Z3950_options_set (o, "count", "10");
38 /* preferred record syntax */
39 Z3950_options_set (o, "preferredRecordSyntax", "usmarc");
40 Z3950_options_set (o, "elementSetName", "F");
43 for (i = 0; i<no; i++)
45 /* create connection - pass options (they are the same for all) */
46 z[i] = Z3950_connection_create (o);
48 /* connect and init */
49 Z3950_connection_connect (z[i], argv[1+i], 0);
52 for (i = 0; i<no; i++)
53 r[i] = Z3950_connection_search_pqf (z[i], argv[argc-1]);
55 /* network I/O. pass number of connections and array of connections */
56 while (Z3950_event (no, z))
59 /* no more to be done. Inspect results */
60 for (i = 0; i<no; i++)
63 const char *errmsg, *addinfo;
64 /* display errors if any */
65 if ((error = Z3950_connection_error(z[i], &errmsg, &addinfo)))
66 fprintf (stderr, "%s error: %s (%d) %s\n", argv[i+1], errmsg,
70 /* OK, no major errors. Look at the result count */
72 printf ("%s: %d hits\n", argv[i+1], Z3950_resultset_size(r[i]));
73 /* go through all records at target */
74 for (pos = 0; pos < 10; pos++)
76 int len; /* length of buffer rec */
78 Z3950_resultset_get (r[i], pos, "render", &len);
79 /* if rec is non-null, we got a record for display */
82 printf ("%d\n", pos+1);
84 fwrite (rec, 1, len, stdout);
90 /* destroy and exit */
91 for (i = 0; i<no; i++)
93 Z3950_resultset_destroy (r[i]);
94 Z3950_connection_destroy (z[i]);
96 Z3950_options_destroy(o);