--- libaitrpc/src/cli.c 2013/08/23 13:34:52 1.17.2.2 +++ libaitrpc/src/cli.c 2013/11/15 09:18:38 1.19.6.2 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: cli.c,v 1.17.2.2 2013/08/23 13:34:52 misho Exp $ +* $Id: cli.c,v 1.19.6.2 2013/11/15 09:18:38 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -303,14 +303,12 @@ rpc_pkt_Receive(int sock, int type, sockaddr_t * __res if (type == SOCK_STREAM) ret = rpc_Read(sock, type, !estlen ? MSG_PEEK : 0, NULL, buf, blen); else - ret = rpc_Read(sock, type, 0, sa, buf, AIT_LEN(pkt)); - if (ret < 1) { - LOGERR; + ret = rpc_Read(sock, type, !estlen ? MSG_PEEK : 0, sa, buf, blen); + if (ret < 1) return -1; - } /* check for response from known address */ - if (type == SOCK_STREAM && !estlen) { + if (!estlen) { /* 1st read for RPC header */ if (ret < sizeof(struct tagRPCCall)) { rpc_SetErr(ERPCMISMATCH, "Short RPC packet %d bytes", ret); @@ -324,14 +322,17 @@ rpc_pkt_Receive(int sock, int type, sockaddr_t * __res AIT_RE_BUF(pkt, estlen); buf = AIT_GET_BUF(pkt); blen = estlen; + rpc = (struct tagRPCCall*) buf; continue; } + /* compiler optimize loop if while(0) and stop working 'continue' on some platforms */ break; } while (42); - if (ret < sizeof(struct tagRPCCall)) { - rpc_SetErr(ERPCMISMATCH, "Short RPC packet %d bytes", ret); + if (ret < sizeof(struct tagRPCCall) || estlen != ret) { + rpc_SetErr(ERPCMISMATCH, "RPC packet mismatch estimate %d bytes, but received %d\n", + estlen, ret); return -1; } @@ -378,7 +379,7 @@ rpc_pkt_Request(ait_val_t * __restrict pkt, rpc_sess_t rpc->call_argc = htons(array_Size(vars)); /* set reply */ - rpc->call_req.flags = noreply ? RPC_NOREPLY : RPC_REPLY; + rpc->call_req.flags = (uint64_t) htonl(noreply ? RPC_NOREPLY : RPC_REPLY); if (array_Size(vars)) { /* marshaling variables */