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