--- libaitrpc/src/blob.c 2012/05/16 14:46:29 1.7.2.6 +++ libaitrpc/src/blob.c 2012/05/19 00:29:51 1.8 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: blob.c,v 1.7.2.6 2012/05/16 14:46:29 misho Exp $ +* $Id: blob.c,v 1.8 2012/05/19 00:29:51 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -247,7 +247,10 @@ rpc_srv_recvBLOB(rpc_cli_t * __restrict cli, rpc_blob_ for (ret = blob->blob_len, pos = blob->blob_data; ret > 0; ret -= len, pos += len) { if ((len = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) < 1 || pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { - LOGERR; + if (len) + LOGERR; + else + rpc_SetErr(ETIMEDOUT, "Timeout reached! Server not respond"); return -1; } @@ -295,6 +298,13 @@ rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t hdr.hdr_crc = htons(crcFletcher16((u_short*) &hdr, sizeof hdr / 2)); /* send SET request */ + pfd.fd = cli->cli_sock; + pfd.events = POLLOUT; + if ((ret = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) == -1 || + pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { + LOGERR; + return -1; + } if (send(cli->cli_sock, &hdr, sizeof hdr, MSG_NOSIGNAL) == -1) { LOGERR; return -1; @@ -308,7 +318,6 @@ rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t } /* wait for reply */ - pfd.fd = cli->cli_sock; pfd.events = POLLIN | POLLPRI; if ((ret = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) < 1 || pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { @@ -382,6 +391,15 @@ rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t hdr.hdr_crc = htons(crcFletcher16((u_short*) &hdr, sizeof hdr / 2)); /* send GET request */ + pfd.fd = cli->cli_sock; + pfd.events = POLLOUT; + if ((ret = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) == -1 || + pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { + LOGERR; + free(*data); + *data = NULL; + return -1; + } if (send(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) { LOGERR; free(*data); @@ -390,7 +408,6 @@ rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t } /* receive BLOB from server */ - pfd.fd = cli->cli_sock; pfd.events = POLLIN | POLLPRI; for (ret = AIT_LEN(var), pos = *data; ret > 0; ret -= len, pos += len) { if ((len = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) < 1 || @@ -477,13 +494,19 @@ rpc_cli_delBLOB(rpc_cli_t * __restrict cli, ait_val_t hdr.hdr_crc = htons(crcFletcher16((u_short*) &hdr, sizeof hdr / 2)); /* send UNSET request */ + pfd.fd = cli->cli_sock; + pfd.events = POLLOUT; + if ((ret = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) == -1 || + pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { + LOGERR; + return -1; + } if (send(cli->cli_sock, &hdr, sizeof hdr, MSG_NOSIGNAL) == -1) { LOGERR; return -1; } /* wait for reply */ - pfd.fd = cli->cli_sock; pfd.events = POLLIN | POLLPRI; if ((ret = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) < 1 || pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) {