From 2873f33bc455bea4d0a4ed49d0f206a5020eec64 Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Wed, 12 May 2021 07:09:52 +0900 Subject: [PATCH] fs: nfs: Fix to read a large packet in TCP mode Summary: - I noticed that receiving a read large packet (e.g. 2KB) in TCP mode does not work correctly - Actually, rpcclnt_receive() only received up to MSS - This commit fixes this issue Impact: - TCP mode only Testing: - Tested with Ubuntu 18.04 (x86_64) - Tested with spresense:rndis (defconfig will be updated later) Signed-off-by: Masayuki Ishikawa --- fs/nfs/rpc_clnt.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/fs/nfs/rpc_clnt.c b/fs/nfs/rpc_clnt.c index 93579667a45..46ee90b151b 100644 --- a/fs/nfs/rpc_clnt.c +++ b/fs/nfs/rpc_clnt.c @@ -359,6 +359,7 @@ static int rpcclnt_receive(FAR struct rpcclnt *rpc, { uint32_t mark; int error = 0; + int offset = 0; /* Receive the record marking(RM) for stream only */ @@ -388,12 +389,20 @@ static int rpcclnt_receive(FAR struct rpcclnt *rpc, resplen = mark; } - error = psock_recv(&rpc->rc_so, reply, resplen, 0); - if (error < 0) + do { - ferr("ERROR: psock_recv response failed: %d\n", error); - return error; + error = psock_recv(&rpc->rc_so, reply + offset, resplen, 0); + + if (error < 0) + { + ferr("ERROR: psock_recv response failed: %d\n", error); + return error; + } + + resplen -= error; + offset += error; } + while (rpc->rc_sotype == SOCK_STREAM && resplen != 0); return OK; }