You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/01/18 19:20:48 UTC

[GitHub] [incubator-nuttx-apps] xiaoxiang781216 commented on a change in pull request #971: netutils/ftpc: implemented FTPC_OVER_SENDFILE option.

xiaoxiang781216 commented on a change in pull request #971:
URL: https://github.com/apache/incubator-nuttx-apps/pull/971#discussion_r787075571



##########
File path: netutils/ftpc/ftpc_putfile.c
##########
@@ -65,11 +67,60 @@
  *
  ****************************************************************************/
 
+#ifdef CONFIG_FTPC_OVER_SENDFILE
 static int ftpc_sendbinary(FAR struct ftpc_session_s *session,
-                           FAR FILE *linstream, FILE *routstream)
+                           int linfd)
+{
+  struct stat stat_buf;
+  off_t offset;
+  ssize_t result;
+  ssize_t len;
+
+  if (fstat(linfd, &stat_buf) == -1)
+    {
+      ftpc_xfrabort(session, NULL);
+      return ERROR;
+    }
+
+  /* Loop until the entire file is sent */
+
+  offset = session->offset;
+  len = stat_buf.st_size - offset;
+
+  while (len > 0)
+    {
+      result = sendfile(session->data.sd, linfd, &offset, len);
+
+      if (result == -1 && errno == EAGAIN)
+        {
+          continue;
+        }
+      else if (result == -1)
+        {
+          ftpc_xfrabort(session, NULL);
+          return ERROR;
+        }
+
+      len -= result;
+
+      /* Increment the size of the file sent */
+
+      session->size += result;
+    }
+
+  /* Return success */
+
+  return OK;
+}
+
+#else
+
+static int ftpc_sendbinary(FAR struct ftpc_session_s *session,
+                           FAR FILE *linstream)

Review comment:
       why not replace all FILE to int? instead spread #ifdef/#else/#endif around the code base?

##########
File path: netutils/ftpc/ftpc_putfile.c
##########
@@ -65,11 +67,60 @@
  *
  ****************************************************************************/
 
+#ifdef CONFIG_FTPC_OVER_SENDFILE
 static int ftpc_sendbinary(FAR struct ftpc_session_s *session,
-                           FAR FILE *linstream, FILE *routstream)
+                           int linfd)
+{
+  struct stat stat_buf;
+  off_t offset;
+  ssize_t result;
+  ssize_t len;
+
+  if (fstat(linfd, &stat_buf) == -1)
+    {
+      ftpc_xfrabort(session, NULL);
+      return ERROR;
+    }
+
+  /* Loop until the entire file is sent */
+
+  offset = session->offset;
+  len = stat_buf.st_size - offset;
+
+  while (len > 0)
+    {
+      result = sendfile(session->data.sd, linfd, &offset, len);
+
+      if (result == -1 && errno == EAGAIN)
+        {
+          continue;
+        }
+      else if (result == -1)
+        {
+          ftpc_xfrabort(session, NULL);
+          return ERROR;
+        }
+
+      len -= result;
+
+      /* Increment the size of the file sent */
+
+      session->size += result;
+    }
+
+  /* Return success */
+
+  return OK;
+}
+
+#else
+
+static int ftpc_sendbinary(FAR struct ftpc_session_s *session,
+                           FAR FILE *linstream)

Review comment:
       why not replace all FILE with int? instead spread #ifdef/#else/#endif around the code base?




-- 
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