~ubuntu-branches/ubuntu/precise/corosync/precise-proposed

« back to all changes in this revision

Viewing changes to test/testevs.c

  • Committer: Bazaar Package Importer
  • Author(s): Ante Karamatic
  • Date: 2009-08-21 09:29:56 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090821092956-w9qxxxx3zeoh8dem
Tags: 1.0.0-4ubuntu2
* debian/control:
  - 'Ubuntu Developers' instead of 'Ubuntu Core Developers'
    as maintainer
  - Bump debhelper dependecy to 7

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Copyright (c) 2004 MontaVista Software, Inc.
3
 
 * Copyright (c) 2006-2008 Red Hat, Inc.
 
3
 * Copyright (c) 2006-2009 Red Hat, Inc.
4
4
 *
5
5
 * All rights reserved.
6
6
 *
7
7
 * Author: Steven Dake (sdake@redhat.com)
8
8
 *
9
9
 * This software licensed under BSD license, the text of which follows:
10
 
 * 
 
10
 *
11
11
 * Redistribution and use in source and binary forms, with or without
12
12
 * modification, are permitted provided that the following conditions are met:
13
13
 *
32
32
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33
33
 * THE POSSIBILITY OF SUCH DAMAGE.
34
34
 */
 
35
 
 
36
#include <config.h>
 
37
 
35
38
#include <stdio.h>
36
39
#include <stdlib.h>
37
40
#include <sys/socket.h>
38
41
#include <netinet/in.h>
39
42
#include <arpa/inet.h>
40
43
#include <errno.h>
 
44
#include <corosync/corotypes.h>
41
45
#include <corosync/evs.h>
42
46
 
43
 
char *delivery_string;
 
47
static const char *delivery_string;
44
48
 
45
 
int deliveries = 0;
46
 
void evs_deliver_fn (
 
49
static int deliveries = 0;
 
50
static void evs_deliver_fn (
 
51
        hdb_handle_t handle,
47
52
        unsigned int nodeid,
48
 
        void *msg,
49
 
        int msg_len)
 
53
        const void *msg,
 
54
        size_t msg_len)
50
55
{
51
 
        char *buf = msg;
 
56
        const char *buf = msg;
52
57
 
53
 
//      buf += 100000;
54
 
//      printf ("Delivery callback\n");
55
58
        printf ("API '%s' msg '%s'\n", delivery_string, buf);
56
59
        deliveries++;
57
60
}
58
61
 
59
 
void evs_confchg_fn (
60
 
        unsigned int *member_list, int member_list_entries,
61
 
        unsigned int *left_list, int left_list_entries,
62
 
        unsigned int *joined_list, int joined_list_entries)
 
62
static void evs_confchg_fn (
 
63
        hdb_handle_t handle,
 
64
        const unsigned int *member_list, size_t member_list_entries,
 
65
        const unsigned int *left_list, size_t left_list_entries,
 
66
        const unsigned int *joined_list, size_t joined_list_entries,
 
67
        const struct evs_ring_id *ring_id)
63
68
{
64
69
        int i;
65
70
 
79
84
        }
80
85
}
81
86
 
82
 
evs_callbacks_t callbacks = {
 
87
static evs_callbacks_t callbacks = {
83
88
        evs_deliver_fn,
84
89
        evs_confchg_fn
85
90
};
86
91
 
87
 
struct evs_group groups[3] = {
 
92
static struct evs_group groups[3] = {
88
93
        { "key1" },
89
94
        { "key2" },
90
95
        { "key3" }
91
96
};
92
97
 
93
 
char buffer[200000];
 
98
static char buffer[2000];
94
99
struct iovec iov = {
95
100
        .iov_base = buffer,
96
101
        .iov_len = sizeof (buffer)
99
104
int main (void)
100
105
{
101
106
        evs_handle_t handle;
102
 
        evs_error_t result;
 
107
        cs_error_t result;
103
108
        int i = 0;
104
109
        int fd;
105
110
        unsigned int member_list[32];
106
111
        unsigned int local_nodeid;
107
 
        unsigned int member_list_entries = 32;
 
112
        size_t member_list_entries = 32;
108
113
 
109
114
        result = evs_initialize (&handle, &callbacks);
110
 
        if (result != EVS_OK) {
 
115
        if (result != CS_OK) {
111
116
                printf ("Couldn't initialize EVS service %d\n", result);
112
117
                exit (0);
113
118
        }
114
 
        
 
119
 
115
120
        result = evs_membership_get (handle, &local_nodeid,
116
121
                member_list, &member_list_entries);
117
 
        printf ("Current membership from evs_membership_get entries %d\n",
118
 
                member_list_entries);
 
122
        printf ("Current membership from evs_membership_get entries %lu\n",
 
123
                (unsigned long int) member_list_entries);
119
124
        for (i = 0; i < member_list_entries; i++) {
120
125
                printf ("member [%d] is %x\n", i, member_list[i]);
121
126
        }
124
129
        printf ("Init result %d\n", result);
125
130
        result = evs_join (handle, groups, 3);
126
131
        printf ("Join result %d\n", result);
127
 
        result = evs_leave (handle, &groups[0], 1);
128
 
        printf ("Leave result %d\n", result);
129
132
        delivery_string = "evs_mcast_joined";
130
133
 
131
134
        /*
142
145
try_again_one:
143
146
                result = evs_mcast_joined (handle, EVS_TYPE_AGREED,
144
147
                        &iov, 1);
145
 
                if (result == EVS_ERR_TRY_AGAIN) {
146
 
//printf ("try again\n");
 
148
                if (result == CS_ERR_TRY_AGAIN) {
147
149
                        goto try_again_one;
148
150
                }
149
 
                result = evs_dispatch (handle, EVS_DISPATCH_ALL);
 
151
                result = evs_dispatch (handle, CS_DISPATCH_ALL);
150
152
        }
151
153
 
152
154
        do {
153
 
                result = evs_dispatch (handle, EVS_DISPATCH_ALL);
 
155
                result = evs_dispatch (handle, CS_DISPATCH_ALL);
154
156
        } while (deliveries < 20);
155
157
        /*
156
158
         * Demonstrate evs_mcast_joined
161
163
try_again_two:
162
164
                result = evs_mcast_groups (handle, EVS_TYPE_AGREED,
163
165
                         &groups[1], 1, &iov, 1);
164
 
                if (result == EVS_ERR_TRY_AGAIN) {
 
166
                if (result == CS_ERR_TRY_AGAIN) {
165
167
                        goto try_again_two;
166
168
                }
167
 
        
168
 
                result = evs_dispatch (handle, EVS_DISPATCH_ALL);
 
169
 
 
170
                result = evs_dispatch (handle, CS_DISPATCH_ALL);
169
171
        }
170
172
        /*
171
173
         * Flush any pending callbacks
172
174
         */
173
175
        do {
174
 
                result = evs_dispatch (handle, EVS_DISPATCH_ALL);
 
176
                result = evs_dispatch (handle, CS_DISPATCH_ALL);
175
177
        } while (deliveries < 500);
176
178
 
177
179
        evs_fd_get (handle, &fd);
178
 
        
 
180
 
179
181
        evs_finalize (handle);
180
182
 
181
183
        return (0);