2 * $Id: zoomtst8.c,v 1.3 2002-05-21 08:36:04 adam Exp $
4 * Asynchronous multi-target client doing scan
11 #include <yaz/xmalloc.h>
14 int main(int argc, char **argv)
18 ZOOM_connection z[500]; /* allow at most 500 connections */
19 ZOOM_scanset s[500]; /* and scan sets .. */
20 ZOOM_options o = ZOOM_options_create ();
24 fprintf (stderr, "usage:\n%s target1 target2 ... targetN scan\n",
32 ZOOM_options_set (o, "async", "1");
35 for (i = 0; i<no; i++)
37 /* create connection - pass options (they are the same for all) */
38 z[i] = ZOOM_connection_create (o);
40 /* connect and init */
41 ZOOM_connection_connect (z[i], argv[1+i], 0);
45 for (i = 0; i<no; i++)
47 /* set number of scan terms to be returned. */
48 ZOOM_connection_option_set (z[i], "number", "7");
49 /* and perform scan */
50 s[i] = ZOOM_connection_scan (z[i], argv[argc-1]);
53 /* network I/O. pass number of connections and array of connections */
54 while (ZOOM_event (no, z))
57 for (i = 0; i<no; i++)
60 const char *errmsg, *addinfo;
61 if ((error = ZOOM_connection_error(z[i], &errmsg, &addinfo)))
62 fprintf (stderr, "%s error: %s (%d) %s\n",
63 ZOOM_connection_option_get(z[i], "host"),
64 errmsg, error, addinfo);
68 printf ("%s\n", ZOOM_connection_option_get(z[i], "host"));
69 for (j = 0; j<ZOOM_scanset_size (s[i]); j++)
73 term = ZOOM_scanset_term (s[i], j, &occur, &len);
75 printf ("%d %.*s %d\n", j, len, term, occur);
80 /* destroy and exit */
81 for (i = 0; i<no; i++)
83 ZOOM_scanset_destroy (s[i]);
84 ZOOM_connection_destroy (z[i]);
86 ZOOM_options_destroy(o);