version 1.7.2.5, 2012/05/16 13:32:47
|
version 1.8.2.1, 2012/05/28 08:02:00
|
Line 81 again:
|
Line 81 again:
|
return NULL; |
return NULL; |
} |
} |
|
|
blob = malloc(sizeof(rpc_blob_t)); | blob = io_malloc(sizeof(rpc_blob_t)); |
if (!blob) { |
if (!blob) { |
LOGERR; |
LOGERR; |
close(f); |
close(f); |
Line 92 again:
|
Line 92 again:
|
blob->blob_data = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, f, 0); |
blob->blob_data = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, f, 0); |
if (blob->blob_data == MAP_FAILED) { |
if (blob->blob_data == MAP_FAILED) { |
LOGERR; |
LOGERR; |
free(blob); | io_free(blob); |
close(f); |
close(f); |
unlink(szFName); |
unlink(szFName); |
return NULL; |
return NULL; |
Line 247 rpc_srv_recvBLOB(rpc_cli_t * __restrict cli, rpc_blob_
|
Line 247 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) { |
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 || |
if ((len = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) < 1 || |
pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { |
pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { |
LOGERR; | if (len) |
| LOGERR; |
| else |
| rpc_SetErr(ETIMEDOUT, "Timeout reached! Server not respond"); |
return -1; |
return -1; |
} |
} |
|
|
Line 282 rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
Line 285 rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
if (!cli || !var || !data) { |
if (!cli || !var || !data) { |
rpc_SetErr(EINVAL, "Invalid arguments"); |
rpc_SetErr(EINVAL, "Invalid arguments"); |
return -1; |
return -1; |
} | } else |
| memset(&hdr, 0, sizeof hdr); |
|
|
rpc_addPktSession(&hdr.hdr_session, cli->cli_parent); |
rpc_addPktSession(&hdr.hdr_session, cli->cli_parent); |
hdr.hdr_cmd = set; |
hdr.hdr_cmd = set; |
Line 294 rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
Line 298 rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
hdr.hdr_crc = htons(crcFletcher16((u_short*) &hdr, sizeof hdr / 2)); |
hdr.hdr_crc = htons(crcFletcher16((u_short*) &hdr, sizeof hdr / 2)); |
|
|
/* send SET request */ |
/* send SET 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; |
|
return -1; |
|
} |
if (send(cli->cli_sock, &hdr, sizeof hdr, MSG_NOSIGNAL) == -1) { |
if (send(cli->cli_sock, &hdr, sizeof hdr, MSG_NOSIGNAL) == -1) { |
LOGERR; |
LOGERR; |
return -1; |
return -1; |
Line 307 rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
Line 318 rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
} |
} |
|
|
/* wait for reply */ |
/* wait for reply */ |
pfd.fd = cli->cli_sock; |
|
pfd.events = POLLIN | POLLPRI; |
pfd.events = POLLIN | POLLPRI; |
if ((ret = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) < 1 || |
if ((ret = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) < 1 || |
pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { |
pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { |
Line 346 rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
Line 356 rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
* |
* |
* @cli = Client instance |
* @cli = Client instance |
* @var = BLOB variable |
* @var = BLOB variable |
* @data = BLOB data, must be free after use! | * @data = BLOB data, must be io_free after use! |
* return: -1 error, 0 ok, 1 remote error |
* return: -1 error, 0 ok, 1 remote error |
*/ |
*/ |
int |
int |
Line 362 rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
Line 372 rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
return -1; |
return -1; |
} |
} |
|
|
*data = malloc(AIT_LEN(var)); | *data = io_malloc(AIT_LEN(var)); |
if (!*data) { |
if (!*data) { |
LOGERR; |
LOGERR; |
return -1; |
return -1; |
} else | } else { |
| memset(&hdr, 0, sizeof hdr); |
memset(*data, 0, AIT_LEN(var)); |
memset(*data, 0, AIT_LEN(var)); |
|
} |
|
|
rpc_addPktSession(&hdr.hdr_session, cli->cli_parent); |
rpc_addPktSession(&hdr.hdr_session, cli->cli_parent); |
hdr.hdr_cmd = get; |
hdr.hdr_cmd = get; |
Line 379 rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
Line 391 rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
hdr.hdr_crc = htons(crcFletcher16((u_short*) &hdr, sizeof hdr / 2)); |
hdr.hdr_crc = htons(crcFletcher16((u_short*) &hdr, sizeof hdr / 2)); |
|
|
/* send GET request */ |
/* 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; |
|
io_free(*data); |
|
*data = NULL; |
|
return -1; |
|
} |
if (send(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) { |
if (send(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) { |
LOGERR; |
LOGERR; |
free(*data); | io_free(*data); |
*data = NULL; |
*data = NULL; |
return -1; |
return -1; |
} |
} |
|
|
/* receive BLOB from server */ |
/* receive BLOB from server */ |
pfd.fd = cli->cli_sock; |
|
pfd.events = POLLIN | POLLPRI; |
pfd.events = POLLIN | POLLPRI; |
for (ret = AIT_LEN(var), pos = *data; ret > 0; ret -= len, pos += len) { |
for (ret = AIT_LEN(var), pos = *data; ret > 0; ret -= len, pos += len) { |
if ((len = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) < 1 || |
if ((len = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) < 1 || |
pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { |
pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { |
LOGERR; |
LOGERR; |
free(*data); | io_free(*data); |
*data = NULL; |
*data = NULL; |
return -1; |
return -1; |
} |
} |
|
|
if ((len = recv(cli->cli_sock, pos, ret, 0)) == -1) { |
if ((len = recv(cli->cli_sock, pos, ret, 0)) == -1) { |
LOGERR; |
LOGERR; |
free(*data); | io_free(*data); |
*data = NULL; |
*data = NULL; |
return -1; |
return -1; |
} |
} |
Line 413 rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
Line 433 rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
LOGERR; |
LOGERR; |
else |
else |
rpc_SetErr(ETIMEDOUT, "Timeout reached! Server not respond"); |
rpc_SetErr(ETIMEDOUT, "Timeout reached! Server not respond"); |
free(*data); | io_free(*data); |
*data = NULL; |
*data = NULL; |
return 1; |
return 1; |
} |
} |
if (recv(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) { |
if (recv(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) { |
LOGERR; |
LOGERR; |
free(*data); | io_free(*data); |
*data = NULL; |
*data = NULL; |
return 1; |
return 1; |
} |
} |
Line 428 rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
Line 448 rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
hdr.hdr_crc ^= hdr.hdr_crc; |
hdr.hdr_crc ^= hdr.hdr_crc; |
if (ret != crcFletcher16((u_short*) &hdr, sizeof hdr / 2)) { |
if (ret != crcFletcher16((u_short*) &hdr, sizeof hdr / 2)) { |
rpc_SetErr(ERPCMISMATCH, "Bad CRC BLOB packet"); |
rpc_SetErr(ERPCMISMATCH, "Bad CRC BLOB packet"); |
free(*data); | io_free(*data); |
*data = NULL; |
*data = NULL; |
return 1; |
return 1; |
} |
} |
if (hdr.hdr_cmd != error) { |
if (hdr.hdr_cmd != error) { |
if (ntohl(hdr.hdr_len) != AIT_LEN(var)) { |
if (ntohl(hdr.hdr_len) != AIT_LEN(var)) { |
rpc_SetErr(ECANCELED, "Bad return length packet"); |
rpc_SetErr(ECANCELED, "Bad return length packet"); |
free(*data); | io_free(*data); |
*data = NULL; |
*data = NULL; |
return 1; |
return 1; |
} |
} |
Line 461 rpc_cli_delBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
Line 481 rpc_cli_delBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
if (!cli || !var) { |
if (!cli || !var) { |
rpc_SetErr(EINVAL, "Invalid arguments"); |
rpc_SetErr(EINVAL, "Invalid arguments"); |
return -1; |
return -1; |
} | } else |
| memset(&hdr, 0, sizeof hdr); |
|
|
rpc_addPktSession(&hdr.hdr_session, cli->cli_parent); |
rpc_addPktSession(&hdr.hdr_session, cli->cli_parent); |
hdr.hdr_cmd = unset; |
hdr.hdr_cmd = unset; |
Line 473 rpc_cli_delBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
Line 494 rpc_cli_delBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
hdr.hdr_crc = htons(crcFletcher16((u_short*) &hdr, sizeof hdr / 2)); |
hdr.hdr_crc = htons(crcFletcher16((u_short*) &hdr, sizeof hdr / 2)); |
|
|
/* send UNSET request */ |
/* send UNSET 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; |
|
return -1; |
|
} |
if (send(cli->cli_sock, &hdr, sizeof hdr, MSG_NOSIGNAL) == -1) { |
if (send(cli->cli_sock, &hdr, sizeof hdr, MSG_NOSIGNAL) == -1) { |
LOGERR; |
LOGERR; |
return -1; |
return -1; |
} |
} |
|
|
/* wait for reply */ |
/* wait for reply */ |
pfd.fd = cli->cli_sock; |
|
pfd.events = POLLIN | POLLPRI; |
pfd.events = POLLIN | POLLPRI; |
if ((ret = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) < 1 || |
if ((ret = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) < 1 || |
pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { |
pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { |
Line 509 rpc_cli_delBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
Line 536 rpc_cli_delBLOB(rpc_cli_t * __restrict cli, ait_val_t
|
* |
* |
* @cli = Client instance |
* @cli = Client instance |
* @var = BLOB variable |
* @var = BLOB variable |
* @data = BLOB data, must be free after use! | * @data = BLOB data, must be io_free after use! |
* return: -1 error, 0 ok, 1 remote error |
* return: -1 error, 0 ok, 1 remote error |
*/ |
*/ |
inline int |
inline int |