1 /* $Id: zoomtst3.c,v 1.11 2006-04-21 10:28:08 adam Exp $ */
4 \brief Asynchronous multi-target client
6 Performs search and piggyback retrieval of records
14 #include <yaz/xmalloc.h>
18 int main(int argc, char **argv)
23 ZOOM_connection z[500]; /* allow at most 500 connections */
24 ZOOM_resultset r[500]; /* and result sets .. */
25 ZOOM_options o = ZOOM_options_create ();
29 fprintf (stderr, "usage:\n%s target1 target2 ... targetN query\n"
30 "%s number target query\n", *argv, *argv);
33 if (argc == 4 && isdigit(argv[1][0]) && !strchr(argv[1],'.'))
43 ZOOM_options_set (o, "async", "1");
45 /* get first 10 records of result set (using piggyback) */
46 ZOOM_options_set (o, "count", "10");
48 /* preferred record syntax */
49 ZOOM_options_set (o, "preferredRecordSyntax", "usmarc");
50 ZOOM_options_set (o, "elementSetName", "F");
53 for (i = 0; i<no; i++)
55 /* create connection - pass options (they are the same for all) */
56 z[i] = ZOOM_connection_create (o);
58 /* connect and init */
60 ZOOM_connection_connect (z[i], argv[2], 0);
62 ZOOM_connection_connect (z[i], argv[1+i], 0);
65 for (i = 0; i<no; i++)
66 r[i] = ZOOM_connection_search_pqf (z[i], argv[argc-1]);
68 /* network I/O. pass number of connections and array of connections */
69 while ((i = ZOOM_event (no, z)))
71 printf ("no = %d event = %d\n", i-1,
72 ZOOM_connection_last_event(z[i-1]));
75 /* no more to be done. Inspect results */
76 for (i = 0; i<no; i++)
79 const char *errmsg, *addinfo;
80 const char *tname = (same_target ? argv[2] : argv[1+i]);
81 /* display errors if any */
82 if ((error = ZOOM_connection_error(z[i], &errmsg, &addinfo)))
83 fprintf (stderr, "%s error: %s (%d) %s\n", tname, errmsg,
87 /* OK, no major errors. Look at the result count */
89 printf ("%s: %ld hits\n", tname, (long) ZOOM_resultset_size(r[i]));
90 /* go through all records at target */
91 for (pos = 0; pos < 10; pos++)
93 int len; /* length of buffer rec */
96 ZOOM_resultset_record (r[i], pos), "render", &len);
97 /* if rec is non-null, we got a record for display */
100 printf ("%d\n", pos+1);
102 fwrite (rec, 1, len, stdout);
108 /* destroy and exit */
109 for (i = 0; i<no; i++)
111 ZOOM_resultset_destroy (r[i]);
112 ZOOM_connection_destroy (z[i]);
114 ZOOM_options_destroy(o);
120 * indent-tabs-mode: nil
122 * vim: shiftwidth=4 tabstop=8 expandtab