1 /* $Id: zoomtst11.c,v 1.2 2007-03-07 13:12:42 adam Exp $ */
4 \brief Asynchronous single-target which tests event/error handling
12 void probe_package(ZOOM_connection z)
15 for (i = 1; i<10; i++)
17 ZOOM_package pkg = ZOOM_connection_package(z, 0);
18 ZOOM_package_option_set(pkg, "action", "recordInsert");
19 ZOOM_package_option_set(pkg, "record", "1234");
20 ZOOM_package_send(pkg, "update");
24 void probe_search(ZOOM_connection z, int start, int error)
29 /* provoke error with yaz-ztest */
31 ZOOM_connection_option_set(z, "databaseName", "x");
33 sprintf(pqf_str, "@attr 1=%d water", start);
34 printf("sending search %s\n", pqf_str);
35 set = ZOOM_connection_search_pqf (z, pqf_str);
36 ZOOM_resultset_destroy(set);
38 /* restore database */
40 ZOOM_connection_option_set(z, "databaseName", "Default");
43 int main(int argc, char **argv)
48 const char *errmsg, *addinfo, *diagset;
52 fprintf (stderr, "usage:\n%s target\n", *argv);
54 "Verify: asynchronous single-target client\n");
58 /* create connection (don't connect yet) */
59 z = ZOOM_connection_create(0);
61 /* option: set sru/get operation (only applicable if http: is used) */
62 ZOOM_connection_option_set (z, "sru", "post");
64 /* option: set async operation */
65 ZOOM_connection_option_set (z, "async", "1");
67 /* connect to target and initialize */
68 ZOOM_connection_connect (z, argv[1], 0);
70 probe_search(z, use, 1);
72 /* block here: only one connection */
73 while (ZOOM_event (1, &z))
75 int ev = ZOOM_connection_last_event(z);
76 int idle = ZOOM_connection_is_idle(z);
78 /* see if any error occurred */
79 if ((error = ZOOM_connection_error_x(z, &errmsg, &addinfo, &diagset)))
81 fprintf (stderr, "Error: %s: %s (%d) %s\n", diagset, errmsg, error,
85 if (ev == ZOOM_EVENT_RECV_SEARCH)
88 printf ("Search OK\n");
89 printf("idle=%d\n", idle);
93 ZOOM_connection_connect(z, 0, 0); /* allow reconnect */
97 probe_search(z, use, use&1);
99 printf("Press enter\n");
103 ZOOM_connection_destroy (z);
109 * indent-tabs-mode: nil
111 * vim: shiftwidth=4 tabstop=8 expandtab