--- libaitrpc/src/blob.c 2012/05/16 08:20:26 1.7.2.3 +++ libaitrpc/src/blob.c 2012/05/17 21:40:02 1.7.2.8 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: blob.c,v 1.7.2.3 2012/05/16 08:20:26 misho Exp $ +* $Id: blob.c,v 1.7.2.8 2012/05/17 21:40:02 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -61,13 +61,6 @@ rpc_srv_blobCreate(rpc_srv_t * __restrict srv, int len int f; u_int rnd; -#ifdef HAVE_SRANDOMDEV - srandomdev(); -#else - time_t tim; - - srandom((time(&tim) ^ getpid())); -#endif again: rnd = random() % UINT_MAX; @@ -254,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; } @@ -289,7 +285,8 @@ rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t if (!cli || !var || !data) { rpc_SetErr(EINVAL, "Invalid arguments"); return -1; - } + } else + memset(&hdr, 0, sizeof hdr); rpc_addPktSession(&hdr.hdr_session, cli->cli_parent); hdr.hdr_cmd = set; @@ -301,20 +298,26 @@ 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 */ - if (send(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) { + 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; + } /* send BLOB to server */ for (ret = AIT_LEN(var), pos = data; ret > 0; ret -= len, pos += len) - if ((len = send(cli->cli_sock, pos, ret, 0)) == -1) { + if ((len = send(cli->cli_sock, pos, ret, 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)) { @@ -342,7 +345,7 @@ rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t return 1; } - var->val.blob = ntohl(hdr.hdr_var); + AIT_SET_BLOB(var, ntohl(hdr.hdr_var), ntohl(hdr.hdr_len)); } return hdr.hdr_cmd == error; @@ -373,8 +376,10 @@ rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t if (!*data) { LOGERR; return -1; - } else + } else { + memset(&hdr, 0, sizeof hdr); memset(*data, 0, AIT_LEN(var)); + } rpc_addPktSession(&hdr.hdr_session, cli->cli_parent); hdr.hdr_cmd = get; @@ -386,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); @@ -394,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 || @@ -468,7 +481,8 @@ rpc_cli_delBLOB(rpc_cli_t * __restrict cli, ait_val_t if (!cli || !var) { rpc_SetErr(EINVAL, "Invalid arguments"); return -1; - } + } else + memset(&hdr, 0, sizeof hdr); rpc_addPktSession(&hdr.hdr_session, cli->cli_parent); hdr.hdr_cmd = unset; @@ -480,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 */ - if (send(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) { + 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)) {