--- libaitrpc/src/blob.c 2012/03/29 01:34:16 1.6 +++ libaitrpc/src/blob.c 2012/05/14 08:39:05 1.7 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: blob.c,v 1.6 2012/03/29 01:34:16 misho Exp $ +* $Id: blob.c,v 1.7 2012/05/14 08:39:05 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -247,20 +247,18 @@ rpc_srv_recvBLOB(rpc_cli_t * __restrict cli, rpc_blob_ { int ret, len; uint8_t *pos; - fd_set fds; - struct timeval tv = { DEF_RPC_TIMEOUT, 0 }; + struct pollfd pfd; if (!cli || !blob || !blob->blob_data) { rpc_SetErr(EINVAL, "Invalid arguments"); return -1; - } else - tv.tv_sec = ((rpc_sess_t*) cli->cli_parent)->sess_timeout; + } + pfd.fd = cli->cli_sock; + pfd.events = POLLIN | POLLPRI; for (ret = blob->blob_len, pos = blob->blob_data; ret > 0; ret -= len, pos += len) { - FD_ZERO(&fds); - FD_SET(cli->cli_sock, &fds); - len = select(cli->cli_sock + 1, &fds, NULL, NULL, &tv); - if (len < 1) { + if ((len = poll(&pfd, 1, ((rpc_sess_t*) cli->cli_parent)->sess_timeout * 1000)) < 1 || + pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { LOGERR; return -1; } @@ -291,14 +289,12 @@ rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t int ret, len; uint8_t *pos; struct tagBLOBHdr hdr; - fd_set fds; - struct timeval tv = { DEF_RPC_TIMEOUT, 0 }; + struct pollfd pfd; if (!cli || !var || !data) { rpc_SetErr(EINVAL, "Invalid arguments"); return -1; - } else - tv.tv_sec = ((rpc_sess_t*) cli->cli_parent)->sess_timeout; + } rpc_addPktSession(&hdr.hdr_session, cli->cli_parent); hdr.hdr_cmd = set; @@ -323,15 +319,15 @@ rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t } /* wait for reply */ - FD_ZERO(&fds); - FD_SET(cli->cli_sock, &fds); - switch (select(cli->cli_sock + 1, &fds, NULL, NULL, &tv)) { - case -1: + pfd.fd = cli->cli_sock; + pfd.events = POLLIN | POLLPRI; + if ((ret = poll(&pfd, 1, ((rpc_sess_t*) cli->cli_parent)->sess_timeout * 1000)) < 1 || + pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { + if (ret) LOGERR; - return 1; - case 0: - rpc_SetErr(ETIMEDOUT, "Timeout reached! Server not responde"); - return 1; + else + rpc_SetErr(ETIMEDOUT, "Timeout reached! Server not respond"); + return -1; } if (recv(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) { LOGERR; @@ -370,15 +366,13 @@ rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t { int ret, len; uint8_t *pos; - fd_set fds; - struct timeval tv = { DEF_RPC_TIMEOUT, 0 }; + struct pollfd pfd; struct tagBLOBHdr hdr; if (!cli || !var || !data) { rpc_SetErr(EINVAL, "Invalid arguments"); return -1; - } else - tv.tv_sec = ((rpc_sess_t*) cli->cli_parent)->sess_timeout; + } *data = malloc(AIT_LEN(var)); if (!*data) { @@ -405,11 +399,11 @@ rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t } /* receive BLOB from server */ + pfd.fd = cli->cli_sock; + pfd.events = POLLIN | POLLPRI; for (ret = AIT_LEN(var), pos = *data; ret > 0; ret -= len, pos += len) { - FD_ZERO(&fds); - FD_SET(cli->cli_sock, &fds); - len = select(cli->cli_sock + 1, &fds, NULL, NULL, &tv); - if (len < 1) { + if ((len = poll(&pfd, 1, ((rpc_sess_t*) cli->cli_parent)->sess_timeout * 1000)) < 1 || + pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { LOGERR; free(*data); *data = NULL; @@ -425,19 +419,15 @@ rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t } /* wait for reply */ - FD_ZERO(&fds); - FD_SET(cli->cli_sock, &fds); - switch (select(cli->cli_sock + 1, &fds, NULL, NULL, &tv)) { - case -1: + if ((len = poll(&pfd, 1, ((rpc_sess_t*) cli->cli_parent)->sess_timeout * 1000)) < 1 || + pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { + if (len) LOGERR; - free(*data); - *data = NULL; - return 1; - case 0: - rpc_SetErr(ETIMEDOUT, "Timeout reached! Server not responde"); - free(*data); - *data = NULL; - return 1; + else + rpc_SetErr(ETIMEDOUT, "Timeout reached! Server not respond"); + free(*data); + *data = NULL; + return 1; } if (recv(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) { LOGERR; @@ -477,15 +467,13 @@ int rpc_cli_delBLOB(rpc_cli_t * __restrict cli, ait_val_t * __restrict var) { struct tagBLOBHdr hdr; - fd_set fds; - struct timeval tv = { DEF_RPC_TIMEOUT, 0 }; + struct pollfd pfd; int ret; if (!cli || !var) { rpc_SetErr(EINVAL, "Invalid arguments"); return -1; - } else - tv.tv_sec = ((rpc_sess_t*) cli->cli_parent)->sess_timeout; + } rpc_addPktSession(&hdr.hdr_session, cli->cli_parent); hdr.hdr_cmd = unset; @@ -503,15 +491,15 @@ rpc_cli_delBLOB(rpc_cli_t * __restrict cli, ait_val_t } /* wait for reply */ - FD_ZERO(&fds); - FD_SET(cli->cli_sock, &fds); - switch (select(cli->cli_sock + 1, &fds, NULL, NULL, &tv)) { - case -1: + pfd.fd = cli->cli_sock; + pfd.events = POLLIN | POLLPRI; + if ((ret = poll(&pfd, 1, ((rpc_sess_t*) cli->cli_parent)->sess_timeout * 1000)) < 1 || + pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { + if (ret) LOGERR; - return 1; - case 0: - rpc_SetErr(ETIMEDOUT, "Timeout reached! Server not responde"); - return 1; + else + rpc_SetErr(ETIMEDOUT, "Timeout reached! Server not respond"); + return 1; } if (recv(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) { LOGERR;