--- libaitrpc/src/cli.c 2013/08/22 11:52:20 1.16.8.3 +++ libaitrpc/src/cli.c 2013/08/22 14:01:00 1.16.8.6 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: cli.c,v 1.16.8.3 2013/08/22 11:52:20 misho Exp $ +* $Id: cli.c,v 1.16.8.6 2013/08/22 14:01:00 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -353,9 +353,13 @@ rpc_pkt_Receive(int sock, int type, sockaddr_t * __res return -1; } +payload: if (type == SOCK_STREAM) { memset(buf, 0, blen); ret = recv(sock, buf, blen, 0); + /* handling case for reply without payload */ + if (!ret && buf != AIT_GET_BUF(pkt)) + return (buf - AIT_GET_BUF(pkt)); } else { blen = AIT_LEN(pkt); memset(buf, 0, blen); @@ -390,12 +394,12 @@ rpc_pkt_Receive(int sock, int type, sockaddr_t * __res /* calc estimated length */ rpc = (struct tagRPCCall*) buf; - estlen = ntohs(rpc->call_len) + blen; - printf("ret = %d len=%d\n", ret, estlen); + estlen = ntohl(rpc->call_len); if (estlen > AIT_LEN(pkt)) AIT_RE_BUF(pkt, estlen); buf = AIT_GET_BUF(pkt) + blen; - blen = AIT_LEN(pkt) - blen; + blen = estlen - blen; + goto payload; } else ret += sizeof(struct tagRPCCall); } @@ -462,7 +466,7 @@ rpc_pkt_Request(ait_val_t * __restrict pkt, rpc_sess_t } /* total packet length */ - rpc->call_len = htons(len); + rpc->call_len = htonl(len); if (!nocrc) { /* calculate CRC */ @@ -503,7 +507,7 @@ rpc_pkt_Replay(ait_val_t * __restrict pkt, rpc_sess_t /* calculate CRC */ crc = ntohs(rpc->call_crc); rpc->call_crc ^= rpc->call_crc; - if (crc != crcFletcher16((u_short*) buf, ntohs(rpc->call_len) / 2)) { + if (crc != crcFletcher16((u_short*) buf, ntohl(rpc->call_len) / 2)) { rpc_SetErr(ERPCMISMATCH, "Bad CRC RPC packet"); return -1; } @@ -529,7 +533,7 @@ rpc_pkt_Replay(ait_val_t * __restrict pkt, rpc_sess_t rpc_SetErr(EMSGSIZE, "Reply RPC packet not enough buffer space ..."); return -1; } - if (len > ntohs(rpc->call_len) - sizeof(struct tagRPCCall)) { + if (len > ntohl(rpc->call_len) - sizeof(struct tagRPCCall)) { rpc_SetErr(EMSGSIZE, "Reply RPC packet is too short ..."); return -1; }