libc/sendfile: fix lib_sendfile() partial send

MIRTOS-482

Fixing the behavior of sending only a few bytes of a file

Signed-off-by: Peter Bee <bijunda1@xiaomi.com>
Change-Id: Ieae600028b79794ede3ac576c2cd015d8df58b05
This commit is contained in:
Peter Bee
2021-04-06 14:26:42 +08:00
committed by bijunda1
parent 48b129f412
commit 487101234b
+13 -5
View File
@@ -150,7 +150,13 @@ ssize_t sendfile(int outfd, int infd, off_t *offset, size_t count)
{
/* Read a buffer of data from the infd */
nbytesread = _NX_READ(infd, iobuffer, CONFIG_LIB_SENDFILE_BUFSIZE);
nbytesread = count - ntransferred;
if (nbytesread > CONFIG_LIB_SENDFILE_BUFSIZE)
{
nbytesread = CONFIG_LIB_SENDFILE_BUFSIZE;
}
nbytesread = _NX_READ(infd, iobuffer, nbytesread);
/* Check for end of file */
@@ -210,15 +216,17 @@ ssize_t sendfile(int outfd, int infd, off_t *offset, size_t count)
if (nbyteswritten >= 0)
{
/* Advance the buffer pointer and decrement the number of bytes
* remaining in the iobuffer. Typically, nbytesread will now
* be zero.
/* Advance the buffer pointer and decrement the number of
* bytes remaining in the iobuffer. Typically, nbytesread
* will now be zero.
*/
wrbuffer += nbyteswritten;
nbytesread -= nbyteswritten;
/* Increment the total number of bytes successfully transferred. */
/* Increment the total number of bytes successfully
* transferred.
*/
ntransferred += nbyteswritten;
}