--- libaitrpc/src/blob.c 2011/05/02 23:07:55 1.1.2.16 +++ libaitrpc/src/blob.c 2011/08/19 12:51:50 1.2.4.2 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: blob.c,v 1.1.2.16 2011/05/02 23:07:55 misho Exp $ +* $Id: blob.c,v 1.2.4.2 2011/08/19 12:51:50 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -60,7 +60,13 @@ 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; @@ -209,11 +215,13 @@ rpc_srv_sendBLOB(rpc_cli_t * __restrict cli, rpc_blob_ return -1; } - for (ret = blob->blob_len, pos = blob->blob_data; ret > 0; ret -= len, pos += len) - if ((len = send(cli->cli_sock, pos, ret > BLOBSIZ ? BLOBSIZ : ret, 0)) == -1) { + for (ret = blob->blob_len, pos = blob->blob_data; ret > 0; ret -= len, pos += len) { + len = send(cli->cli_sock, pos, ret > BLOBSIZ ? BLOBSIZ : ret, 0); + if (len == -1) { LOGERR; return -1; } + } return ret; } @@ -246,7 +254,8 @@ rpc_srv_recvBLOB(rpc_cli_t * __restrict cli, rpc_blob_ return -1; } - if ((len = recv(cli->cli_sock, pos, BLOBSIZ, 0)) == -1) { + len = recv(cli->cli_sock, pos, BLOBSIZ, 0); + if (len == -1) { LOGERR; return -1; } @@ -283,13 +292,13 @@ rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, rpc_val_t hdr.hdr_var = 0; hdr.hdr_ret = 0; hdr.hdr_len = var->val_len; - if (send(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) { + if (write(cli->cli_sock, &hdr, sizeof hdr) == -1) { LOGERR; return -1; } for (ret = var->val_len, pos = data; ret > 0; ret -= len, pos += len) - if ((len = send(cli->cli_sock, pos, ret > BLOBSIZ ? BLOBSIZ : ret, 0)) == -1) { + if ((len = write(cli->cli_sock, pos, ret > BLOBSIZ ? BLOBSIZ : ret)) == -1) { LOGERR; return -1; } @@ -304,7 +313,7 @@ rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, rpc_val_t rpc_SetErr(ETIMEDOUT, "Error:: Timeout reached! Server not responde ...\n"); return -1; } - if (recv(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) { + if (read(cli->cli_sock, &hdr, sizeof hdr) == -1) { LOGERR; return -1; } @@ -353,7 +362,7 @@ rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, rpc_val_t hdr.hdr_var = (uint32_t) RPC_GET_BLOB(var); hdr.hdr_ret = 0; hdr.hdr_len = 0; - if (send(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) { + if (write(cli->cli_sock, &hdr, sizeof hdr) == -1) { LOGERR; free(*data); *data = NULL; @@ -371,7 +380,7 @@ rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, rpc_val_t return -1; } - if ((len = recv(cli->cli_sock, pos, BLOBSIZ, 0)) == -1) { + if ((len = read(cli->cli_sock, pos, BLOBSIZ)) == -1) { LOGERR; free(*data); *data = NULL; @@ -393,7 +402,7 @@ rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, rpc_val_t *data = NULL; return -1; } - if (recv(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) { + if (read(cli->cli_sock, &hdr, sizeof hdr) == -1) { LOGERR; free(*data); *data = NULL; @@ -434,7 +443,7 @@ rpc_cli_delBLOB(rpc_cli_t * __restrict cli, rpc_val_t hdr.hdr_var = (uint32_t) RPC_GET_BLOB(var); hdr.hdr_ret = 0; hdr.hdr_len = 0; - if (send(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) { + if (write(cli->cli_sock, &hdr, sizeof hdr) == -1) { LOGERR; return -1; } @@ -449,7 +458,7 @@ rpc_cli_delBLOB(rpc_cli_t * __restrict cli, rpc_val_t rpc_SetErr(ETIMEDOUT, "Error:: Timeout reached! Server not responde ...\n"); return -1; } - if (recv(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) { + if (read(cli->cli_sock, &hdr, sizeof hdr) == -1) { LOGERR; return -1; }