--- libaitrpc/src/srv.c 2012/03/15 01:22:55 1.6.2.10 +++ libaitrpc/src/srv.c 2012/03/28 13:37:13 1.7.2.2 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: srv.c,v 1.6.2.10 2012/03/15 01:22:55 misho Exp $ +* $Id: srv.c,v 1.7.2.2 2012/03/28 13:37:13 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -60,7 +60,7 @@ txPacket(sched_task_t *task) int ret, wlen = sizeof(struct tagRPCCall); array_t *arr = NULL; - FTRACE(); + ioTRACE(RPC_TRACE_LEVEL); if (rpc->call_argc) { f = rpc_srv_getCall(s, ntohs(rpc->call_tag), ntohl(rpc->call_hash)); @@ -95,7 +95,7 @@ txPacket(sched_task_t *task) rpc_SetErr(EPROCUNAVAIL, "RPC reply, should be send %d bytes, " "really sended %d bytes", wlen, ret); else - LOGGER("Sended %d bytes", ret); + ioDEBUG(RPC_DEBUG_LEVEL, "Sended %d bytes", ret); return NULL; } @@ -111,10 +111,10 @@ execCall(sched_task_t *task) struct tagRPCCall *rpc = (struct tagRPCCall*) buf; int argc = ntohs(rpc->call_argc); - FTRACE(); + ioTRACE(RPC_TRACE_LEVEL); /* Go decapsulate variables ... */ - if (!(rpc->call_req.flags & RPC_NOREPLY) && argc) { + if (argc) { arr = io_buffer2vars(buf + sizeof(struct tagRPCCall), TASK_DATLEN(task) - sizeof(struct tagRPCCall), argc, 1); if (!arr) { @@ -132,16 +132,23 @@ execCall(sched_task_t *task) rpc->call_rep.ret = RPC_ERROR(-1); rpc->call_rep.eno = RPC_ERROR(rpc_Errno); } else { - LOGGER("RPC function %s from module %s", AIT_GET_STR(&f->func_name), - AIT_GET_LIKE(&f->func_file, char*)); + ioDEBUG(RPC_DEBUG_LEVEL, "RPC function %s from module %s", + AIT_GET_STR(&f->func_name), AIT_GET_LIKE(&f->func_file, char*)); + /* if client doesn't want reply */ + argc = rpc->call_req.flags & RPC_NOREPLY; rpc->call_rep.ret = RPC_ERROR(rpc_srv_execCall(f, rpc, arr)); if (rpc->call_rep.ret == htonl(-1)) { rpc->call_rep.eno = RPC_ERROR(errno); rpc->call_argc ^= rpc->call_argc; } else { rpc->call_rep.eno ^= rpc->call_rep.eno; - rpc->call_argc = htons(rpc_srv_getVars(f, NULL)); + if (argc) { + /* without reply */ + io_clrVars(f->func_vars); + rpc->call_argc ^= rpc->call_argc; + } else + rpc->call_argc = htons(rpc_srv_getVars(f, NULL)); } } @@ -161,7 +168,7 @@ rxPacket(sched_task_t *task) struct tagRPCCall *rpc; struct timespec ts; - FTRACE(); + ioTRACE(RPC_TRACE_LEVEL); memset(buf, 0, TASK_DATLEN(task)); rlen = recv(TASK_FD(task), buf, TASK_DATLEN(task), 0); @@ -173,7 +180,7 @@ rxPacket(sched_task_t *task) s->srv_kill = s->srv_blob.state = kill; return NULL; } else - LOGGER("Readed %d bytes", rlen); + ioDEBUG(RPC_DEBUG_LEVEL, "Readed %d bytes", rlen); if (rlen < sizeof(struct tagRPCCall)) { rpc_SetErr(ERPCMISMATCH, "Too short RPC packet"); @@ -233,7 +240,7 @@ rpc_srv_dispatchCall(void *arg) sched_root_task_t *root; struct timespec ts = { DEF_RPC_TIMEOUT, 0 }; - FTRACE(); + ioTRACE(RPC_TRACE_LEVEL); if (!arg) { rpc_SetErr(EINVAL, "Invalid parameter can`t procced RPC client"); @@ -278,7 +285,7 @@ txBLOB(sched_task_t *task) struct tagBLOBHdr *blob = (struct tagBLOBHdr *) buf; int wlen = sizeof(struct tagBLOBHdr); - FTRACE(); + ioTRACE(RPC_TRACE_LEVEL); /* calculate CRC */ blob->hdr_crc ^= blob->hdr_crc; @@ -292,7 +299,7 @@ txBLOB(sched_task_t *task) rpc_SetErr(EPROCUNAVAIL, "RPC reply, should be send %d bytes, " "really sended %d bytes", sizeof(struct tagBLOBHdr), wlen); else - LOGGER("Sended %d bytes", wlen); + ioDEBUG(RPC_DEBUG_LEVEL, "Sended %d bytes", wlen); return NULL; } @@ -309,10 +316,10 @@ rxBLOB(sched_task_t *task) u_short crc; struct timespec ts; - FTRACE(); + ioTRACE(RPC_TRACE_LEVEL); /* check for disable service at this moment? */ - if (s->srv_blob.state == disable) { + if (!s || s->srv_blob.state == disable) { usleep(100000); #ifdef HAVE_PTHREAD_YIELD pthread_yield(); @@ -332,7 +339,7 @@ rxBLOB(sched_task_t *task) s->srv_blob.state = kill; return NULL; } else - LOGGER("Readed %d bytes", rlen); + ioDEBUG(RPC_DEBUG_LEVEL, "Readed %d bytes", rlen); if (rlen < sizeof(struct tagBLOBHdr)) { rpc_SetErr(ERPCMISMATCH, "Too short BLOB packet"); @@ -425,7 +432,7 @@ rpc_srv_dispatchVars(void *arg) u_char *buf; struct timespec ts = { DEF_RPC_TIMEOUT, 0 }; - FTRACE(); + ioTRACE(RPC_TRACE_LEVEL); if (!arg) { rpc_SetErr(EINVAL, "Invalid parameter can`t procced BLOB"); @@ -478,7 +485,7 @@ rpc_srv_initBLOBServer(rpc_srv_t * __restrict srv, u_s int n = 1; io_sockaddr_t sa; - FTRACE(); + ioTRACE(RPC_TRACE_LEVEL); if (!srv) { rpc_SetErr(EINVAL, "Invalid parameters can`t init BLOB server"); @@ -584,12 +591,11 @@ rpc_srv_endBLOBServer(rpc_srv_t * __restrict srv) register int i; rpc_blob_t *f; - FTRACE(); + ioTRACE(RPC_TRACE_LEVEL); - if (!srv) { - rpc_SetErr(EINVAL, "Can`t destroy server because parameter is null!"); + if (!srv || srv->srv_blob.state == disable) return; - } else + else srv->srv_blob.state = kill; rpc_srv_unregisterCall(srv, NULL, CALL_BLOBSHUTDOWN); @@ -621,6 +627,9 @@ rpc_srv_endBLOBServer(rpc_srv_t * __restrict srv) while (pthread_mutex_trylock(&srv->srv_blob.mtx) == EBUSY); pthread_mutex_destroy(&srv->srv_blob.mtx); + + /* at final, save disable BLOB service state */ + srv->srv_blob.state = disable; } /* @@ -640,7 +649,7 @@ rpc_srv_loopBLOB(rpc_srv_t * __restrict srv) struct timeval tv = { DEF_RPC_TIMEOUT, 0 }; pthread_attr_t attr; - FTRACE(); + ioTRACE(RPC_TRACE_LEVEL); if (!srv || srv->srv_blob.state == kill) { rpc_SetErr(EINVAL, "Invalid parameter can`t start BLOB server"); @@ -724,7 +733,7 @@ rpc_srv_initServer(u_int regProgID, u_int regProcID, i struct hostent *host = NULL; io_sockaddr_t sa; - FTRACE(); + ioTRACE(RPC_TRACE_LEVEL); if (!concurentClients || !regProgID || (family != AF_INET && family != AF_INET6 && family != AF_LOCAL)) { @@ -838,6 +847,7 @@ rpc_srv_initServer(u_int regProgID, u_int regProcID, i 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; } @@ -854,7 +864,7 @@ rpc_srv_endServer(rpc_srv_t ** __restrict psrv) register int i; rpc_func_t *f; - FTRACE(); + ioTRACE(RPC_TRACE_LEVEL); if (!psrv || !*psrv) { rpc_SetErr(EINVAL, "Error:: Can`t destroy server because parameter is null!\n"); @@ -912,7 +922,7 @@ rpc_srv_loopServer(rpc_srv_t * __restrict srv) struct timeval tv = { DEF_RPC_TIMEOUT, 0 }; pthread_attr_t attr; - FTRACE(); + ioTRACE(RPC_TRACE_LEVEL); if (!srv) { rpc_SetErr(EINVAL, "Error:: Invalid parameter can`t start RPC server ...\n"); @@ -993,7 +1003,7 @@ rpc_srv_execCall(rpc_func_t * __restrict call, struct rpc_callback_t func; int ret; - FTRACE(); + ioTRACE(RPC_TRACE_LEVEL); if (!call || !rpc || !call->func_parent) { rpc_SetErr(EINVAL, "Invalid parameter can`t exec function");