This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new aee20c39231 net/tcp: Return the count of a partial sendfile().
aee20c39231 is described below
commit aee20c39231a4da8a3c1ee7f2f3c00ae711c5f62
Author: Marco Casaroli <[email protected]>
AuthorDate: Tue Nov 17 13:21:09 2026 +0100
net/tcp: Return the count of a partial sendfile().
When SO_SNDTIMEO is set, tcp_sendfile() waits for progress with that
timeout. After a wait with no new acknowledgment, it returned -EAGAIN,
also when some bytes went out in an earlier wait. A signal had the same
effect with -EINTR. The caller cannot know that these bytes went out and
sends them again.
Also *offset was the file position after the last file read, not the
offset of the caller plus the bytes sent. A retransmission reads the
file again at an earlier position, and the result is wrong after it. On
an error, *offset was set to the file position, also when the caller gave
another offset. Without an offset, the file position was left after the
last file read, also after a retransmission.
When the wait ends with a timeout or a signal after some bytes went
out, return the count, as write() does. Move *offset by the count.
Without an offset, put the file position after the bytes sent.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <[email protected]>
---
net/tcp/tcp_sendfile.c | 42 +++++++++++++++++++++---------------------
1 file changed, 21 insertions(+), 21 deletions(-)
diff --git a/net/tcp/tcp_sendfile.c b/net/tcp/tcp_sendfile.c
index dc90e3142d7..c44a2798e4b 100644
--- a/net/tcp/tcp_sendfile.c
+++ b/net/tcp/tcp_sendfile.c
@@ -551,40 +551,40 @@ errout_locked:
#endif
conn_dev_unlock(&conn->sconn, conn->dev);
- /* Return the current file position */
+ /* A timeout or a signal can end the wait after some bytes went out.
+ * Then return the count of these bytes. Return the error only when no
+ * byte went out.
+ */
- if (offset)
+ if (ret < 0 && state.snd_sent <= 0)
{
- /* Use lseek to get the current file position */
+ state.snd_sent = ret;
+ }
- off_t curpos = file_seek(infile, 0, SEEK_CUR);
+ if (offset)
+ {
+ /* Move *offset over the bytes sent and restore the file position */
- if (curpos < 0)
+ if (state.snd_sent > 0)
{
- return curpos;
+ *offset += state.snd_sent;
}
- /* Return the current file position */
-
- *offset = curpos;
-
- /* Use lseek again to restore the original file position */
-
startpos = file_seek(infile, startpos, SEEK_SET);
- if (startpos < 0)
- {
- return startpos;
- }
}
-
- if (ret < 0)
+ else if (state.snd_sent > 0)
{
- return ret;
+ /* Put the file position after the bytes sent */
+
+ startpos = file_seek(infile, startpos + state.snd_sent, SEEK_SET);
}
- else
+
+ if (startpos < 0)
{
- return state.snd_sent;
+ return startpos;
}
+
+ return state.snd_sent;
}
#endif /* CONFIG_NET_SENDFILE && CONFIG_NET_TCP && NET_TCP_HAVE_STACK */