newlib pipe.c implementation [non]-blocking read() PATCH

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
anhanguera
Posts: 31
Joined: Thu Aug 26, 2004 4:20 pm

newlib pipe.c implementation [non]-blocking read() PATCH

Post by anhanguera »

hi,

- in __psp_pipe_read (...) it is looking for how many bytes already in the pipe with __psp_pipe_peekmsgsize(...). and if there is no data already in the pipe, returns '-1'. this is correct for 'non-blocking read', for 'blocking read' it should wait until some data cames in to the pipe.

- in __psp_pipe_nonblocking_read (...) it sets the errno 'EBADF' if pipe fd is OK, but there is no data available at the moment. it should set errno to 'EAGAIN' if the pipe fd is OK, but there no data avail.

here is the patch for these;

Code: Select all

Index: patches/newlib-1.15.0-PSP.patch
===================================================================
--- patches/newlib-1.15.0-PSP.patch     (revision 2235)
+++ patches/newlib-1.15.0-PSP.patch     (working copy)
@@ -7420,7 +7420,7 @@
 diff -burN orig.newlib-1.15.0/newlib/libc/sys/psp/pipe.c newlib-1.15.0/newlib/libc/sys/psp/pipe.c
 --- orig.newlib-1.15.0/newlib/libc/sys/psp/pipe.c      1969-12-31 20:00:00.000000000 -0400
 +++ newlib-1.15.0/newlib/libc/sys/psp/pipe.c   2007-05-29 15:02:51.000000000 -0300
-@@ -0,0 +1,276 @@
+@@ -0,0 +1,285 @@
 +/*
 + * PSP Software Development Kit - http://www.pspdev.org
 + * -----------------------------------------------------------------------
@@ -7551,6 +7551,10 @@
 +                      len = size;
 +              }
 +      }
++      else if (size == 0) {
++              errno = EAGAIN;
++              return -1;
++      }
 +      else {
 +              errno = EBADF;
 +              return -1;
@@ -7595,6 +7599,10 @@
 +
 +      sceuid = __psp_descriptormap[fd]->sce_descriptor;
 +
++#if 0
++      /* we should block until there is some data (or maybe for enough data),
++       * peeking the msg size should be only for nonblocking reads
++       */
 +      size = __psp_pipe_peekmsgsize(fd);
 +      if (size > 0) {
 +              if &#40;size < len&#41; &#123;
@@ -7605,6 +7613,7 @@
 +              errno = EBADF;
 +              return -1;
 +      &#125;
++#endif
 +
 +      /**
 +      * Receive a message from a pipe
@@ -7700,7 +7709,7 @@
 diff -burN orig.newlib-1.15.0/newlib/libc/sys/psp/pipe.c.orig newlib-1.15.0/newlib/libc/sys/psp/pipe.c.orig
 --- orig.newlib-1.15.0/newlib/libc/sys/psp/pipe.c.orig 1969-12-31 20&#58;00&#58;00.000000000 -0400
 +++ newlib-1.15.0/newlib/libc/sys/psp/pipe.c.orig      2007-05-29 15&#58;00&#58;50.000000000 -0300
-@@ -0,0 +1,271 @@
+@@ -0,0 +1,280 @@
 +/*
 + * PSP Software Development Kit - http&#58;//www.pspdev.org
 + * -----------------------------------------------------------------------
@@ -7831,6 +7840,10 @@
 +                      len = size;
 +              &#125;
 +      &#125;
++      else if &#40;size == 0&#41; &#123;
++              errno = EAGAIN;
++              return -1;
++      &#125;
 +      else &#123;
 +              errno = EBADF;
 +              return -1;
@@ -7875,6 +7888,10 @@
 +
 +      sceuid = __psp_descriptormap&#91;fd&#93;->sce_descriptor;
 +
++#if 0
++      /* we should block until there is some data &#40;or maybe for enough data&#41;,
++       * peeking the msg size should be only for nonblocking reads
++       */
 +      size = __psp_pipe_peekmsgsize&#40;fd&#41;;
 +      if &#40;size > 0&#41; &#123;
 +              if &#40;size < len&#41; &#123;
@@ -7885,6 +7902,7 @@
 +              errno = EBADF;
 +              return -1;
 +      &#125;
++#endif
 +
 +      /**
 +      * Receive a message from a pipe
cheers,
anhanguera.
ooPo
Site Admin
Posts: 2023
Joined: Sat Jan 17, 2004 9:56 am
Location: Canada
Contact:

Post by ooPo »

This has been updated in the repository.
anhanguera
Posts: 31
Joined: Thu Aug 26, 2004 4:20 pm

Post by anhanguera »

thanks ;)
Post Reply