test.cpp 3.8 KB

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