You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "fjpanag (via GitHub)" <gi...@apache.org> on 2023/06/19 15:44:19 UTC

[GitHub] [nuttx] fjpanag opened a new pull request, #9576: sendfile: Fixed behavior os sendfile when count is set to zero.

fjpanag opened a new pull request, #9576:
URL: https://github.com/apache/nuttx/pull/9576

   ## Summary
   
   If `sendfile()` is called with a zero count, it will nevertheless try to send the data.
   This is mostly meaningless, it causes waste of resources, and in some cases delays.
   
   For example, in case of just copying a file [unneeded buffers are allocated](https://github.com/apache/nuttx/blob/master/fs/vfs/fs_sendfile.c#L74), or in case of TCP the code waits for (no) data to be transmitted [till the socket timeouts](https://github.com/apache/nuttx/blob/master/net/tcp/tcp_sendfile.c#L527).
   
   This commit adds special handling for this case, allowing `sendfile()` to return immediately zero.  
   The new behavior is in line with the Linux variant of `sendfile()`, as tested with [this](https://github.com/fjpanag/code_for_nuttx/blob/main/ftp/ftpc.c) FTP client.
   
   For more information, see the discussion [here](https://lists.apache.org/thread/gls3rr8h4ggbwgk4skq1j0txoyd94jrf).
   
   ## Impact
   
   Proper handling of this edge case, without waste of resources, or needless delays.
   
   ## Testing
   
   *Pending. I will comment back when this is tested on actual hardware.*
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] acassis commented on a diff in pull request #9576: sendfile: Fixed behavior of sendfile when count is set to zero.

Posted by "acassis (via GitHub)" <gi...@apache.org>.
acassis commented on code in PR #9576:
URL: https://github.com/apache/nuttx/pull/9576#discussion_r1236026431


##########
fs/vfs/fs_sendfile.c:
##########
@@ -244,6 +244,11 @@ static ssize_t copyfile(FAR struct file *outfile, FAR struct file *infile,
 ssize_t file_sendfile(FAR struct file *outfile, FAR struct file *infile,
                       off_t *offset, size_t count)
 {
+  if (count == 0)
+    {
+      return 0;

Review Comment:
   please add a nwarn() to let the user know that is tried to send a packet with 0 bytes. I think that kind message could have helped you with your application! ;-)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 merged pull request #9576: sendfile: Fixed behavior of sendfile when count is set to zero.

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 merged PR #9576:
URL: https://github.com/apache/nuttx/pull/9576


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] fjpanag commented on a diff in pull request #9576: sendfile: Fixed behavior of sendfile when count is set to zero.

Posted by "fjpanag (via GitHub)" <gi...@apache.org>.
fjpanag commented on code in PR #9576:
URL: https://github.com/apache/nuttx/pull/9576#discussion_r1237437365


##########
fs/vfs/fs_sendfile.c:
##########
@@ -244,6 +244,11 @@ static ssize_t copyfile(FAR struct file *outfile, FAR struct file *infile,
 ssize_t file_sendfile(FAR struct file *outfile, FAR struct file *infile,
                       off_t *offset, size_t count)
 {
+  if (count == 0)
+    {
+      return 0;

Review Comment:
   Done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org