# New Ticket Created by Jürgen Bömmels # Please include the string: [perl #21600] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=21600 >
Next baby-step in PIO: Enabling buffering. This patch patch enables the formerly stubbed out buffering, and shakes out some bugs (Only the first part: Write buffering). Certainly all tests passed on my machine. bye boe -- attachment 1 ------------------------------------------------------ url: http://rt.perl.org/rt2/attach/53762/40505/c32005/io3.diff
Index: io/io.c =================================================================== RCS file: /cvs/public/parrot/io/io.c,v retrieving revision 1.31 diff -u -r1.31 io.c --- io/io.c 14 Mar 2003 20:20:19 -0000 1.31 +++ io/io.c 17 Mar 2003 00:16:51 -0000 @@ -149,10 +149,8 @@ for (i = 0 ; i < PIO_NR_OPEN; i++) { if ( (io = GET_INTERP_IOD(interpreter)->table[i]) ) { -#if 0 PIO_flush(interpreter, io); PIO_close(interpreter, io); -#endif mem_sys_free(io); } } @@ -201,9 +199,7 @@ #ifdef PIO_OS_STDIO PIO_push_layer(interpreter, PIO_base_new_layer(&pio_stdio_layer), NULL); #endif -#if 0 PIO_push_layer(interpreter, PIO_base_new_layer(&pio_buf_layer), NULL); -#endif /* Note: All layer pushes should be done before init calls */ for (p = GET_INTERP_IO(interpreter); p; p = p->down) { Index: io/io_buf.c =================================================================== RCS file: /cvs/public/parrot/io/io_buf.c,v retrieving revision 1.1 diff -u -r1.1 io_buf.c --- io/io_buf.c 8 Jun 2002 00:11:19 -0000 1.1 +++ io/io_buf.c 17 Mar 2003 00:16:51 -0000 @@ -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,18 +78,21 @@ ParrotIO *io; ParrotIOLayer *l = layer; while (l) { - if (l->api->Open) { - io = (*l->api->Open) (interpreter, l, path, flags); - /* - * We have an IO stream now setup stuff - * for our layer before returning it. - */ - PIO_buf_setbuf(interpreter, l, io, PIO_UNBOUND); - return io; - } l = PIO_DOWNLAYER(l); + if (l && l->api->Open) break; } - return NULL; + if (!l) { + /* Now underlying layer found */ + return NULL; + } + + io = (*l->api->Open) (interpreter, l, path, flags); + /* + * We have an IO stream now setup stuff + * for our layer before returning it. + */ + PIO_buf_setbuf(interpreter, l, io, PIO_UNBOUND); + return io; } @@ -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, Index: io/io_unix.c =================================================================== RCS file: /cvs/public/parrot/io/io_unix.c,v retrieving revision 1.22 diff -u -r1.22 io_unix.c --- io/io_unix.c 14 Mar 2003 20:20:19 -0000 1.22 +++ io/io_unix.c 17 Mar 2003 00:16:52 -0000 @@ -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,