--- libaitrpc/src/srv.c 2013/11/14 23:38:41 1.21.2.2 +++ libaitrpc/src/srv.c 2013/11/15 09:09:39 1.21.2.6 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: srv.c,v 1.21.2.2 2013/11/14 23:38:41 misho Exp $ +* $Id: srv.c,v 1.21.2.6 2013/11/15 09:09:39 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -223,7 +223,7 @@ txPacket(sched_task_t *task) if (ret) LOGERR; else - rpc_SetErr(ETIMEDOUT, "Timeout reached! Server not respond"); + rpc_SetErr(ETIMEDOUT, "Timeout reached! Client not respond"); /* close connection */ schedEvent(TASK_ROOT(task), cbProto[s->srv_proto][CB_CLOSECLIENT], TASK_ARG(task), 0, NULL, 0); @@ -346,7 +346,7 @@ rxPacket(sched_task_t *task) if (rlen) LOGERR; else - rpc_SetErr(ETIMEDOUT, "Timeout reached! Server not respond"); + rpc_SetErr(ETIMEDOUT, "Timeout reached! Client not respond"); schedEvent(TASK_ROOT(task), cbProto[s->srv_proto][CB_CLOSECLIENT], TASK_ARG(task), 0, NULL, 0); return NULL; @@ -448,7 +448,7 @@ txUDPPacket(sched_task_t *task) rpc_func_t *f = NULL; u_char *buf = AIT_GET_BUF(&c->cli_buf); struct tagRPCCall *rpc = (struct tagRPCCall*) buf; - int ret, wlen = sizeof(struct tagRPCCall); + int ret, estlen, wlen = sizeof(struct tagRPCCall); struct timespec ts = { DEF_RPC_TIMEOUT, 0 }; struct pollfd pfd; @@ -464,6 +464,13 @@ txUDPPacket(sched_task_t *task) rpc->call_rep.ret = RPC_ERROR(-1); rpc->call_rep.eno = RPC_ERROR(rpc_Errno); } else { + /* calc estimated length */ + estlen = ait_resideVars(RPC_RETVARS(c)) + wlen; + if (estlen > AIT_LEN(&c->cli_buf)) + AIT_RE_BUF(&c->cli_buf, estlen); + buf = AIT_GET_BUF(&c->cli_buf); + rpc = (struct tagRPCCall*) buf; + rpc->call_argc = htons(array_Size(RPC_RETVARS(c))); /* Go Encapsulate variables */ ret = ait_vars2buffer(buf + wlen, AIT_LEN(&c->cli_buf) - wlen, @@ -495,7 +502,7 @@ txUDPPacket(sched_task_t *task) if (ret) LOGERR; else - rpc_SetErr(ETIMEDOUT, "Timeout reached! Server not respond"); + rpc_SetErr(ETIMEDOUT, "Timeout reached! Client not respond"); /* close connection */ schedEvent(TASK_ROOT(task), cbProto[s->srv_proto][CB_CLOSECLIENT], TASK_ARG(task), 0, NULL, 0); @@ -537,9 +544,11 @@ rxUDPPacket(sched_task_t *task) } c = _allocClient(srv, &sa); - if (!c) + if (!c) { + EVERBOSE(1, "RPC client quota exceeded! Connection will be shutdown!\n"); + usleep(2000); /* blocked client delay */ goto end; - else { + } else { estlen = ntohl(rpc->call_len); if (estlen > AIT_LEN(&c->cli_buf)) AIT_RE_BUF(&c->cli_buf, estlen); @@ -566,11 +575,12 @@ rxUDPPacket(sched_task_t *task) if (rlen) LOGERR; else - rpc_SetErr(ETIMEDOUT, "Timeout reached! Server not respond"); + rpc_SetErr(ETIMEDOUT, "Timeout reached! Client not respond"); schedEvent(TASK_ROOT(task), cbProto[srv->srv_proto][CB_CLOSECLIENT], c, 0, NULL, 0); return NULL; } + salen = sa.ss.ss_len = sizeof(sockaddr_t); rlen = recvfrom(TASK_FD(task), buf, len, 0, &sa.sa, &salen); if (rlen == -1) { /* close connection */ @@ -578,6 +588,8 @@ rxUDPPacket(sched_task_t *task) c, 0, NULL, 0); return NULL; } + if (e_addrcmp(&c->cli_sa, &sa, 42)) + rlen ^= rlen; /* skip if arrive from different address */ } len = estlen;