mirror of
https://github.com/apache/nuttx.git
synced 2026-06-07 09:18:00 +08:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user