--- libaitrpc/src/cli.c 2015/06/28 22:11:30 1.25.2.3 +++ libaitrpc/src/cli.c 2015/06/29 22:29:25 1.25.2.4 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: cli.c,v 1.25.2.3 2015/06/28 22:11:30 misho Exp $ +* $Id: cli.c,v 1.25.2.4 2015/06/29 22:29:25 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -158,6 +158,7 @@ rpc_cli_closeBLOBClient(rpc_cli_t ** __restrict cli) rpc_cli_t * rpc_cli_openClient(u_char InstID, int netBuf, const char *csHost, u_short Port, int proto) { + int n = 1; rpc_cli_t *cli = NULL; sockaddr_t sa = E_SOCKADDR_INIT; @@ -218,11 +219,13 @@ rpc_cli_openClient(u_char InstID, int netBuf, const ch LOGERR; goto err; } - if (cli->cli_id == SOCK_STREAM) + if (cli->cli_id == SOCK_STREAM) { + setsockopt(cli->cli_sock, IPPROTO_TCP, TCP_NODELAY, &n, sizeof n); if (connect(cli->cli_sock, &cli->cli_sa.sa, cli->cli_sa.sa.sa_len) == -1) { LOGERR; goto err; } + } if (cli->cli_id == SOCK_DGRAM) { sockaddr_t sa2; @@ -429,8 +432,10 @@ rpc_pkt_Request(ait_val_t * __restrict pkt, rpc_sess_t /* calc estimated length */ estlen = ait_resideVars(vars) + len; - if (estlen > AIT_LEN(pkt)) - AIT_RE_BUF(pkt, estlen); + if (estlen > AIT_LEN(pkt)) { + rpc_SetErr(EMSGSIZE, "Message too long"); + return -1; + } buf = AIT_GET_BUF(pkt); /* prepare RPC call */ @@ -581,10 +586,12 @@ rpc_cli_execCall(rpc_cli_t *cli, int noreply, u_short if (out_vars) *out_vars = NULL; - if ((wlen = rpc_pkt_Request(&cli->cli_buf, cli->cli_parent, tag, in_vars, noreply, type, seq)) == -1) + if ((wlen = rpc_pkt_Request(&cli->cli_buf, cli->cli_parent, tag, + in_vars, noreply, type, seq)) == -1) return -1; - if ((wlen = rpc_pkt_Send(cli->cli_sock, cli->cli_id, &cli->cli_sa, &cli->cli_buf, wlen)) == -1) + if ((wlen = rpc_pkt_Send(cli->cli_sock, cli->cli_id, &cli->cli_sa, + &cli->cli_buf, wlen)) == -1) return -1; if (!wlen) /* closed rpc connection */ return 1; @@ -592,12 +599,14 @@ rpc_cli_execCall(rpc_cli_t *cli, int noreply, u_short if (noreply) /* we not want reply */ return 0; - if ((wlen = rpc_pkt_Receive(cli->cli_sock, cli->cli_id, &cli->cli_sa, &cli->cli_buf, seq)) == -1) + if ((wlen = rpc_pkt_Receive(cli->cli_sock, cli->cli_id, &cli->cli_sa, + &cli->cli_buf, seq)) == -1) return -1; if (!wlen) /* closed rpc connection */ return 1; - if ((wlen = rpc_pkt_Replay(&cli->cli_buf, cli->cli_parent, tag, out_vars, type)) == -1) + if ((wlen = rpc_pkt_Replay(&cli->cli_buf, cli->cli_parent, tag, + out_vars, type)) == -1) return -1; return 0;