Fix build error.
[openais.git] / test / test.cpp
blob713ef927e7c00f3a60d634e426fb771eff7bc527
1 #include <time.h>
2 #include <sys/time.h>
3 #include <pthread.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <errno.h>
7 #include <unistd.h>
8 #include <sys/types.h>
9 #include <sys/socket.h>
10 #include <sys/select.h>
11 #include <sys/un.h>
12 #include <arpa/inet.h>
13 #include <vector.h>
14 #include <iostream>
17 #include "saAis.h"
18 #include "saCkpt.h"
21 SaVersionT version = { 'B', 1, 1 };
23 SaCkptCallbacksT callbacks = {
28 SaCkptCheckpointCreationAttributesT checkpointCreationAttributes = {
29 SA_CKPT_WR_ALL_REPLICAS,
30 100000,
31 5000000000LL,
33 20000,
37 SaCkptSectionIdT sectionId = {
38 14,
39 (SaUint8T*)"section ID #1"
42 SaCkptSectionCreationAttributesT sectionCreationAttributes = {
43 &sectionId,
44 SA_TIME_END
47 char* getPayload(int psize) {
48 int i;
49 char* retVal = new char[psize];
50 if (retVal == NULL)
52 return NULL;
54 for (i = 0; i < psize; i++)
56 if (i == (psize - 1)) {
57 *retVal = '\0';
58 retVal++;
59 continue;
61 *retVal = 'z';
62 retVal++;
64 retVal = retVal - psize;
65 return retVal;
68 SaCkptCheckpointHandleT WriteCheckpointHandle;
70 static long sendCount = 0;
71 void process_message()
73 struct timeval tv;
74 long t1;
75 long t2;
76 long told;
77 SaCkptIOVectorElementT writeElement; // KJS
79 SaUint32T erroroneousVectorIndex = 0;
80 SaAisErrorT error;
82 writeElement.sectionId = sectionId;
83 writeElement.dataBuffer = getPayload(200);
84 writeElement.dataSize = 200;
85 writeElement.dataOffset = 0;
86 writeElement.readSize = 0;
88 gettimeofday(&tv, NULL);
89 t1 = tv.tv_usec;
90 told = tv.tv_sec;
92 do {
93 error = saCkptCheckpointWrite (WriteCheckpointHandle,
94 &writeElement,
96 &erroroneousVectorIndex);
98 if (error != SA_AIS_OK) {
99 fprintf(stderr,"saCkptCheckpointWrite result %d (should be 1)\n", error);
101 sendCount++;
102 fprintf(stderr,"sendCount = %d",(int)sendCount);
103 } while (error == SA_AIS_ERR_TRY_AGAIN);
105 gettimeofday(&tv, NULL);
106 t2 = tv.tv_usec;
107 fprintf(stderr," ,RTT::%d.%d\n",(long)tv.tv_sec - told, t2-t1);
110 int main () {
111 SaAisErrorT error;
112 SaNameT* WriteCheckpointName = (SaNameT*) malloc(sizeof(SaNameT));
113 char name[10];
114 SaCkptHandleT ckptHandle;
116 sprintf(name,"ckpt%d",1);
117 int namelen = strlen(name) + 1;
118 memcpy(WriteCheckpointName->value, name, namelen);
119 WriteCheckpointName->length = namelen;
121 error = saCkptInitialize (&ckptHandle, &callbacks, &version);
123 error = saCkptCheckpointOpen (
124 ckptHandle,
125 WriteCheckpointName,
126 &checkpointCreationAttributes,
127 SA_CKPT_CHECKPOINT_WRITE,
128 1000000000, /* 1 Second */
129 &WriteCheckpointHandle);
131 if (error != SA_AIS_OK) {
132 fprintf(stderr,"saCkptCheckpointOpen result %d (should be 1)\n", error);
133 return error;
136 error = saCkptSectionCreate ( WriteCheckpointHandle,
137 &sectionCreationAttributes,
138 "Initial Data #0",
139 strlen ("Initial Data #0") + 1);
140 if (error != SA_AIS_OK) {
141 fprintf(stderr,"saCkptSectionCreate result = %d\n", error);
142 return error;
145 struct timespec tv;
146 tv.tv_sec = 0;
147 tv.tv_nsec = 15000000; //15 milliseconds
149 while(1) {
150 process_message();
151 nanosleep(&tv,NULL);
154 return 1;