File:  [ELWIX - Embedded LightWeight unIX -] / libaitrpc / example / tsrv.c
Revision 1.2.4.7: download - view: text, annotated - select for diffs - revision graph
Fri Aug 19 12:51:50 2011 UTC (12 years, 10 months ago) by misho
Branches: rpc1_2
Diff to: branchpoint 1.2: preferred, unified
remove socktype
at this moment support for dgram type of sockets is meaningless

    1: #include <stdio.h>
    2: #include <pthread.h>
    3: #include <aitrpc.h>
    4: 
    5: 
    6: 
    7: int aaa(rpc_func_t *f, int in, rpc_val_t *iv)
    8: {
    9: 	rpc_blob_t *b;
   10: 
   11: 	RPC_CALLBACK_CHECK_INPUT(f);
   12: 
   13: 	printf("%s(%d): Piuk! %s\n", __func__, __LINE__, f->func_name);
   14: 
   15: 	/*
   16: 	b = rpc_srv_registerBLOB(f->func_parent, BUFSIZ);
   17: 	if (!b)
   18: 		return -1;
   19: 	if (rpc_srv_blobMap(f->func_parent, b) == -1) {
   20: 		rpc_srv_blobFree(f->func_parent, b);
   21: 		return -1;
   22: 	}
   23: 
   24: 	memset(b->blob_data, 0, b->blob_len);
   25: 	strcpy(b->blob_data, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAa dsfsfsfnskjfnk\n");
   26: 
   27: 	rpc_srv_blobUnmap(b);
   28: 	*/
   29: 	return 0;
   30: }
   31: 
   32: int BBB(rpc_func_t *f, int in, rpc_val_t *iv)
   33: {
   34: 	rpc_val_t *v;
   35: 	rpc_blob_t *b;
   36: 
   37: 	RPC_CALLBACK_CHECK_INPUT(f);
   38: 
   39: 	printf("%s(%d): Piuk! %s  %d %s %X\n", __func__, __LINE__, f->func_name, 
   40: 			RPC_GET_I32(&iv[0]), RPC_GET_STR(&iv[1]), RPC_GET_BLOB(&iv[2]));
   41: 
   42: 	// input blob object
   43: 	if (!(b = rpc_srv_getBLOB(f->func_parent, RPC_GET_BLOB(&iv[2]))))
   44: 		return -1;
   45: 	if (rpc_srv_blobMap(f->func_parent, b) == -1) {
   46: 		rpc_srv_blobFree(f->func_parent, b);
   47: 		return -1;
   48: 	}
   49: 	printf("VAR=%X(%d):: %s\n", b->blob_var, b->blob_len, b->blob_data);
   50: 	rpc_srv_unregisterBLOB(f->func_parent, RPC_GET_BLOB(&iv[2]));
   51: 
   52: 
   53: 	rpc_srv_allocVars(f, 4);
   54: 	rpc_srv_getVars(f, &v);
   55: 	RPC_SET_BUF(&v[0], "00!oo", 6);
   56: 	RPC_SET_I8(&v[1], 65);
   57: 	RPC_SET_STR(&v[2], "Oho boho i cheburashka");
   58: 
   59: 	// return blob object
   60: 	b = rpc_srv_registerBLOB(f->func_parent, 128);
   61: 	if (!b)
   62: 		return -1;
   63: 	else
   64: 		RPC_SET_BLOB2(&v[3], b);
   65: 
   66: 	if (rpc_srv_blobMap(f->func_parent, b) == -1) {
   67: 		rpc_srv_blobFree(f->func_parent, b);
   68: 		return -1;
   69: 	}
   70: 
   71: 	printf("data=%p blen=%d\n", b->blob_data, b->blob_len);
   72: 	memset(b->blob_data, 0, b->blob_len);
   73: 	strcpy(b->blob_data, "Hello Worldzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz mzdnfdskf\naddfs\n");
   74: 
   75: 	rpc_srv_blobUnmap(b);
   76: 	return 33;
   77: }
   78: 
   79: int main()
   80: {
   81: 	rpc_srv_t *srv;
   82: 	rpc_func_t *f;
   83: 	pthread_t tid[2];
   84: 	int ret;
   85: 
   86: 	srv = rpc_srv_initServer(100, 2, 1, AF_INET, "0.0.0.0", 11111);
   87: //	srv = rpc_srv_initServer(100, 2, 1, AF_LOCAL, "0.0.0.0", 11111);
   88: 	if (!srv) {
   89: 		printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
   90: 		return 1;
   91: 	}
   92: 
   93: 	if (rpc_srv_initBLOBServer(srv, 0, "/tmp")) {
   94: 		printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
   95: 		return 1;
   96: 	}
   97: 
   98: 	/* dump register functions
   99: 	for (f = srv->srv_funcs; f; f = f->func_next)
  100: 		printf("func::name=%s args=%d\n", f->func_name, f->func_args);
  101: 		*/
  102: 
  103: 	if (!fork()) {
  104: 		setsid();
  105: 
  106: 		rpc_srv_registerCall(srv, NULL, "aaa", 0);
  107: 		rpc_srv_registerCall(srv, NULL, "BBB", 4);
  108: 		rpc_srv_registerCall(srv, NULL, "dummy", 1);
  109: 		rpc_srv_registerCall(srv, NULL, "xYz", 2);
  110: 
  111: 		rpc_srv_unregisterCall(srv, NULL, "dummy");
  112: 
  113: 		pthread_create(&tid[1], NULL, (void*(*)(void*)) rpc_srv_execBLOBServer, srv);
  114: 		rpc_srv_execServer(srv);
  115: 	}
  116: 
  117: 	rpc_srv_endBLOBServer(srv);
  118: 	rpc_srv_endServer(srv);
  119: 	return 0;
  120: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>