--- libaitrpc/src/srv.c 2012/03/13 17:21:52 1.6.2.6 +++ libaitrpc/src/srv.c 2012/03/14 13:29:11 1.6.2.7 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: srv.c,v 1.6.2.6 2012/03/13 17:21:52 misho Exp $ +* $Id: srv.c,v 1.6.2.7 2012/03/14 13:29:11 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -59,6 +59,8 @@ txPacket(sched_task_t *task) int ret, wlen = sizeof(struct tagRPCCall); array_t *arr = NULL; + FTRACE(); + if (rpc->call_argc) { f = rpc_srv_getCall(s, ntohs(rpc->call_tag), ntohl(rpc->call_hash)); if (!f) { @@ -80,6 +82,10 @@ txPacket(sched_task_t *task) } } + /* calculate CRC */ + rpc->call_crc ^= rpc->call_crc; + rpc->call_crc = htons(crcFletcher16((u_short*) buf, ((wlen + 1) & ~1) / 2)); + /* send reply */ ret = send(TASK_FD(task), buf, wlen, 0); if (ret == -1) @@ -87,6 +93,8 @@ txPacket(sched_task_t *task) else if (ret != wlen) rpc_SetErr(EPROCUNAVAIL, "RPC reply, should be send %d bytes, " "really sended %d bytes", wlen, ret); + else + LOGGER("Sended %d bytes", ret); /* lets get next packet */ schedRead(TASK_ROOT(task), rxPacket, TASK_ARG(task), TASK_FD(task), @@ -105,6 +113,8 @@ execCall(sched_task_t *task) struct tagRPCCall *rpc = (struct tagRPCCall*) buf; int argc = ntohs(rpc->call_argc); + FTRACE(); + /* Go decapsulate variables ... */ if (!(rpc->call_req.flags & RPC_NOREPLY) && argc) { arr = io_buffer2vars(buf + sizeof(struct tagRPCCall), @@ -124,6 +134,9 @@ 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_STR(&f->func_file)); + 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); @@ -150,6 +163,8 @@ rxPacket(sched_task_t *task) struct tagRPCCall *rpc; struct timespec ts; + FTRACE(); + memset(buf, 0, TASK_DATLEN(task)); rlen = recv(TASK_FD(task), buf, TASK_DATLEN(task), 0); if (rlen == -1) { @@ -165,7 +180,9 @@ rxPacket(sched_task_t *task) schedRead(TASK_ROOT(task), rxPacket, TASK_ARG(task), TASK_FD(task), TASK_DATA(task), TASK_DATLEN(task)); return NULL; - } + } else + LOGGER("Readed %d bytes", rlen); + if (rlen < sizeof(struct tagRPCCall)) { rpc_SetErr(ERPCMISMATCH, "Too short RPC packet"); @@ -224,6 +241,8 @@ rpc_srv_dispatchCall(void *arg) sched_root_task_t *root; struct timespec ts = { DEF_RPC_TIMEOUT, 0 }; + FTRACE(); + if (!arg) { rpc_SetErr(EINVAL, "Invalid parameter can`t procced RPC client"); return NULL; @@ -271,6 +290,8 @@ rpc_srv_dispatchVars(void *arg) u_char buf[sizeof(struct tagBLOBHdr)]; struct tagBLOBHdr *blob; + FTRACE(); + if (!arg) { rpc_SetErr(EINVAL, "Error:: Invalid parameter can`t procced BLOB client ...\n"); return NULL; @@ -407,6 +428,8 @@ rpc_srv_initBLOBServer(rpc_srv_t * __restrict srv, u_s int n = 1; io_sockaddr_t sa; + FTRACE(); + if (!srv) { rpc_SetErr(EINVAL, "Invalid parameters can`t init BLOB server"); return -1; @@ -511,6 +534,8 @@ rpc_srv_endBLOBServer(rpc_srv_t * __restrict srv) register int i; rpc_blob_t *f; + FTRACE(); + if (!srv) { rpc_SetErr(EINVAL, "Can`t destroy server because parameter is null!"); return; @@ -565,6 +590,8 @@ rpc_srv_loopBLOB(rpc_srv_t * __restrict srv) struct timeval tv = { DEF_RPC_TIMEOUT, 0 }; pthread_attr_t attr; + FTRACE(); + if (!srv || srv->srv_blob.state == kill) { rpc_SetErr(EINVAL, "Error:: Invalid parameter can`t start BLOB server ...\n"); return -1; @@ -647,6 +674,8 @@ rpc_srv_initServer(u_int regProgID, u_int regProcID, i struct hostent *host = NULL; io_sockaddr_t sa; + FTRACE(); + if (!concurentClients || !regProgID || (family != AF_INET && family != AF_INET6 && family != AF_LOCAL)) { rpc_SetErr(EINVAL, "Error:: Invalid parameters can`t init RPC server ...\n"); @@ -773,6 +802,8 @@ rpc_srv_endServer(rpc_srv_t ** __restrict psrv) register int i; rpc_func_t *f; + FTRACE(); + if (!psrv || !*psrv) { rpc_SetErr(EINVAL, "Error:: Can`t destroy server because parameter is null!\n"); return; @@ -829,6 +860,8 @@ rpc_srv_loopServer(rpc_srv_t * __restrict srv) struct timeval tv = { DEF_RPC_TIMEOUT, 0 }; pthread_attr_t attr; + FTRACE(); + if (!srv) { rpc_SetErr(EINVAL, "Error:: Invalid parameter can`t start RPC server ...\n"); return -1; @@ -907,6 +940,8 @@ rpc_srv_execCall(rpc_func_t * __restrict call, struct void *dl; rpc_callback_t func; int ret; + + FTRACE(); if (!call || !rpc || !call->func_parent) { rpc_SetErr(EINVAL, "Invalid parameter can`t exec function");