--- libaitrpc/src/srv.c 2013/11/14 21:44:14 1.21 +++ libaitrpc/src/srv.c 2013/11/14 22:29:31 1.21.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: srv.c,v 1.21 2013/11/14 21:44:14 misho Exp $ +* $Id: srv.c,v 1.21.2.1 2013/11/14 22:29:31 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -449,6 +449,7 @@ txUDPPacket(sched_task_t *task) struct tagRPCCall *rpc = (struct tagRPCCall*) buf; int ret, wlen = sizeof(struct tagRPCCall); struct timespec ts = { DEF_RPC_TIMEOUT, 0 }; + struct pollfd pfd; schedCancelby(TASK_ROOT(task), taskTIMER, CRITERIA_DATA, TASK_ARG(task), NULL); schedTimer(TASK_ROOT(task), cbProto[s->srv_proto][CB_CLOSECLIENT], @@ -485,12 +486,28 @@ txUDPPacket(sched_task_t *task) rpc->call_crc = htons(crcFletcher16((u_short*) buf, wlen / 2)); /* send reply */ - ret = sendto(TASK_FD(task), buf, wlen, MSG_NOSIGNAL, - &c->cli_sa.sa, c->cli_sa.sa.sa_len); - if (ret == -1 || ret != wlen) { - /* close connection */ - schedEvent(TASK_ROOT(task), cbProto[s->srv_proto][CB_CLOSECLIENT], - TASK_ARG(task), 0, NULL, 0); + pfd.fd = TASK_FD(task); + pfd.events = POLLOUT; + for (; wlen > 0; wlen -= ret, buf += ret) { + if ((ret = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) < 1 || + pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { + if (ret) + LOGERR; + else + rpc_SetErr(ETIMEDOUT, "Timeout reached! Server not respond"); + /* close connection */ + schedEvent(TASK_ROOT(task), cbProto[s->srv_proto][CB_CLOSECLIENT], + TASK_ARG(task), 0, NULL, 0); + return NULL; + } + ret = sendto(TASK_FD(task), buf, MIN(wlen, s->srv_netbuf), MSG_NOSIGNAL, + &c->cli_sa.sa, c->cli_sa.sa.sa_len); + if (ret == -1) { + /* close connection */ + schedEvent(TASK_ROOT(task), cbProto[s->srv_proto][CB_CLOSECLIENT], + TASK_ARG(task), 0, NULL, 0); + return NULL; + } } return NULL;