cvsuser     03/03/17 08:19:21

  Modified:    io       io_buf.c io_unix.c
  Log:
  io fixups
  
  Courtesy of Juergen Boemmels
  
  Revision  Changes    Path
  1.2       +27 -21    parrot/io/io_buf.c
  
  Index: io_buf.c
  ===================================================================
  RCS file: /cvs/public/parrot/io/io_buf.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- io_buf.c  8 Jun 2002 00:11:19 -0000       1.1
  +++ io_buf.c  17 Mar 2003 16:19:20 -0000      1.2
  @@ -1,7 +1,7 @@
   /* io_buf.c
    *  Copyright: (When this is determined...it will go here)
    *  CVS Info
  - *      $Id: io_buf.c,v 1.1 2002/06/08 00:11:19 josh Exp $
  + *      $Id: io_buf.c,v 1.2 2003/03/17 16:19:20 dan Exp $
    *  Overview:
    *      The "buf" layer of Parrot IO. Buffering and all the fun stuff.
    *
  @@ -26,7 +26,6 @@
       0, 0
   };
   
  -
   /*
    * Currently keeping layer prototypes local to each layer
    * file.
  @@ -41,7 +40,7 @@
   ParrotIO *PIO_buf_fdopen(theINTERP, ParrotIOLayer *l,
                              PIOHANDLE fd, INTVAL flags);
   INTVAL PIO_buf_close(theINTERP, ParrotIOLayer *l, ParrotIO *io);
  -void PIO_buf_flush(theINTERP, ParrotIOLayer *l, ParrotIO *io);
  +INTVAL PIO_buf_flush(theINTERP, ParrotIOLayer *l, ParrotIO *io);
   size_t PIO_buf_read(theINTERP, ParrotIOLayer *l,
                         ParrotIO *io, void *buffer, size_t len);
   size_t PIO_buf_write(theINTERP, ParrotIOLayer *l,
  @@ -52,6 +51,7 @@
                         INTVAL hi, INTVAL lo, INTVAL whence);
   PIOOFF_T PIO_buf_tell(theINTERP, ParrotIOLayer *l, ParrotIO *io);
   
  +
   /* Local util functions */
   size_t PIO_buf_writethru(theINTERP, ParrotIOLayer *layer,
                              ParrotIO *io, const void *buffer, size_t len);
  @@ -78,7 +78,14 @@
       ParrotIO *io;
       ParrotIOLayer *l = layer;
       while (l) {
  -        if (l->api->Open) {
  +        l = PIO_DOWNLAYER(l);
  +        if (l && l->api->Open) break;
  +    }
  +    if (!l) {
  +        /* Now underlying layer found */
  +        return NULL;
  +    }
  +
               io = (*l->api->Open) (interpreter, l, path, flags);
               /*
                * We have an IO stream now setup stuff
  @@ -87,10 +94,6 @@
               PIO_buf_setbuf(interpreter, l, io, PIO_UNBOUND);
               return io;
           }
  -        l = PIO_DOWNLAYER(l);
  -    }
  -    return NULL;
  -}
   
   
   /*
  @@ -187,7 +190,7 @@
   }
   
   
  -void
  +INTVAL
   PIO_buf_flush(theINTERP, ParrotIOLayer *layer, ParrotIO *io)
   {
       long wrote;
  @@ -198,7 +201,7 @@
       if (!io->b.startb
           || (io->flags & (PIO_F_BLKBUF | PIO_F_LINEBUF)) == 0
           || (io->b.flags & (PIO_BF_WRITEBUF | PIO_BF_READBUF)) == 0)
  -        return;
  +        return 0;
       /*
        * Write flush
        */
  @@ -213,7 +216,7 @@
               io->b.next = io->b.startb;
               /* Release buffer */
               io->b.flags &= ~PIO_BF_WRITEBUF;
  -            return;
  +            return 0;
           }
           else {
               /* FIXME: I/O Error */
  @@ -224,6 +227,7 @@
           io->b.flags &= ~PIO_BF_READBUF;
           io->b.next = io->b.startb;
       }
  +    return -1;
   }
   
   
  @@ -253,7 +257,7 @@
           avail = io->b.size - (io->b.next - io->b.startb);
       }
       else if (io->b.flags & PIO_BF_READBUF) {
  -        io->b.flags |= ~PIO_BF_READBUF;
  +        io->b.flags &= ~PIO_BF_READBUF;
           io->b.next = io->b.startb;
           avail = io->b.size;
       }
  @@ -278,17 +282,19 @@
           }
       }
       else if (avail > len) {
  +        io->b.flags |= PIO_BF_WRITEBUF;
           memcpy(io->b.next, buffer, len);
           io->b.next += len;
           return len;
       }
       else {
  -        /* Fill remainder, flush, then try to buffer more */
           unsigned int diff = (int)(len - avail);
  +
  +        io->b.flags |= PIO_BF_WRITEBUF;
  +        /* Fill remainder, flush, then try to buffer more */
           memcpy(io->b.next, buffer, diff);
           /* We don't call flush here because it clears flag */
  -        wrote = PIO_buf_writethru(interpreter, layer, io,
  -                                    io->b.startb, io->b.size);
  +        PIO_buf_flush(interpreter, layer, io);
           memcpy(io->b.startb, ((const char *)buffer + diff), len - diff);
           io->b.next = io->b.startb + (len - diff);
           return len;
  @@ -378,7 +384,7 @@
       PIO_null_write_async,
       PIO_buf_read,
       PIO_null_read_async,
  -    PIO_null_flush,
  +    PIO_buf_flush,
       PIO_null_seek,
       PIO_null_tell,
       PIO_buf_setbuf,
  
  
  
  1.23      +2 -4      parrot/io/io_unix.c
  
  Index: io_unix.c
  ===================================================================
  RCS file: /cvs/public/parrot/io/io_unix.c,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -w -r1.22 -r1.23
  --- io_unix.c 14 Mar 2003 20:20:19 -0000      1.22
  +++ io_unix.c 17 Mar 2003 16:19:20 -0000      1.23
  @@ -1,7 +1,7 @@
   /* io_unix.c
    *  Copyright: (When this is determined...it will go here)
    *  CVS Info
  - *      $Id: io_unix.c,v 1.22 2003/03/14 20:20:19 dan Exp $
  + *      $Id: io_unix.c,v 1.23 2003/03/17 16:19:20 dan Exp $
    *  Overview:
    *      This is the Parrot IO UNIX layer. May be changed to
    *      include other platforms if that platform is similar 
  @@ -276,9 +276,7 @@
   void
   PIO_unix_flush(theINTERP, ParrotIOLayer *layer, ParrotIO *io)
   {
  -#  if 0
       fsync(io->fd);
  -#  endif
   }
   
   
  @@ -425,7 +423,7 @@
       PIO_null_write_async,
       PIO_unix_read,
       PIO_null_read_async,
  -    PIO_null_flush,
  +    PIO_unix_flush,
       PIO_unix_seek,
       PIO_unix_tell,
       PIO_null_setbuf,
  
  
  

Reply via email to