2 * $Id: zoomtst3.c,v 1.4 2001-11-18 21:14:23 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 ZOOM_connection z[500]; /* allow at most 500 connections */
20 ZOOM_resultset r[500]; /* and result sets .. */
21 ZOOM_options o = ZOOM_options_create ();
25 fprintf (stderr, "usage:\n%s target1 target2 ... targetN query\n",
33 ZOOM_options_set (o, "async", "1");
35 /* get first 10 records of result set (using piggyback) */
36 ZOOM_options_set (o, "count", "10");
38 /* preferred record syntax */
39 ZOOM_options_set (o, "preferredRecordSyntax", "usmarc");
40 ZOOM_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] = ZOOM_connection_create (o);
48 /* connect and init */
49 ZOOM_connection_connect (z[i], argv[1+i], 0);
52 for (i = 0; i<no; i++)
53 r[i] = ZOOM_connection_search_pqf (z[i], argv[argc-1]);
55 /* network I/O. pass number of connections and array of connections */
56 while (ZOOM_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 = ZOOM_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], ZOOM_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 */
79 ZOOM_resultset_record (r[i], pos), "render", &len);
80 /* if rec is non-null, we got a record for display */
83 printf ("%d\n", pos+1);
85 fwrite (rec, 1, len, stdout);
91 /* destroy and exit */
92 for (i = 0; i<no; i++)
94 ZOOM_resultset_destroy (r[i]);
95 ZOOM_connection_destroy (z[i]);
97 ZOOM_options_destroy(o);