f8e31596c3543d6844ed4a41d87729ff9530b365
[yaz-moved-to-github.git] / zoom / zoomtst2.c
1 /* $Id: zoomtst2.c,v 1.8 2006-04-21 10:28:08 adam Exp $  */
2
3 /** \file zoomtst2.c
4     \brief Asynchronous single-target client performing search (no retrieval)
5 */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9
10 #include <yaz/zoom.h>
11
12 int main(int argc, char **argv)
13 {
14     ZOOM_connection z;
15     ZOOM_resultset r;
16     int error;
17     const char *errmsg, *addinfo, *diagset;
18
19     if (argc < 3)
20     {
21         fprintf (stderr, "usage:\n%s target query\n", *argv);
22         fprintf (stderr,
23                  "Verify: asynchronous single-target client\n");
24         exit (1);
25     }
26
27     /* create connection (don't connect yet) */
28     z = ZOOM_connection_create(0);
29
30     /* option: set sru/get operation (only applicable if http: is used) */
31     ZOOM_connection_option_set (z, "sru", "post");
32
33     /* option: set async operation */
34     ZOOM_connection_option_set (z, "async", "1");
35
36     /* connect to target and initialize */
37     ZOOM_connection_connect (z, argv[1], 0);
38
39     /* search using prefix query format */
40     r = ZOOM_connection_search_pqf (z, argv[2]);
41
42     /* block here: only one connection */
43     while (ZOOM_event (1, &z))
44         ;
45
46     /* see if any error occurred */
47     if ((error = ZOOM_connection_error_x(z, &errmsg, &addinfo, &diagset)))
48     {
49         fprintf (stderr, "Error: %s: %s (%d) %s\n", diagset, errmsg, error,
50                          addinfo);
51         exit (2);
52     }
53     else /* OK print hit count */
54         printf ("Result count: %ld\n", (long) ZOOM_resultset_size(r));  
55     ZOOM_resultset_destroy (r);
56     ZOOM_connection_destroy (z);
57     exit (0);
58 }
59 /*
60  * Local variables:
61  * c-basic-offset: 4
62  * indent-tabs-mode: nil
63  * End:
64  * vim: shiftwidth=4 tabstop=8 expandtab
65  */
66