File: test.cpp

package info (click to toggle)
openais 1.1.4-4.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,404 kB
  • sloc: ansic: 44,955; sh: 3,983; makefile: 372; cpp: 129
file content (156 lines) | stat: -rw-r--r-- 3,998 bytes parent folder | download | duplicates (3)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <time.h>
#include <sys/time.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <sys/un.h>
#include <arpa/inet.h>
#include <vector.h>
#include <iostream>


#include "saAis.h"
#include "saCkpt.h"


SaVersionT version = { 'B', 1, 1 };

SaCkptCallbacksT callbacks = {
    0,
    0
};

SaCkptCheckpointCreationAttributesT checkpointCreationAttributes = {
        SA_CKPT_WR_ALL_REPLICAS,
        100000,
        5000000000LL,
        5,
        20000,
        10
};

SaCkptSectionIdT sectionId = {
        14,
        (SaUint8T*)"section ID #1"
};

SaCkptSectionCreationAttributesT sectionCreationAttributes = {
        &sectionId,
        SA_TIME_END
};

char* getPayload(int psize) {
        int i;
        char* retVal = new char[psize];
        if (retVal == NULL)
        {
                return NULL;
        }
        for (i = 0; i < psize; i++)
        {
                if (i == (psize - 1)) {
                        *retVal = '\0';
                        retVal++;
                        continue;
                }
                *retVal = 'z';
                retVal++;
        }
        retVal = retVal - psize;
        return retVal;
}

SaCkptCheckpointHandleT WriteCheckpointHandle;

static long sendCount = 0;
void process_message()
{
        struct timeval tv;
        long t1;
        long t2;
	long told;
        SaCkptIOVectorElementT writeElement; // KJS

        SaUint32T erroroneousVectorIndex = 0;
        SaAisErrorT error;

        writeElement.sectionId = sectionId;
        writeElement.dataBuffer = getPayload(200);
        writeElement.dataSize = 200;
        writeElement.dataOffset = 0;
        writeElement.readSize = 0;

        gettimeofday(&tv, NULL);
        t1 = tv.tv_usec;
	told = tv.tv_sec;

        do {
                error = saCkptCheckpointWrite (WriteCheckpointHandle,
                                               &writeElement,
                                               1,
                                               &erroroneousVectorIndex);

                if (error != SA_AIS_OK) {
                        fprintf(stderr,"saCkptCheckpointWrite result %d (should be 1)\n", error);
                }
                sendCount++;
                fprintf(stderr,"sendCount = %d",(int)sendCount);
        } while (error == SA_AIS_ERR_TRY_AGAIN);

        gettimeofday(&tv, NULL);
        t2 = tv.tv_usec;
        fprintf(stderr," ,RTT::%d.%d\n",(long)tv.tv_sec - told, t2-t1);
}

int main () {
	SaAisErrorT error;
	SaNameT* WriteCheckpointName = (SaNameT*) malloc(sizeof(SaNameT));
        char name[10];
        SaCkptHandleT ckptHandle;

        sprintf(name,"ckpt%d",1);
        int namelen = strlen(name) + 1;
        memcpy(WriteCheckpointName->value, name, namelen);
        WriteCheckpointName->length = namelen;

	error = saCkptInitialize (&ckptHandle, &callbacks, &version);

        error = saCkptCheckpointOpen (
			ckptHandle,
			WriteCheckpointName,
                        &checkpointCreationAttributes,
                        SA_CKPT_CHECKPOINT_WRITE,
                        1000000000, /* 1 Second */
                        &WriteCheckpointHandle);

        if (error != SA_AIS_OK) {
                fprintf(stderr,"saCkptCheckpointOpen result %d (should be 1)\n", error);
                return error;
        }

        error = saCkptSectionCreate (	WriteCheckpointHandle,
                                        &sectionCreationAttributes,
                                        "Initial Data #0",
                                         strlen ("Initial Data #0") + 1);
        if (error != SA_AIS_OK) {
                fprintf(stderr,"saCkptSectionCreate result = %d\n", error);
                return error;
        }

	struct timespec tv;
	tv.tv_sec = 0;
	tv.tv_nsec = 15000000; //15 milliseconds

	while(1) {
		process_message();
		nanosleep(&tv,NULL);
	}

	return 1;

}