2 * $Id: zoomtst6.c,v 1.7 2001-11-18 21:14:23 adam Exp $
4 * Asynchronous multi-target client doing two searches
9 #include <yaz/xmalloc.h>
13 static void display_records (const char *tname, ZOOM_resultset r)
15 /* OK, no major errors. Look at the result count */
17 printf ("%s: %d hits\n", tname, ZOOM_resultset_size(r));
18 /* go through all records at target */
19 for (pos = 0; pos < 2; pos++)
21 ZOOM_record rec = ZOOM_resultset_record (r, pos);
23 /* get database for record and record itself at pos */
24 const char *db = ZOOM_record_get (rec, "database", 0);
26 const char *render = ZOOM_record_get (rec, "render", &len);
27 /* if rec is non-null, we got a record for display */
30 printf ("%d %s\n", pos+1, (db ? db : "unknown"));
32 fwrite (render, 1, len, stdout);
38 int main(int argc, char **argv)
42 ZOOM_connection z[500]; /* allow at most 500 connections */
43 ZOOM_resultset r1[500]; /* and result sets .. */
44 ZOOM_resultset r2[500]; /* and result sets .. */
48 o = ZOOM_options_create ();
51 fprintf (stderr, "usage:\n%s target1 .. targetN query1 query2\n",
58 ZOOM_options_set (o, "async", "1");
60 /* get 3 (at most) records from beginning */
61 ZOOM_options_set (o, "count", "3");
63 ZOOM_options_set (o, "preferredRecordSyntax", "sutrs");
64 ZOOM_options_set (o, "elementSetName", "B");
67 q = ZOOM_query_create ();
68 if (ZOOM_query_prefix (q, argv[argc-2]))
70 printf ("bad PQF: %s\n", argv[argc-2]);
73 /* connect - and search all */
74 for (i = 0; i<no; i++)
76 z[i] = ZOOM_connection_create (o);
77 ZOOM_connection_connect (z[i], argv[i+1], 0);
78 r1[i] = ZOOM_connection_search (z[i], q);
80 if (ZOOM_query_prefix (q, argv[argc-1]))
82 printf ("bad sort spec: %s\n", argv[argc-1]);
85 /* queue second search */
86 for (i = 0; i<no; i++)
87 r2[i] = ZOOM_connection_search (z[i], q);
91 while (ZOOM_event (no, z))
94 for (i = 0; i<no; i++)
95 ZOOM_resultset_records (r1[i], 0, 4, 1);
98 while (ZOOM_event (no, z))
102 for (i = 0; i<no; i++)
105 const char *errmsg, *addinfo;
106 if ((error = ZOOM_connection_error(z[i], &errmsg, &addinfo)))
107 fprintf (stderr, "%s error: %s (%d) %s\n",
108 ZOOM_connection_option_get(z[i], "host"),
109 errmsg, error, addinfo);
112 display_records (ZOOM_connection_option_get(z[i], "host"), r1[i]);
113 display_records (ZOOM_connection_option_get(z[i], "host"), r2[i]);
116 /* destroy stuff and exit */
117 ZOOM_query_destroy (q);
118 for (i = 0; i<no; i++)
120 ZOOM_connection_destroy (z[i]);
121 ZOOM_resultset_destroy (r1[i]);
122 ZOOM_resultset_destroy (r2[i]);
124 ZOOM_options_destroy(o);