--- libaitrpc/src/aitrpc.c 2013/08/23 13:53:15 1.11 +++ libaitrpc/src/aitrpc.c 2013/11/11 22:48:53 1.12 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aitrpc.c,v 1.11 2013/08/23 13:53:15 misho Exp $ +* $Id: aitrpc.c,v 1.12 2013/11/11 22:48:53 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -228,7 +228,12 @@ rpc_Write(int sock, int type, int flags, sockaddr_t * for (len = blen; len > 0; len -= ret, buf += ret) { if ((ret = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) < 1 || pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { - LOGERR; + if (!ret) + continue; + if (ret > 0) + rpc_SetErr(EPIPE, "Disconnected RPC session\n"); + else + LOGERR; return -1; } else ret = send(sock, buf, len, flags); @@ -240,12 +245,19 @@ rpc_Write(int sock, int type, int flags, sockaddr_t * if (ret > -1) ret = blen - len; } else if (sa) { - if ((ret = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) < 1 || - pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { - LOGERR; - return -1; - } else - ret = sendto(sock, buf, blen, flags, &sa->sa, sa->sa.sa_len); + do { + if ((ret = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) < 1 || + pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { + if (!ret) + continue; + if (ret > 0) + rpc_SetErr(EPIPE, "Disconnected RPC session\n"); + else + LOGERR; + return -1; + } else + ret = sendto(sock, buf, blen, flags, &sa->sa, sa->sa.sa_len); + } while (0); } else { rpc_SetErr(EINVAL, "Invalid argument(s)!"); return -1;