--- libaitrpc/src/blob.c 2011/05/02 23:12:08 1.2 +++ libaitrpc/src/blob.c 2011/08/29 22:37:06 1.3 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: blob.c,v 1.2 2011/05/02 23:12:08 misho Exp $ +* $Id: blob.c,v 1.3 2011/08/29 22:37:06 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -70,8 +70,8 @@ rpc_srv_blobCreate(rpc_srv_t * __restrict srv, int len again: rnd = random() % UINT_MAX; - memset(szFName, 0, MAXPATHLEN); - snprintf(szFName, MAXPATHLEN, BLOB_FILE, srv->srv_blob.dir, rnd); + memset(szFName, 0, sizeof szFName); + snprintf(szFName, sizeof szFName, BLOB_FILE, srv->srv_blob.dir, rnd); f = open(szFName, O_CREAT | O_EXCL | O_RDWR, 0600); if (f == -1) { if (errno == EEXIST) @@ -128,8 +128,8 @@ rpc_srv_blobMap(rpc_srv_t * __restrict srv, rpc_blob_t return -1; } - memset(szFName, 0, MAXPATHLEN); - snprintf(szFName, MAXPATHLEN, BLOB_FILE, srv->srv_blob.dir, blob->blob_var); + memset(szFName, 0, sizeof szFName); + snprintf(szFName, sizeof szFName, BLOB_FILE, srv->srv_blob.dir, blob->blob_var); f = open(szFName, O_RDWR); if (f == -1) { LOGERR; @@ -186,9 +186,9 @@ rpc_srv_blobFree(rpc_srv_t * __restrict srv, rpc_blob_ if (blob->blob_data) rpc_srv_blobUnmap(blob); - memset(szFName, 0, MAXPATHLEN); - snprintf(szFName, MAXPATHLEN, BLOB_FILE, srv->srv_blob.dir, blob->blob_var); - if (remove(szFName) == -1) { + memset(szFName, 0, sizeof szFName); + snprintf(szFName, sizeof szFName, BLOB_FILE, srv->srv_blob.dir, blob->blob_var); + if (unlink(szFName) == -1) { LOGERR; return -1; } @@ -215,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, 0); + if (len == -1) { LOGERR; return -1; } + } return ret; } @@ -252,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, ret, 0); + if (len == -1) { LOGERR; return -1; } @@ -295,7 +298,7 @@ rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, rpc_val_t } 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 = send(cli->cli_sock, pos, ret, 0)) == -1) { LOGERR; return -1; } @@ -377,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 = recv(cli->cli_sock, pos, ret, 0)) == -1) { LOGERR; free(*data); *data = NULL;