summaryrefslogtreecommitdiff
path: root/nuttx
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-09-05 01:59:54 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-09-05 01:59:54 +0000
commit26ee5f5668ab205c940feaed71f1ba159a3b85b0 (patch)
treeed9a1833777f8d26e866a9eedb2368ef84ad7b19 /nuttx
parent31fdad493b7fbf88dd5caf6ad4ac7632d508d9c5 (diff)
downloadpx4-nuttx-26ee5f5668ab205c940feaed71f1ba159a3b85b0.tar.gz
px4-nuttx-26ee5f5668ab205c940feaed71f1ba159a3b85b0.tar.bz2
px4-nuttx-26ee5f5668ab205c940feaed71f1ba159a3b85b0.zip
Oops.. sendfile() was not keeping track of the number bytes transferred or handling partial writes correctly.
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5091 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx')
-rw-r--r--nuttx/lib/misc/lib_sendfile.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/nuttx/lib/misc/lib_sendfile.c b/nuttx/lib/misc/lib_sendfile.c
index 7d7a781f5..b7959482e 100644
--- a/nuttx/lib/misc/lib_sendfile.c
+++ b/nuttx/lib/misc/lib_sendfile.c
@@ -114,6 +114,7 @@
ssize_t sendfile(int outfd, int infd, off_t *offset, size_t count)
{
FAR uint8_t *iobuffer;
+ FAR uint8_t *wrbuffer;
off_t startpos = 0;
ssize_t nbytesread;
ssize_t nbyteswritten;
@@ -205,18 +206,31 @@ ssize_t sendfile(int outfd, int infd, off_t *offset, size_t count)
* conclusion.
*/
+ wrbuffer = iobuffer;
do
{
- nbyteswritten = write(outfd, iobuffer, nbytesread);
+ nbyteswritten = write(outfd, wrbuffer, nbytesread);
- /* Check for a complete (or parial write) */
+ /* Check for a complete (or parial write). write() should not
+ * return zero.
+ */
if (nbyteswritten >= 0)
{
- nbytesread -= nbyteswritten;
+ /* 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. */
+
+ ntransferred += nbyteswritten;
}
- /* Otherwise an error occurred (write should not return zero) */
+ /* Otherwise an error occurred */
else
{