File: zoomtst11.c

package info (click to toggle)
yaz 4.2.30-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 15,120 kB
  • ctags: 13,367
  • sloc: xml: 119,746; ansic: 66,073; sh: 11,795; tcl: 2,125; makefile: 1,308; yacc: 371
file content (113 lines) | stat: -rw-r--r-- 2,842 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* This file is part of the YAZ toolkit.
 * Copyright (C) 1995-2012 Index Data
 * See the file LICENSE for details.
 */

#include <stdio.h>
#include <stdlib.h>

#include <yaz/zoom.h>

void probe_package(ZOOM_connection z)
{
    int i;
    for (i = 1; i<10; i++)
    {
        ZOOM_package pkg = ZOOM_connection_package(z, 0);
        ZOOM_package_option_set(pkg, "action", "recordInsert");
        ZOOM_package_option_set(pkg, "record", "1234");
        ZOOM_package_send(pkg, "update");
    }
}

void probe_search(ZOOM_connection z, int start, int error)
{
    char pqf_str[100];
    ZOOM_resultset set;

    /* provoke error with yaz-ztest */
    if (error)
        ZOOM_connection_option_set(z, "databaseName", "x");

    sprintf(pqf_str, "@attr 1=%d water", start);
    printf("sending search %s\n", pqf_str);
    set = ZOOM_connection_search_pqf (z, pqf_str);
    ZOOM_resultset_destroy(set);

    /* restore database */
    if (error)
        ZOOM_connection_option_set(z, "databaseName", "Default");
}

int main(int argc, char **argv)
{
    ZOOM_connection z;
    int error;
    int use = 0;
    const char *errmsg, *addinfo, *diagset;

    if (argc < 2)
    {
        fprintf (stderr, "usage:\n%s target\n", *argv);
        fprintf (stderr,
                 "Verify: asynchronous single-target client\n");
        exit (1);
    }

    /* create connection (don't connect yet) */
    z = ZOOM_connection_create(0);

    /* option: set sru/get operation (only applicable if http: is used) */
    ZOOM_connection_option_set (z, "sru", "post");

    /* option: set async operation */
    ZOOM_connection_option_set (z, "async", "1");

    /* connect to target and initialize */
    ZOOM_connection_connect (z, argv[1], 0);

    probe_search(z, use, 1);

    /* block here: only one connection */
    while (ZOOM_event (1, &z))
    {
        int ev = ZOOM_connection_last_event(z);
        int idle = ZOOM_connection_is_idle(z);

        /* see if any error occurred */
        if ((error = ZOOM_connection_error_x(z, &errmsg, &addinfo, &diagset)))
        {
            fprintf (stderr, "Error: %s: %s (%d) %s\n", diagset, errmsg, error,
                     addinfo);

        }
        if (ev == ZOOM_EVENT_RECV_SEARCH)
        {
            if (error == 0)
                printf ("Search OK\n");
            printf("idle=%d\n", idle);
        }
        if (idle)
        {
            ZOOM_connection_connect(z, 0, 0); /* allow reconnect */
            
            if (++use <= 10)
            {
                probe_search(z, use, use&1);
            }
            printf("Press enter\n");
            getchar();
        }
    }
    ZOOM_connection_destroy (z);
    exit (0);
}
/*
 * Local variables:
 * c-basic-offset: 4
 * c-file-style: "Stroustrup"
 * indent-tabs-mode: nil
 * End:
 * vim: shiftwidth=4 tabstop=8 expandtab
 */