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/04/28 00:54:13 UTC

[GitHub] [incubator-nuttx] yamt opened a new pull request, #6168: Implement preadv and pwritev

yamt opened a new pull request, #6168:
URL: https://github.com/apache/incubator-nuttx/pull/6168

   ## Summary
   Implement preadv and pwritev
   ## Impact
   
   ## Testing
   build tested with modified wamr
   


-- 
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] [incubator-nuttx] yamt commented on a diff in pull request #6168: Implement preadv and pwritev

Posted by GitBox <gi...@apache.org>.
yamt commented on code in PR #6168:
URL: https://github.com/apache/incubator-nuttx/pull/6168#discussion_r860463262


##########
libs/libc/uio/lib_pwritev.c:
##########
@@ -0,0 +1,111 @@
+/****************************************************************************
+ * libs/libc/uio/lib_pwritev.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <unistd.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: pwritev()
+ *
+ * Description:
+ *   The pwritev() function is equivalent to write(), except it takes
+ *   an iov array.
+ *
+ ****************************************************************************/
+
+ssize_t pwritev(int fildes, FAR const struct iovec *iov, int iovcnt,
+                off_t offset)
+{
+  ssize_t ntotal;
+  ssize_t nwritten;
+  size_t remaining;
+  FAR uint8_t *buffer;
+  off_t pos;
+  int i;
+
+  /* Get the current file position in case we have to reset it */
+
+  pos = lseek(fildes, 0, SEEK_CUR);
+
+  /* Process each entry in the struct iovec array */
+
+  for (i = 0, ntotal = 0; i < iovcnt; i++)
+    {
+      /* Ignore zero-length writes */
+
+      if (iov[i].iov_len > 0)
+        {
+          buffer    = iov[i].iov_base;
+          remaining = iov[i].iov_len;
+
+          /* Write repeatedly as necessary to write the entire buffer */
+
+          do
+            {
+              /* NOTE: pwrite() is a cancellation point */
+
+              nwritten = pwrite(fildes, buffer, remaining, offset + ntotal);
+
+              /* Check for a write error */
+
+              if (nwritten < 0)
+                {
+                  if (pos != (off_t)-1)
+                    {
+                      /* Save the errno value */
+
+                      int save = get_errno();
+
+                      /* Restore the file position */
+
+                      lseek(fildes, pos, SEEK_SET);

Review Comment:
   because of copy-and-paste w/o thinking. :-)
   fixed.
   



-- 
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] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #6168: Implement preadv and pwritev

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #6168:
URL: https://github.com/apache/incubator-nuttx/pull/6168#discussion_r860457776


##########
libs/libc/uio/lib_pwritev.c:
##########
@@ -0,0 +1,111 @@
+/****************************************************************************
+ * libs/libc/uio/lib_pwritev.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <unistd.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: pwritev()
+ *
+ * Description:
+ *   The pwritev() function is equivalent to write(), except it takes
+ *   an iov array.
+ *
+ ****************************************************************************/
+
+ssize_t pwritev(int fildes, FAR const struct iovec *iov, int iovcnt,
+                off_t offset)
+{
+  ssize_t ntotal;
+  ssize_t nwritten;
+  size_t remaining;
+  FAR uint8_t *buffer;
+  off_t pos;
+  int i;
+
+  /* Get the current file position in case we have to reset it */
+
+  pos = lseek(fildes, 0, SEEK_CUR);
+
+  /* Process each entry in the struct iovec array */
+
+  for (i = 0, ntotal = 0; i < iovcnt; i++)
+    {
+      /* Ignore zero-length writes */
+
+      if (iov[i].iov_len > 0)
+        {
+          buffer    = iov[i].iov_base;
+          remaining = iov[i].iov_len;
+
+          /* Write repeatedly as necessary to write the entire buffer */
+
+          do
+            {
+              /* NOTE: pwrite() is a cancellation point */
+
+              nwritten = pwrite(fildes, buffer, remaining, offset + ntotal);
+
+              /* Check for a write error */
+
+              if (nwritten < 0)
+                {
+                  if (pos != (off_t)-1)
+                    {
+                      /* Save the errno value */
+
+                      int save = get_errno();
+
+                      /* Restore the file position */
+
+                      lseek(fildes, pos, SEEK_SET);

Review Comment:
   why need restore file pointer here? pwrite at line 74 doesn't expect to change the file location.



-- 
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] [incubator-nuttx] xiaoxiang781216 merged pull request #6168: Implement preadv and pwritev

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 merged PR #6168:
URL: https://github.com/apache/incubator-nuttx/pull/6168


-- 
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] [incubator-nuttx] yamt commented on a diff in pull request #6168: Implement preadv and pwritev

Posted by GitBox <gi...@apache.org>.
yamt commented on code in PR #6168:
URL: https://github.com/apache/incubator-nuttx/pull/6168#discussion_r860520855


##########
libs/libc/uio/lib_pwritev.c:
##########
@@ -0,0 +1,111 @@
+/****************************************************************************
+ * libs/libc/uio/lib_pwritev.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <unistd.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: pwritev()
+ *
+ * Description:
+ *   The pwritev() function is equivalent to write(), except it takes
+ *   an iov array.
+ *
+ ****************************************************************************/
+
+ssize_t pwritev(int fildes, FAR const struct iovec *iov, int iovcnt,
+                off_t offset)
+{
+  ssize_t ntotal;
+  ssize_t nwritten;
+  size_t remaining;
+  FAR uint8_t *buffer;
+  off_t pos;
+  int i;
+
+  /* Get the current file position in case we have to reset it */
+
+  pos = lseek(fildes, 0, SEEK_CUR);
+
+  /* Process each entry in the struct iovec array */
+
+  for (i = 0, ntotal = 0; i < iovcnt; i++)
+    {
+      /* Ignore zero-length writes */
+
+      if (iov[i].iov_len > 0)
+        {
+          buffer    = iov[i].iov_base;
+          remaining = iov[i].iov_len;
+
+          /* Write repeatedly as necessary to write the entire buffer */
+
+          do
+            {
+              /* NOTE: pwrite() is a cancellation point */
+
+              nwritten = pwrite(fildes, buffer, remaining, offset + ntotal);
+
+              /* Check for a write error */
+
+              if (nwritten < 0)
+                {
+                  if (pos != (off_t)-1)
+                    {
+                      /* Save the errno value */
+
+                      int save = get_errno();
+
+                      /* Restore the file position */
+
+                      lseek(fildes, pos, SEEK_SET);

Review Comment:
   > it's better to fix pwrite too, could you create a new patch/pr for this?
   
   what needs to be fixed in pwrite?
   



-- 
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] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #6168: Implement preadv and pwritev

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #6168:
URL: https://github.com/apache/incubator-nuttx/pull/6168#discussion_r860498804


##########
libs/libc/uio/lib_pwritev.c:
##########
@@ -0,0 +1,111 @@
+/****************************************************************************
+ * libs/libc/uio/lib_pwritev.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <unistd.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: pwritev()
+ *
+ * Description:
+ *   The pwritev() function is equivalent to write(), except it takes
+ *   an iov array.
+ *
+ ****************************************************************************/
+
+ssize_t pwritev(int fildes, FAR const struct iovec *iov, int iovcnt,
+                off_t offset)
+{
+  ssize_t ntotal;
+  ssize_t nwritten;
+  size_t remaining;
+  FAR uint8_t *buffer;
+  off_t pos;
+  int i;
+
+  /* Get the current file position in case we have to reset it */
+
+  pos = lseek(fildes, 0, SEEK_CUR);
+
+  /* Process each entry in the struct iovec array */
+
+  for (i = 0, ntotal = 0; i < iovcnt; i++)
+    {
+      /* Ignore zero-length writes */
+
+      if (iov[i].iov_len > 0)
+        {
+          buffer    = iov[i].iov_base;
+          remaining = iov[i].iov_len;
+
+          /* Write repeatedly as necessary to write the entire buffer */
+
+          do
+            {
+              /* NOTE: pwrite() is a cancellation point */
+
+              nwritten = pwrite(fildes, buffer, remaining, offset + ntotal);
+
+              /* Check for a write error */
+
+              if (nwritten < 0)
+                {
+                  if (pos != (off_t)-1)
+                    {
+                      /* Save the errno value */
+
+                      int save = get_errno();
+
+                      /* Restore the file position */
+
+                      lseek(fildes, pos, SEEK_SET);

Review Comment:
   it's better to fix pwrite too, could you create a new patch/pr for this?



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