version 1.12, 2013/04/02 15:50:14
|
version 1.15, 2014/01/28 14:05:43
|
Line 12 terms:
|
Line 12 terms:
|
All of the documentation and software included in the ELWIX and AITNET |
All of the documentation and software included in the ELWIX and AITNET |
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
|
|
Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 | Copyright 2004 - 2014 |
by Michael Pounov <misho@elwix.org>. All rights reserved. |
by Michael Pounov <misho@elwix.org>. All rights reserved. |
|
|
Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
Line 46 SUCH DAMAGE.
|
Line 46 SUCH DAMAGE.
|
#include "global.h" |
#include "global.h" |
|
|
|
|
|
static void * |
|
toutBLOB(sched_task_t *task) |
|
{ |
|
rpc_srv_unregisterBLOB(TASK_DATA(task), ((rpc_blob_t*) TASK_ARG(task))->blob_var); |
|
|
|
return NULL; |
|
} |
|
|
|
|
/* |
/* |
* rpc_srv_blobCreate() - Create and map blob to memory region and return object |
* rpc_srv_blobCreate() - Create and map blob to memory region and return object |
* |
* |
* @srv = RPC Server instance |
* @srv = RPC Server instance |
* @len = BLOB length object |
* @len = BLOB length object |
|
* @tout = BLOB live timeout in seconds |
* return: NULL error or !=NULL allocated BLOB object |
* return: NULL error or !=NULL allocated BLOB object |
*/ |
*/ |
inline rpc_blob_t * | rpc_blob_t * |
rpc_srv_blobCreate(rpc_srv_t * __restrict srv, int len) | rpc_srv_blobCreate(rpc_srv_t * __restrict srv, int len, int tout) |
{ |
{ |
rpc_blob_t *blob = NULL; |
rpc_blob_t *blob = NULL; |
char szFName[MAXPATHLEN]; |
char szFName[MAXPATHLEN]; |
int f; |
int f; |
u_int rnd; |
u_int rnd; |
|
struct timespec ts = { tout ? tout : RPC_BLOB_TIMEOUT, 0 }; |
|
|
again: |
again: |
rnd = random() % UINT_MAX; |
rnd = random() % UINT_MAX; |
Line 101 again:
|
Line 112 again:
|
|
|
blob->blob_len = len; |
blob->blob_len = len; |
blob->blob_var = rnd; |
blob->blob_var = rnd; |
|
|
|
schedTimer(srv->srv_blob.root, toutBLOB, blob, ts, srv, 0); |
return blob; |
return blob; |
} |
} |
|
|
Line 111 again:
|
Line 124 again:
|
* @blob = Map to this BLOB element |
* @blob = Map to this BLOB element |
* return: -1 error or 0 ok |
* return: -1 error or 0 ok |
*/ |
*/ |
inline int | int |
rpc_srv_blobMap(rpc_srv_t * __restrict srv, rpc_blob_t * __restrict blob) |
rpc_srv_blobMap(rpc_srv_t * __restrict srv, rpc_blob_t * __restrict blob) |
{ |
{ |
int f; |
int f; |
Line 155 rpc_srv_blobMap(rpc_srv_t * __restrict srv, rpc_blob_t
|
Line 168 rpc_srv_blobMap(rpc_srv_t * __restrict srv, rpc_blob_t
|
* @blob = Mapped BLOB element |
* @blob = Mapped BLOB element |
* return: none |
* return: none |
*/ |
*/ |
inline void | void |
rpc_srv_blobUnmap(rpc_blob_t * __restrict blob) |
rpc_srv_blobUnmap(rpc_blob_t * __restrict blob) |
{ |
{ |
if (blob && blob->blob_data) { |
if (blob && blob->blob_data) { |
Line 171 rpc_srv_blobUnmap(rpc_blob_t * __restrict blob)
|
Line 184 rpc_srv_blobUnmap(rpc_blob_t * __restrict blob)
|
* @blob = Mapped BLOB element |
* @blob = Mapped BLOB element |
* return: -1 error or 0 ok |
* return: -1 error or 0 ok |
*/ |
*/ |
inline int | int |
rpc_srv_blobFree(rpc_srv_t * __restrict srv, rpc_blob_t * __restrict blob) |
rpc_srv_blobFree(rpc_srv_t * __restrict srv, rpc_blob_t * __restrict blob) |
{ |
{ |
char szFName[MAXPATHLEN]; |
char szFName[MAXPATHLEN]; |
Line 182 rpc_srv_blobFree(rpc_srv_t * __restrict srv, rpc_blob_
|
Line 195 rpc_srv_blobFree(rpc_srv_t * __restrict srv, rpc_blob_
|
} else |
} else |
rpc_srv_blobUnmap(blob); |
rpc_srv_blobUnmap(blob); |
|
|
|
schedCancelby(srv->srv_blob.root, taskTIMER, CRITERIA_ARG, blob, NULL); |
|
|
memset(szFName, 0, sizeof szFName); |
memset(szFName, 0, sizeof szFName); |
snprintf(szFName, sizeof szFName, BLOB_FILE, AIT_GET_STRZ(&srv->srv_blob.dir), blob->blob_var); |
snprintf(szFName, sizeof szFName, BLOB_FILE, AIT_GET_STRZ(&srv->srv_blob.dir), blob->blob_var); |
if (unlink(szFName) == -1) { |
if (unlink(szFName) == -1) { |
Line 272 rpc_srv_recvBLOB(rpc_cli_t * __restrict cli, rpc_blob_
|
Line 287 rpc_srv_recvBLOB(rpc_cli_t * __restrict cli, rpc_blob_
|
* @cli = Client instance |
* @cli = Client instance |
* @var = BLOB variable |
* @var = BLOB variable |
* @data = BLOB data |
* @data = BLOB data |
|
* @tout = BLOB live on server timeout in seconds, if =0 default timeout |
* return: -1 error, 0 ok, 1 remote error |
* return: -1 error, 0 ok, 1 remote error |
*/ |
*/ |
int |
int |
rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t * __restrict var, void * __restrict data) | rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t * __restrict var, |
| void * __restrict data, int tout) |
{ |
{ |
int ret, len; |
int ret, len; |
uint8_t *pos; |
uint8_t *pos; |
Line 291 rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
Line 308 rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
rpc_addPktSession(&hdr.hdr_session, cli->cli_parent); |
rpc_addPktSession(&hdr.hdr_session, cli->cli_parent); |
hdr.hdr_cmd = set; |
hdr.hdr_cmd = set; |
hdr.hdr_var = 0; |
hdr.hdr_var = 0; |
hdr.hdr_ret = 0; | hdr.hdr_ret = tout; |
hdr.hdr_len = htonl(AIT_LEN(var)); |
hdr.hdr_len = htonl(AIT_LEN(var)); |
|
|
/* send SET request */ |
/* send SET request */ |
Line 330 rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
Line 347 rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
} |
} |
|
|
if (hdr.hdr_cmd != error) { |
if (hdr.hdr_cmd != error) { |
|
AIT_SET_BLOB(var, ntohl(hdr.hdr_var), ntohl(hdr.hdr_len)); |
|
|
if (ntohl(hdr.hdr_len) != AIT_LEN(var)) { |
if (ntohl(hdr.hdr_len) != AIT_LEN(var)) { |
|
rpc_cli_delBLOB(cli, var); |
|
AIT_NEW_BLOB(var, ntohl(hdr.hdr_len)); |
|
|
rpc_SetErr(ECANCELED, "Bad return length packet"); |
rpc_SetErr(ECANCELED, "Bad return length packet"); |
return 1; |
return 1; |
} |
} |
|
|
AIT_SET_BLOB(var, ntohl(hdr.hdr_var), ntohl(hdr.hdr_len)); |
|
} |
} |
|
|
return hdr.hdr_cmd == error; |
return hdr.hdr_cmd == error; |
Line 507 rpc_cli_delBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
Line 527 rpc_cli_delBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
* @data = BLOB data, must be e_free after use! |
* @data = BLOB data, must be e_free after use! |
* return: -1 error, 0 ok, 1 remote error |
* return: -1 error, 0 ok, 1 remote error |
*/ |
*/ |
inline int | int |
rpc_cli_getBLOB(rpc_cli_t * __restrict cli, ait_val_t * __restrict var, void ** __restrict data) |
rpc_cli_getBLOB(rpc_cli_t * __restrict cli, ait_val_t * __restrict var, void ** __restrict data) |
{ |
{ |
int ret; |
int ret; |