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