1 /* $Id: zoomtst7.c,v 1.16 2007-01-03 08:42:17 adam Exp $ */
4 \brief Mix of operations
11 #include <yaz/xmalloc.h>
16 int main(int argc, char **argv)
21 ZOOM_resultset r[10]; /* and result sets .. */
25 o = ZOOM_options_create ();
27 z = ZOOM_connection_new ("localhost", 9999);
28 if (ZOOM_connection_error (z, 0, 0))
30 printf ("error - couldn't connect?\n");
34 ZOOM_connection_destroy (z);
36 for (block = 0; block < 3; block++)
41 printf ("blocking - not calling ZOOM_events\n");
44 printf ("blocking - calling ZOOM_events\n");
47 printf ("non-blocking - calling ZOOM_events\n");
51 ZOOM_options_set (o, "async", "1");
52 for (i = 0; i<10; i++)
56 printf ("session %2d", i);
57 sprintf (host, "localhost:9999/%d", i);
58 z = ZOOM_connection_create (o);
59 ZOOM_connection_connect (z, host, 0);
61 for (j = 0; j < 10; j++)
65 ZOOM_query s = ZOOM_query_create ();
67 sprintf (query, "i%dr%d", i, j);
69 if (ZOOM_query_prefix (s, query))
71 printf ("bad PQF: %s\n", query);
74 ZOOM_options_set (o, "start", "0");
75 ZOOM_options_set (o, "count", "0");
77 r[j] = ZOOM_connection_search (z, s); /* non-piggy */
79 ZOOM_resultset_records (r[j], recs, 0, 2); /* first two */
81 ZOOM_resultset_records (r[j], recs, 1, 2); /* third */
83 ZOOM_resultset_records (r[j], recs, 0, 0); /* ignored */
85 if (ZOOM_resultset_size (r[j]) > 2)
89 fprintf (stderr, "\nrecord missing\n");
94 ZOOM_query_destroy (s);
98 while (ZOOM_event (1, &z))
101 for (j = 0; j<i; j++)
102 ZOOM_resultset_destroy (r[j]);
103 ZOOM_connection_destroy (z);
105 ZOOM_resultset_destroy (r[j]);
106 printf ("10 searches, 20 presents done\n");
110 for (i = 0; i<1; i++)
112 ZOOM_query q = ZOOM_query_create ();
115 printf ("session %2d", i+10);
116 sprintf (host, "localhost:9999/%d", i);
117 z = ZOOM_connection_create (o);
118 ZOOM_connection_connect (z, host, 0);
120 for (j = 0; j < 10; j++)
124 sprintf (query, "i%dr%d", i, j);
126 ZOOM_options_set (o, "count", "0");
128 r[j] = ZOOM_connection_search_pqf (z, query);
132 while (ZOOM_event (1, &z))
136 ZOOM_connection_destroy (z);
138 for (j = 0; j < 10; j++)
140 ZOOM_resultset_records (r[j], 0, 0, 1);
142 for (j = 0; j < 10; j++)
143 ZOOM_resultset_destroy (r[j]);
144 ZOOM_query_destroy (q);
145 printf ("10 searches, 10 ignored presents done\n");
149 for (i = 0; i<1; i++)
152 ZOOM_scanset scan = 0;
154 printf ("session %2d", i);
155 sprintf (host, "localhost:9999/%d", i);
156 z = ZOOM_connection_create (o);
157 ZOOM_connection_connect (z, host, 0);
159 scan = ZOOM_connection_scan (z, "@attr 1=4 a");
161 while (ZOOM_event (1, &z))
163 printf (" scan size = %ld\n", (long) ZOOM_scanset_size(scan));
164 for (j = 0; j<ZOOM_scanset_size (scan); j++)
168 term = ZOOM_scanset_term (scan, j, &occur, &len);
170 printf ("%d %.*s %d\n", j, len, term, occur);
173 ZOOM_scanset_destroy (scan);
174 ZOOM_connection_destroy (z);
178 ZOOM_options_destroy (o);
185 * indent-tabs-mode: nil
187 * vim: shiftwidth=4 tabstop=8 expandtab