Annotation of libaitrpc/example/tcli2.c, revision 1.1.2.1
1.1.2.1 ! misho 1: #include <stdio.h>
! 2: #include <sys/time.h>
! 3: #include <pthread.h>
! 4: #include <aitrpc.h>
! 5: #include "rc.h"
! 6:
! 7:
! 8: int main(int argc, char **argv)
! 9: {
! 10: rpc_cli_t *cli = NULL, *cli2 = NULL;
! 11: int c, i, ret;
! 12: ait_val_t tval, *v = NULL;
! 13: array_t *valz, *arr;
! 14: char *mem, *blob43 = e_malloc(512);
! 15: struct timeval after, before;
! 16:
! 17: // printf("MM model=%d\n", elwix_mm_inuse());
! 18: // getchar();
! 19:
! 20: cli = rpc_cli_openClient2(2, 1024 * 10, NULL, "ff:ff:ff:ff:ff:ff");
! 21: if (!cli) {
! 22: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
! 23: e_free(blob43);
! 24: return 1;
! 25: }
! 26:
! 27: #if 0
! 28: printf("\n\n1 pass>>> RPC ping\n\n");
! 29: for (i = 0; i < 1000; i++) {
! 30: gettimeofday(&before, NULL);
! 31: if ((ret = rpc_cli_ping(cli)) == -1) {
! 32: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
! 33: rpc_cli_closeBLOBClient(&cli2);
! 34: rpc_cli_closeClient(&cli);
! 35: e_free(blob43);
! 36: return 127;
! 37: }
! 38: gettimeofday(&after, NULL);
! 39: printf("RPC ping seq[0x%04x] #%d --- %f\n", ret, i,
! 40: (after.tv_sec - before.tv_sec) + (after.tv_usec - before.tv_usec) / 1.e6);
! 41: }
! 42: //#if 0
! 43: printf("\n\n2 pass>>> RPC ping without reply!!!\n\n");
! 44: for (i = 0; i < 10; i++) {
! 45: gettimeofday(&before, NULL);
! 46: if (rpc_cli_execCall(cli, RPC_NOREPLY, CALL_SRVPING, NULL, &arr)) {
! 47: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
! 48: rpc_cli_closeBLOBClient(&cli2);
! 49: rpc_cli_closeClient(&cli);
! 50: e_free(blob43);
! 51: return 127;
! 52: }
! 53: gettimeofday(&after, NULL);
! 54: rpc_cli_freeCall(&arr);
! 55: printf("RPC ping #%d --- %f\n", i, (after.tv_sec - before.tv_sec) +
! 56: (after.tv_usec - before.tv_usec) / 1.e6);
! 57: }
! 58: #if 0
! 59: printf("\n\n3 pass>>> RPC ping\n\n");
! 60: for (i = 0; i < 10000; i++) {
! 61: gettimeofday(&before, NULL);
! 62: if ((ret = rpc_cli_ping(cli)) == -1) {
! 63: printf("error %d:: errno=%d %s\n", i, rpc_GetErrno(), rpc_GetError());
! 64: rpc_cli_closeBLOBClient(&cli2);
! 65: rpc_cli_closeClient(&cli);
! 66: e_free(blob43);
! 67: return 127;
! 68: }
! 69: gettimeofday(&after, NULL);
! 70: printf("RPC ping seq[0x%04x] #%d --- %f\n", ret, i,
! 71: (after.tv_sec - before.tv_sec) + (after.tv_usec - before.tv_usec) / 1.e6);
! 72: }
! 73: #endif
! 74: //#endif
! 75:
! 76: memset(blob43, 0, 512);
! 77: strlcpy(blob43, "aaaaaaaaaaaaaaa cddddddddddddddd zzzzzzzzzzzzzzzzzzzzz !!!!\n\n\n675675676...\n", 512);
! 78:
! 79: valz = ait_allocVars(3);
! 80: v = array(valz, 0, ait_val_t*);
! 81: AIT_SET_I32(v, 12345678);
! 82: v = array(valz, 1, ait_val_t*);
! 83: AIT_SET_STR(v, "gniah_blah SHMINK!");
! 84: v = array(valz, 2, ait_val_t*);
! 85: AIT_NEW_BLOB(v, 512);
! 86: if (rpc_cli_sendBLOB(cli2, v, blob43, 0) == -1) {
! 87: printf("!!!!! blob error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
! 88: ait_freeVars(&valz);
! 89: rpc_cli_closeBLOBClient(&cli2);
! 90: rpc_cli_closeClient(&cli);
! 91: e_free(blob43);
! 92: return 2;
! 93: } else
! 94: printf("Get BLOB = %x\n", AIT_GET_BLOB(v));
! 95:
! 96: /* test case for unknown blob ...
! 97: AIT_SET_BLOB(&tval, 0x554C1BC7, BUFSIZ);
! 98: printf("test not found blob=%d\n", rpc_cli_getBLOB(cli2, &tval, (void**) &mem));
! 99: if (mem)
! 100: e_free(mem);
! 101: */
! 102:
! 103: // for (i = 0; i < 1000000; i++)
! 104: if ((ret = rpc_cli_execCall(cli, RPC_REPLY, RC_BBB, valz, &arr)) < 0) {
! 105: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
! 106: ait_freeVars(&valz);
! 107: rpc_cli_closeBLOBClient(&cli2);
! 108: rpc_cli_closeClient(&cli);
! 109: e_free(blob43);
! 110: return 2;
! 111: } else {
! 112: printf("ret=%d\n", ret);
! 113: if (arr) {
! 114: v = array(arr, 0, ait_val_t*);
! 115: printf("ret_val0:: %p %s len=%d type=%d\n",
! 116: v, AIT_GET_BUF(v), AIT_LEN(v), AIT_TYPE(v));
! 117: v = array(arr, 1, ait_val_t*);
! 118: printf("ret_val1:: %d len=%d type=%d\n",
! 119: AIT_GET_I8(v), AIT_LEN(v), AIT_TYPE(v));
! 120: v = array(arr, 2, ait_val_t*);
! 121: printf("ret_val2:: is_empty? %d %s len=%d type=%d\n",
! 122: AIT_ISEMPTY(v), AIT_GET_STR(v), AIT_LEN(v), AIT_TYPE(v));
! 123: //#if 0
! 124: v = array(arr, 3, ait_val_t*);
! 125: printf("ret_val3:: %X %d\n", AIT_GET_BLOB(v), AIT_LEN(v));
! 126: printf("test found blob=%d\n", rpc_cli_getBLOB(cli2, v, (void**) &mem));
! 127: // printf("+++++++++ test found blob=%d\n", rpc_cli_recvBLOB(cli2, v, (void**) &mem));
! 128: if (mem) {
! 129: printf("+++++++ BLOB=%s", mem);
! 130: e_free(mem);
! 131: }
! 132: //#endif
! 133: rpc_cli_freeCall(&arr);
! 134: }
! 135: }
! 136: ait_freeVars(&valz);
! 137: e_free(blob43);
! 138:
! 139: if (rpc_cli_execCall(cli, RPC_REPLY, RC_aaa, NULL, &arr) < 0) {
! 140: printf("error:: \"aaa\" errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
! 141: return 3;
! 142: }
! 143: printf("return=%d aaa arr=%p\n", arr ? array_Size(arr) : 42424242, arr);
! 144:
! 145: if (rpc_cli_execCall(cli, RPC_REPLY, RC_big, NULL, &arr) < 0) {
! 146: printf("error:: \"big\" errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
! 147: } else
! 148: printf("return=%d big arr=%p\n", arr ? array_Size(arr) : 42424242, arr);
! 149: ait_freeVars(&arr);
! 150:
! 151:
! 152: valz = ait_allocVars(1);
! 153: v = array(valz, 0, ait_val_t*);
! 154: AIT_SET_DATA(v, "1234567890", 11);
! 155: array_Set(valz, 0, v);
! 156: if (rpc_cli_execCall(cli, RPC_NOREPLY, RC_xxx, valz, &arr) < 0) {
! 157: printf("0) error:: \"xxx\" errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
! 158: ait_freeVars(&valz);
! 159: if (arr)
! 160: rpc_cli_freeCall(&arr);
! 161: rpc_cli_closeBLOBClient(&cli2);
! 162: rpc_cli_closeClient(&cli);
! 163: return 3;
! 164: }
! 165: printf("0) return=%d xxx arr=%p\n", arr ? array_Size(arr) : 42424242, arr);
! 166: ait_freeVars(&valz);
! 167: if (arr) {
! 168: printf("...REPLY --- ");
! 169: v = array(arr, 0, ait_val_t*);
! 170: printf("ret_val0:: %p %s len=%d type=%d\n",
! 171: v, AIT_GET_BUF(v), AIT_LEN(v), AIT_TYPE(v));
! 172: rpc_cli_freeCall(&arr);
! 173: }
! 174:
! 175: valz = ait_allocVars(1);
! 176: v = array(valz, 0, ait_val_t*);
! 177: AIT_SET_DATA(v, "0987654321", 11);
! 178: array_Set(valz, 0, v);
! 179: if (rpc_cli_execCall(cli, RPC_REPLY, RC_xxx, valz, &arr) < 0) {
! 180: printf("1) error:: \"xxx\" errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
! 181: ait_freeVars(&valz);
! 182: if (arr)
! 183: rpc_cli_freeCall(&arr);
! 184: rpc_cli_closeBLOBClient(&cli2);
! 185: rpc_cli_closeClient(&cli);
! 186: return 3;
! 187: }
! 188: printf("1) return=%d xxx arr=%p\n", arr ? array_Size(arr) : 42424242, arr);
! 189: ait_freeVars(&valz);
! 190: if (arr) {
! 191: printf("@REPLY --- ");
! 192: v = array(arr, 0, ait_val_t*);
! 193: printf("ret_val0:: %p %s len=%d type=%d\n",
! 194: v, AIT_GET_BUF(v), AIT_LEN(v), AIT_TYPE(v));
! 195: rpc_cli_freeCall(&arr);
! 196: }
! 197:
! 198:
! 199: if (rpc_cli_execCall(cli, RPC_REPLY, CALL_SRVCLIENTS, NULL, &arr) < 0) {
! 200: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
! 201: rpc_cli_closeBLOBClient(&cli2);
! 202: rpc_cli_closeClient(&cli);
! 203: return 4;
! 204: }
! 205: printf("return=%d registeredClient\n", (arr ? array_Size(arr) : 0));
! 206: for (i = 0; i < (arr ? array_Size(arr) : 0); i++)
! 207: printf("registeredClient(%d)=%s\n", i, AIT_GET_STR(array(arr, i, ait_val_t*)));
! 208: rpc_cli_freeCall(&arr);
! 209:
! 210: if (rpc_cli_execCall(cli, RPC_REPLY, CALL_BLOBCLIENTS, NULL, &arr) < 0) {
! 211: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
! 212: rpc_cli_closeBLOBClient(&cli2);
! 213: rpc_cli_closeClient(&cli);
! 214: return 4;
! 215: }
! 216: printf("return=%d registeredBLOBClient\n", (arr ? array_Size(arr) : 0));
! 217: for (i = 0; i < (arr ? array_Size(arr) : 0); i++)
! 218: printf("registeredBLOBClient(%d)=%s\n", i, AIT_GET_STR(array(arr, i, ait_val_t*)));
! 219: rpc_cli_freeCall(&arr);
! 220:
! 221: if (rpc_cli_execCall(cli, RPC_REPLY, CALL_BLOBVARS, NULL, &arr) < 0) {
! 222: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
! 223: rpc_cli_closeBLOBClient(&cli2);
! 224: rpc_cli_closeClient(&cli);
! 225: return 5;
! 226: }
! 227: for (i = 0; i < (arr ? array_Size(arr) : 0); i++)
! 228: printf("registeredBLOBVars(%d)=%s\n", i, AIT_GET_STR(array(arr, i, ait_val_t*)));
! 229: rpc_cli_freeCall(&arr);
! 230:
! 231: if (rpc_cli_execCall(cli, RPC_REPLY, CALL_SRVCALLS, NULL, &arr) < 0) {
! 232: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
! 233: rpc_cli_closeBLOBClient(&cli2);
! 234: rpc_cli_closeClient(&cli);
! 235: return 5;
! 236: }
! 237: for (i = 0; i < (arr ? array_Size(arr) : 0); i++)
! 238: printf("registeredCall(%d)=%s\n", i, AIT_GET_STR(array(arr, i, ait_val_t*)));
! 239: rpc_cli_freeCall(&arr);
! 240:
! 241: if (rpc_cli_execCall(cli, RPC_REPLY, CALL_SRVSESSIONS, NULL, &arr) < 0) {
! 242: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
! 243: rpc_cli_closeBLOBClient(&cli2);
! 244: rpc_cli_closeClient(&cli);
! 245: return 6;
! 246: }
! 247: printf("c=%d v=%p\n", array_Size(arr), arr);
! 248: printf("session(%d:%d) clients=%d\n", (uint8_t) AIT_GET_U8(array(arr, 0, ait_val_t*)),
! 249: AIT_GET_U8(array(arr, 1, ait_val_t*)), AIT_GET_I32(array(arr, 2, ait_val_t*)));
! 250: rpc_cli_freeCall(&arr);
! 251: #endif
! 252:
! 253: printf("shutdown rpc server? (y/n): ");
! 254: if (getchar() == 'y')
! 255: rpc_cli_execCall(cli, RPC_NOREPLY, CALL_SRVSHUTDOWN, NULL, NULL);
! 256:
! 257: rpc_cli_closeClient2(&cli);
! 258: return 0;
! 259: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>