--- libaitrpc/src/blob.c 2011/08/29 23:26:56 1.3.2.1 +++ libaitrpc/src/blob.c 2012/03/13 17:21:52 1.4.4.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: blob.c,v 1.3.2.1 2011/08/29 23:26:56 misho Exp $ +* $Id: blob.c,v 1.4.4.1 2012/03/13 17:21:52 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 +Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -71,7 +71,7 @@ again: rnd = random() % UINT_MAX; memset(szFName, 0, sizeof szFName); - snprintf(szFName, sizeof szFName, BLOB_FILE, srv->srv_blob.dir, rnd); + snprintf(szFName, sizeof szFName, BLOB_FILE, AIT_GET_STR(&srv->srv_blob.dir), rnd); f = open(szFName, O_CREAT | O_EXCL | O_RDWR, 0600); if (f == -1) { if (errno == EEXIST) @@ -127,9 +127,13 @@ rpc_srv_blobMap(rpc_srv_t * __restrict srv, rpc_blob_t rpc_SetErr(EINVAL, "Error:: invalid arguments ...\n"); return -1; } + if (blob->blob_data) { + rpc_SetErr(EPERM, "Error:: already mmapped object found!\n"); + return -1; + } memset(szFName, 0, sizeof szFName); - snprintf(szFName, sizeof szFName, BLOB_FILE, srv->srv_blob.dir, blob->blob_var); + snprintf(szFName, sizeof szFName, BLOB_FILE, AIT_GET_STR(&srv->srv_blob.dir), blob->blob_var); f = open(szFName, O_RDWR); if (f == -1) { LOGERR; @@ -187,7 +191,7 @@ rpc_srv_blobFree(rpc_srv_t * __restrict srv, rpc_blob_ rpc_srv_blobUnmap(blob); memset(szFName, 0, sizeof szFName); - snprintf(szFName, sizeof szFName, BLOB_FILE, srv->srv_blob.dir, blob->blob_var); + snprintf(szFName, sizeof szFName, BLOB_FILE, AIT_GET_STR(&srv->srv_blob.dir), blob->blob_var); if (unlink(szFName) == -1) { LOGERR; return -1; @@ -297,6 +301,7 @@ rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t 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) { LOGERR; @@ -337,7 +342,7 @@ rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t * return: -1 error, 0 ok, 1 remote error */ int -rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t * __restrict var, void ** data) +rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t * __restrict var, void ** __restrict data) { int ret, len; uint8_t *pos; @@ -369,6 +374,7 @@ rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t return -1; } + /* receive BLOB from server */ for (ret = AIT_LEN(var), pos = *data; ret > 0; ret -= len, pos += len) { FD_ZERO(&fds); FD_SET(cli->cli_sock, &fds);