--- libaitrpc/src/cli.c 2012/05/17 15:24:28 1.9.2.12 +++ libaitrpc/src/cli.c 2012/05/18 15:37:58 1.9.2.17 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: cli.c,v 1.9.2.12 2012/05/17 15:24:28 misho Exp $ +* $Id: cli.c,v 1.9.2.17 2012/05/18 15:37:58 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -102,9 +102,8 @@ rpc_cli_openBLOBClient(rpc_cli_t * __restrict rpccli, close(cli->cli_sock); free(cli); return NULL; - } /*else + } else fcntl(cli->cli_sock, F_SETFL, fcntl(cli->cli_sock, F_GETFL) | O_NONBLOCK); - */ return cli; } @@ -203,9 +202,8 @@ rpc_cli_openClient(u_int ProgID, u_char ProcID, int ne free(cli->cli_parent); free(cli); return NULL; - } /*else + } else fcntl(cli->cli_sock, F_SETFL, fcntl(cli->cli_sock, F_GETFL) | O_NONBLOCK); - */ return cli; } @@ -290,6 +288,21 @@ rpc_cli_execCall(rpc_cli_t *cli, int noreply, u_short rpc->call_crc ^= rpc->call_crc; rpc->call_crc = htons(crcFletcher16((u_short*) buf, wlen / 2)); + pfd.fd = cli->cli_sock; + pfd.events = POLLOUT; + do { + if ((ret = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) < 1 || + pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { + if (ret) { + if (errno == EAGAIN) + continue; + else + LOGERR; + } else + rpc_SetErr(ETIMEDOUT, "Timeout, can't send to RPC server"); + return -1; + } + } while (0); if ((ret = send(cli->cli_sock, buf, wlen, MSG_NOSIGNAL)) == -1) { LOGERR; return -1; @@ -302,18 +315,26 @@ rpc_cli_execCall(rpc_cli_t *cli, int noreply, u_short if (noreply) /* we not want reply */ return 0; + wlen = 0; /* reply from RPC server */ - pfd.fd = cli->cli_sock; pfd.events = POLLIN | POLLPRI; - if ((ret = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) == -1 || - pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { - if (ret) - LOGERR; - else - rpc_SetErr(ETIMEDOUT, "Timeout, no answer from RPC server"); - - return -1; - } + do { + if ((ret = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) < 1 || + pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { + if (ret) { + if (errno == EAGAIN) + continue; + else + LOGERR; + } else { + if (wlen++ < 7) + continue; + else + rpc_SetErr(ETIMEDOUT, "Timeout, no answer from RPC server"); + } + return -1; + } + } while (0); memset(buf, 0, AIT_LEN(&cli->cli_buf)); if ((ret = recv(cli->cli_sock, buf, AIT_LEN(&cli->cli_buf), 0)) < 1) { if (ret) @@ -377,8 +398,8 @@ rpc_cli_execCall(rpc_cli_t *cli, int noreply, u_short inline int rpc_cli_ping(rpc_cli_t *cli) { - array_t *arr; int ret = 0; + array_t *arr = NULL; if (!cli) return -1; @@ -386,7 +407,7 @@ rpc_cli_ping(rpc_cli_t *cli) if (rpc_cli_execCall(cli, RPC_REPLY, CALL_SRVPING, NULL, &arr)) return -1; else - ret = AIT_GET_U16(io_getVars(arr, 0)); + ret = AIT_GET_U16(io_array(arr, 0, ait_val_t*)); io_freeVars(&arr); return ret;