--- libaitrpc/src/srv.c 2011/08/31 17:11:58 1.4.2.4 +++ libaitrpc/src/srv.c 2011/09/03 12:58:49 1.4.2.9 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: srv.c,v 1.4.2.4 2011/08/31 17:11:58 misho Exp $ +* $Id: srv.c,v 1.4.2.9 2011/09/03 12:58:49 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -97,14 +97,14 @@ rpc_srv_dispatchCall(void *arg) break; } if (ret < sizeof(struct tagRPCCall)) { - rpc_SetErr(EMSGSIZE, "Error:: too short RPC packet ...\n"); + rpc_SetErr(ERPCMISMATCH, "Error:: too short RPC packet ...\n"); ret = -4; break; } else rpc = (struct tagRPCCall*) buf; /* check RPC packet session info */ if (memcmp(&rpc->call_session, &s->srv_session, sizeof rpc->call_session)) { - rpc_SetErr(EINVAL, "Error:: get invalid RPC session ...\n"); + rpc_SetErr(ERPCMISMATCH, "Error:: get invalid RPC session ...\n"); ret = -5; goto makeReply; } else @@ -123,18 +123,20 @@ rpc_srv_dispatchCall(void *arg) argc = 0; memcpy(&ses, &rpc->call_session, sizeof ses); if (!(f = rpc_srv_getCall(s, rpc->call_tag, rpc->call_hash))) { - rpc_SetErr(EINVAL, "Error:: call not found into RPC server ...\n"); + rpc_SetErr(EPROGUNAVAIL, "Error:: call not found into RPC server ...\n"); ret = -6; } else if ((ret = rpc_srv_execCall(f, rpc, arr)) == -1) ret = -9; else { - io_arrayDestroy(&arr); + if (arr) + io_arrayDestroy(&arr); argc = rpc_srv_getVars(f, &arr); goto makeReply; /* Call finish OK */ } - io_arrayDestroy(&arr); + if (arr) + io_arrayDestroy(&arr); makeReply: /* Made reply */ @@ -152,15 +154,15 @@ makeReply: if (argc && arr) { /* Go Encapsulate variables ... */ if ((i = io_vals2buffer(buf + Limit, s->srv_netbuf - Limit, arr)) == -1) { - rpc_srv_freeVars(f); + rpc_srv_freeVals(f); argc = 0; ret = -7; - rpc_SetErr(EMSGSIZE, "Error:: in prepare RPC packet values (-7) ...\n"); + rpc_SetErr(EBADRPC, "Error:: in prepare RPC packet values (-7) ...\n"); goto makeReply; } else { Limit += i; - rpc_srv_freeVars(f); + rpc_srv_freeVals(f); } } @@ -171,7 +173,7 @@ makeReply: break; } if (ret != Limit) { - rpc_SetErr(ECANCELED, "Error:: in send RPC request, should be send %d bytes, " + rpc_SetErr(EPROCUNAVAIL, "Error:: in send RPC request, should be send %d bytes, " "really is %d\n", Limit, ret); ret = -9; break; @@ -238,7 +240,7 @@ rpc_srv_dispatchVars(void *arg) break; } if (ret < sizeof(struct tagBLOBHdr)) { - rpc_SetErr(EMSGSIZE, "Error:: too short BLOB packet ...\n"); + rpc_SetErr(ERPCMISMATCH, "Error:: too short BLOB packet ...\n"); ret = -4; break; } else @@ -282,7 +284,7 @@ rpc_srv_dispatchVars(void *arg) ret = -7; break; default: - rpc_SetErr(EINVAL, "Error:: unsupported BLOB command (%d)...\n", + rpc_SetErr(EPROCUNAVAIL, "Error:: unsupported BLOB command (%d)...\n", blob->hdr_cmd); ret = -7; } @@ -298,7 +300,7 @@ makeReply: break; } if (ret != sizeof buf) { - rpc_SetErr(ECANCELED, "Error:: in send BLOB reply, should be send %d bytes, " + rpc_SetErr(EPROCUNAVAIL, "Error:: in send BLOB reply, should be send %d bytes, " "really is %d\n", sizeof buf, ret); ret = -9; break; @@ -308,7 +310,7 @@ makeReply: shutdown(c->cli_sock, SHUT_RDWR); close(c->cli_sock); memset(c, 0, sizeof(rpc_cli_t)); - return (void*) (long)ret; + return (void*) ((long)ret); } // ------------------------------------------------- @@ -408,12 +410,10 @@ rpc_srv_initBLOBServer(rpc_srv_t * __restrict srv, u_s pthread_mutex_init(&srv->srv_blob.mtx, NULL); - pthread_mutex_lock(&srv->srv_mtx); rpc_srv_registerCall(srv, NULL, CALL_BLOBSHUTDOWN, 0); - rpc_srv_registerCall(srv, NULL, CALL_BLOBCLIENTS, 0); - rpc_srv_registerCall(srv, NULL, CALL_BLOBVARS, 0); - rpc_srv_registerCall(srv, NULL, CALL_BLOBSTATE, 1); - pthread_mutex_unlock(&srv->srv_mtx); + rpc_srv_registerCall(srv, NULL, CALL_BLOBCLIENTS, 1); + rpc_srv_registerCall(srv, NULL, CALL_BLOBVARS, 1); + rpc_srv_registerCall(srv, NULL, CALL_BLOBSTATE, 0); srv->srv_blob.state = enable; /* enable BLOB */ return 0; @@ -467,12 +467,12 @@ rpc_srv_endBLOBServer(rpc_srv_t * __restrict srv) } /* - * rpc_srv_execBLOBServer() Execute Main BLOB server loop and wait for clients requests + * rpc_srv_loopBLOB() Execute Main BLOB server loop and wait for clients requests * @srv = RPC Server instance * return: -1 error or 0 ok, infinite loop ... */ int -rpc_srv_execBLOBServer(rpc_srv_t * __restrict srv) +rpc_srv_loopBLOB(rpc_srv_t * __restrict srv) { socklen_t salen = sizeof(struct sockaddr); register int i; @@ -672,9 +672,9 @@ rpc_srv_initServer(u_int regProgID, u_int regProcID, i pthread_mutex_init(&srv->srv_mtx, NULL); rpc_srv_registerCall(srv, NULL, CALL_SRVSHUTDOWN, 0); - rpc_srv_registerCall(srv, NULL, CALL_SRVCLIENTS, 0); - rpc_srv_registerCall(srv, NULL, CALL_SRVCALLS, 0); - rpc_srv_registerCall(srv, NULL, CALL_SRVSESSIONS, 0); + rpc_srv_registerCall(srv, NULL, CALL_SRVCLIENTS, 1); + rpc_srv_registerCall(srv, NULL, CALL_SRVSESSIONS, 4); + rpc_srv_registerCall(srv, NULL, CALL_SRVCALLS, 1); return srv; } @@ -727,12 +727,12 @@ rpc_srv_endServer(rpc_srv_t * __restrict srv) } /* - * rpc_srv_execServer() Execute Main server loop and wait for clients requests + * rpc_srv_loopServer() Execute Main server loop and wait for clients requests * @srv = RPC Server instance * return: -1 error or 0 ok, infinite loop ... */ int -rpc_srv_execServer(rpc_srv_t * __restrict srv) +rpc_srv_loopServer(rpc_srv_t * __restrict srv) { socklen_t salen = sizeof(struct sockaddr); register int i; @@ -745,6 +745,9 @@ rpc_srv_execServer(rpc_srv_t * __restrict srv) rpc_SetErr(EINVAL, "Error:: Invalid parameter can`t start RPC server ...\n"); return -1; } + + /* activate BLOB server worker if srv->srv_blob.state == enable */ + rpc_srv_execBLOBServer(srv); if (listen(srv->srv_server.cli_sock, SOMAXCONN) == -1) { LOGERR;