4
0

test.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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>
  15. #include "saAis.h"
  16. #include "saCkpt.h"
  17. SaVersionT version = { 'B', 1, 1 };
  18. SaCkptCallbacksT callbacks = {
  19. 0,
  20. 0
  21. };
  22. SaCkptCheckpointCreationAttributesT checkpointCreationAttributes = {
  23. SA_CKPT_WR_ALL_REPLICAS,
  24. 100000,
  25. 5000000000LL,
  26. 5,
  27. 20000,
  28. 10
  29. };
  30. SaCkptSectionIdT sectionId = {
  31. 14,
  32. (SaUint8T*)"section ID #1"
  33. };
  34. SaCkptSectionCreationAttributesT sectionCreationAttributes = {
  35. &sectionId,
  36. SA_TIME_END
  37. };
  38. char* getPayload(int psize) {
  39. int i;
  40. char* retVal = new char[psize];
  41. if (retVal == NULL)
  42. {
  43. return NULL;
  44. }
  45. for (i = 0; i < psize; i++)
  46. {
  47. if (i == (psize - 1)) {
  48. *retVal = '\0';
  49. retVal++;
  50. continue;
  51. }
  52. *retVal = 'z';
  53. retVal++;
  54. }
  55. retVal = retVal - psize;
  56. return retVal;
  57. }
  58. SaCkptCheckpointHandleT WriteCheckpointHandle;
  59. static long sendCount = 0;
  60. void process_message()
  61. {
  62. struct timeval tv;
  63. long t1;
  64. long t2;
  65. long told;
  66. SaCkptIOVectorElementT writeElement; // KJS
  67. SaUint32T erroroneousVectorIndex = 0;
  68. SaAisErrorT error;
  69. writeElement.sectionId = sectionId;
  70. writeElement.dataBuffer = getPayload(200);
  71. writeElement.dataSize = 200;
  72. writeElement.dataOffset = 0;
  73. writeElement.readSize = 0;
  74. gettimeofday(&tv, NULL);
  75. t1 = tv.tv_usec;
  76. told = tv.tv_sec;
  77. do {
  78. error = saCkptCheckpointWrite (WriteCheckpointHandle,
  79. &writeElement,
  80. 1,
  81. &erroroneousVectorIndex);
  82. if (error != SA_AIS_OK) {
  83. fprintf(stderr,"saCkptCheckpointWrite result %d (should be 1)\n", error);
  84. }
  85. sendCount++;
  86. fprintf(stderr,"sendCount = %d",(int)sendCount);
  87. } while (error == SA_AIS_ERR_TRY_AGAIN);
  88. gettimeofday(&tv, NULL);
  89. t2 = tv.tv_usec;
  90. fprintf(stderr," ,RTT::%d.%d\n",(long)tv.tv_sec - told, t2-t1);
  91. }
  92. int main () {
  93. SaAisErrorT error;
  94. SaNameT* WriteCheckpointName = (SaNameT*) malloc(sizeof(SaNameT));
  95. char name[10];
  96. SaCkptHandleT ckptHandle;
  97. sprintf(name,"ckpt%d",1);
  98. int namelen = strlen(name) + 1;
  99. memcpy(WriteCheckpointName->value, name, namelen);
  100. WriteCheckpointName->length = namelen;
  101. error = saCkptInitialize (&ckptHandle, &callbacks, &version);
  102. error = saCkptCheckpointOpen (
  103. ckptHandle,
  104. WriteCheckpointName,
  105. &checkpointCreationAttributes,
  106. SA_CKPT_CHECKPOINT_WRITE,
  107. 1000000000, /* 1 Second */
  108. &WriteCheckpointHandle);
  109. if (error != SA_AIS_OK) {
  110. fprintf(stderr,"saCkptCheckpointOpen result %d (should be 1)\n", error);
  111. return error;
  112. }
  113. error = saCkptSectionCreate ( WriteCheckpointHandle,
  114. &sectionCreationAttributes,
  115. "Initial Data #0",
  116. strlen ("Initial Data #0") + 1);
  117. if (error != SA_AIS_OK) {
  118. fprintf(stderr,"saCkptSectionCreate result = %d\n", error);
  119. return error;
  120. }
  121. struct timespec tv;
  122. tv.tv_sec = 0;
  123. tv.tv_nsec = 15000000; //15 milliseconds
  124. while(1) {
  125. process_message();
  126. nanosleep(&tv,NULL);
  127. }
  128. return 1;
  129. }