2 * $Id: zoomtst3.c,v 1.6 2002-02-20 14:40:42 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 ((i = ZOOM_event (no, z)))
58 printf ("no = %d event = %d\n", i-1,
59 ZOOM_connection_last_event(z[i-1]));
62 /* no more to be done. Inspect results */
63 for (i = 0; i<no; i++)
66 const char *errmsg, *addinfo;
67 /* display errors if any */
68 if ((error = ZOOM_connection_error(z[i], &errmsg, &addinfo)))
69 fprintf (stderr, "%s error: %s (%d) %s\n", argv[i+1], errmsg,
73 /* OK, no major errors. Look at the result count */
75 printf ("%s: %d hits\n", argv[i+1], ZOOM_resultset_size(r[i]));
76 /* go through all records at target */
77 for (pos = 0; pos < 10; pos++)
79 int len; /* length of buffer rec */
82 ZOOM_resultset_record (r[i], pos), "render", &len);
83 /* if rec is non-null, we got a record for display */
86 printf ("%d\n", pos+1);
88 fwrite (rec, 1, len, stdout);
94 /* destroy and exit */
95 for (i = 0; i<no; i++)
97 ZOOM_resultset_destroy (r[i]);
98 ZOOM_connection_destroy (z[i]);
100 ZOOM_options_destroy(o);