MCPcopy Create free account
hub / github.com/corosync/corosync / main

Function main

test/cpgverify.c:109–184  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107
108static unsigned char buffer[200000];
109int main (int argc, char *argv[])
110{
111 cpg_handle_t handle;
112 cs_error_t result;
113 int i = 0;
114 int j;
115 struct my_msg msg;
116 struct iovec iov[2];
117 const char *options = "i:";
118 int iter = 1000;
119 int opt;
120 int run_forever = 1;
121 uLong chsum;
122 uint32_t nchsum;
123
124 while ((opt = getopt(argc, argv, options)) != -1) {
125 switch (opt) {
126 case 'i':
127 run_forever = 0;
128 iter = atoi(optarg);
129 break;
130 }
131 }
132
133 result = cpg_initialize (&handle, &callbacks);
134 if (result != CS_OK) {
135 printf ("Couldn't initialize CPG service %d\n", result);
136 exit (0);
137 }
138
139 result = cpg_join (handle, &group_name);
140 if (result != CS_OK) {
141 printf ("cpg_join failed with result %d\n", result);
142 exit (1);
143 }
144
145 iov[0].iov_base = (void *)&msg;
146 iov[0].iov_len = sizeof (struct my_msg);
147 iov[1].iov_base = (void *)buffer;
148
149 /*
150 * Demonstrate cpg_mcast_joined
151 */
152 i = 0;
153 do {
154 // coverity[DC.WEAK_CRYPTO:SUPPRESS] rand is not used in a security context
155 msg.msg_size = 100 + rand() % 100000;
156 iov[1].iov_len = msg.msg_size;
157 for (j = 0; j < msg.msg_size; j++) {
158 buffer[j] = j;
159 }
160 sprintf ((char *)buffer,
161 "cpg_mcast_joined: This is message %12d", i);
162
163 chsum = crc32(0L, Z_NULL, 0);
164 chsum = crc32(chsum, buffer, msg.msg_size) & 0xFFFFFFFF;
165 nchsum = htonl((uint32_t)chsum);
166 memcpy(msg.crc32, &nchsum, sizeof(nchsum)) ;

Callers

nothing calls this directly

Calls 5

cpg_initializeFunction · 0.85
cpg_joinFunction · 0.85
cpg_mcast_joinedFunction · 0.85
cpg_dispatchFunction · 0.85
cpg_finalizeFunction · 0.85

Tested by

no test coverage detected