--- libaitrpc/src/cli.c 2012/03/29 01:34:16 1.8 +++ libaitrpc/src/cli.c 2012/05/14 15:35:58 1.9.2.2 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: cli.c,v 1.8 2012/03/29 01:34:16 misho Exp $ +* $Id: cli.c,v 1.9.2.2 2012/05/14 15:35:58 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -60,9 +60,7 @@ rpc_cli_openBLOBClient(rpc_cli_t * __restrict rpccli, io_sockaddr_t sa; int n; - if (!rpccli || - (rpccli->cli_sa.sa.sa_family != AF_INET && rpccli->cli_sa.sa.sa_family != AF_INET6 && - rpccli->cli_sa.sa.sa_family != AF_LOCAL)) { + if (!rpccli) { rpc_SetErr(EINVAL, "Invalid parameters can`t connect to BLOB server"); return NULL; } @@ -158,51 +156,17 @@ rpc_cli_openClient(u_int ProgID, u_int ProcID, int net u_short family, const char *csHost, u_short Port) { rpc_cli_t *cli = NULL; - struct hostent *host = NULL; io_sockaddr_t sa; int n; - if (!csHost || (family != AF_INET && family != AF_INET6 && family != AF_LOCAL)) { - rpc_SetErr(EINVAL, "Invalid parameters can`t connect to RPC server ..."); + if (!io_gethostbyname(csHost, Port, &sa)) return NULL; - } if (!Port) Port = RPC_DEFPORT; if (!netBuf) netBuf = BUFSIZ; if (!Timeout) Timeout = DEF_RPC_TIMEOUT; - if (csHost && family != AF_LOCAL) { - host = gethostbyname2(csHost, family); - if (!host) { - rpc_SetErr(h_errno, "%s", hstrerror(h_errno)); - return NULL; - } - } - memset(&sa, 0, sizeof sa); - sa.sa.sa_family = family; - switch (family) { - case AF_INET: - sa.sin.sin_len = sizeof(struct sockaddr_in); - sa.sin.sin_port = htons(Port); - if (csHost) - memcpy(&sa.sin.sin_addr, host->h_addr, host->h_length); - break; - case AF_INET6: - sa.sin6.sin6_len = sizeof(struct sockaddr_in6); - sa.sin6.sin6_port = htons(Port); - if (csHost) - memcpy(&sa.sin6.sin6_addr, host->h_addr, host->h_length); - break; - case AF_LOCAL: - sa.sun.sun_len = sizeof(struct sockaddr_un); - if (csHost) - strlcpy(sa.sun.sun_path, csHost, sizeof sa.sun.sun_path); - break; - default: - rpc_SetErr(EINVAL, "Invalid parameters can`t connect to RPC server ..."); - return NULL; - } cli = malloc(sizeof(rpc_cli_t)); if (!cli) { @@ -227,7 +191,7 @@ rpc_cli_openClient(u_int ProgID, u_int ProcID, int net memcpy(&cli->cli_sa, &sa, sizeof cli->cli_sa); /* connect to RPC server */ - cli->cli_sock = socket(family, SOCK_STREAM, 0); + cli->cli_sock = socket(cli->cli_sa.sa.sa_family, SOCK_STREAM, 0); if (cli->cli_sock == -1) { LOGERR; free(cli->cli_parent); @@ -299,14 +263,13 @@ int rpc_cli_execCall(rpc_cli_t *cli, int noreply, const char *csModule, const char *csFunc, array_t * __restrict in_vars, array_t ** __restrict out_vars) { - fd_set fds; u_char *buf; rpc_func_t func; struct tagRPCCall *rpc; int ret = 0, wlen = sizeof(struct tagRPCCall); - struct timeval tv = { DEF_RPC_TIMEOUT, 0 }; uint16_t tag, crc; uint32_t hash; + struct pollfd pfd; if (!cli || !csFunc) { rpc_SetErr(EINVAL, "Can`t execute call because parameter is null or invalid!"); @@ -377,9 +340,10 @@ rpc_cli_execCall(rpc_cli_t *cli, int noreply, const ch } /* reply from RPC server */ - FD_ZERO(&fds); - FD_SET(cli->cli_sock, &fds); - if ((ret = select(cli->cli_sock + 1, &fds, NULL, NULL, &tv)) < 1) { + pfd.fd = cli->cli_sock; + pfd.events = POLLIN | POLLPRI; + if ((ret = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) == -1 || + pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { if (ret) LOGERR; else