| parrotcode: Generic IO | |
| Contents | C |

src/io/io.c - Generic IO

The Parrot IO subsystem uses a per-interpreter stack to provide a layer-based approach to IO.
Each layer implements a subset of the ParrotIOLayerAPI vtable.
To find an IO function,
Parrot searches the layer stack downwards until it finds a non-NULL function pointer for that particular slot.
This file implements the generic functionality. Specific layers are in separate files: src/io/io_buf.c, src/io/io_stdio.c, src/io/io_unix.c, src/io/io_win32.c, and src/io/io_layers.c.
The ParrotIO PMC provides the class-based interface that is used in Parrot ops.
The ParrotIO struct is defined in src/io/io_private.h.

new_io_pmcParrotIO PMC.PIO_make_io_stringbuf parameter can:strstart tells this function to allocate the STRING memory.PIO_newflags and mode are set in the returned ParrotIO.iotype is unused.PIO_destroyPIO_initSTD* handles.PIO_finishPIO_internal_shutdownPIO_init_stacksPIO_base_initINIT {} block.0.ParrotIO interface 
PIO_parse_open_flags*flagstr for Perl-style file open mode flags (<,
>,
>>,
+<,
+>) and returns the combined generic bit flags.PIO_peekPIO_pioctlPIOCTL* values in include/parrot/io.h.set operations return 0 on success and a negative value on error.
get operations use the return value as the value requested,
but should always be >= 0.
A negative value indicates an error.
This may be too limited,
but we will see.
--MelvinPIO_setbuf*pmc to bufsize.
Returns 0 if the buffering was enabled.PIO_setlinebuf*pmc.
Returns 0 if line buffering was successfully set,
or already enabled.PIO_openParrotIO PMC for *spath.PIO_fdopenParrotIO PMC for *spath on an existing,
open file descriptor.STD* IO handles onto the OS IO handles (0,1,2).PIO_closeParrotIO PMC *pmc.PIO_flushParrotIO PMC *pmc.PIO_readsSTRING* holding up to len bytes.len bytes from *pmc and copies them into *buffer.PIO_writelen bytes from *buffer to *pmc.PIO_seek*pmc to offset bytes from the position indicated by w.
Typically w will be 0 for the start of the file,
1 for the current position,
and 2 for the end.PIO_tell*pmc.PIO_eof*pmc's current read/write position is EOF.PIO_puts*s tp *pmc.
C string version.PIO_putps*s to *pmc.
Parrot string version.PIO_fprintf*pmc.PIO_printfstdout.PIO_eprintfstderr.PIO_getfd*pmc's file descriptor,
or 0 if it is not defined.PIO_STD* Functions 
PIO_STDINParrotIO PMC for stdin.PIO_STDOUTParrotIO PMC for stdout.PIO_STDERRParrotIO PMC for stderr.
Parrot_IOData_marktrace_active_PMCs() to mark the IO data live.
These are used to create offsets for the seek op.
PIO_make_offsetoffset.PIO_make_offset32hi is shifted 32 bytes to the left and ored together with lo.
This allows 64-bit seeks with only 32-bit INTVALS.PIO_make_offset_pmcget_integer vtable method on *pmc.
PIO_poll*pmc for the events in which every sec seconds + usec microseconds.PIO_socketPIO_recv*pmc in *buf.
Returns -1 if it fails.PIO_send*buf to the connected socket *pmc.
Returns -1 if it cannot send the message.PIO_connect*pmc to *address.
Returns -1 on failure.PIO_bind*pmc's socket to the local address and port specified by *address.
Returns -1 on failure.PIO_listen*pmc.
Returns -1 on failure.PIO_acceptParrotIO socket.
Returns NULL on failure.PIO_isatty*pmc is a console/tty.
io/io_buf.c, io/io_passdown.c, io/io_stdio.c, io/io_unix.c, io/io_win32.c, io/io_private.h.

Initially written by Melvin Smith.
Some ideas and goals from Perl 5.7 and Nick Ing-Simmons' work.

Rework to use copy-on-write IO stacks rather than creating a new stack for each IO stream.
Add support for loadable layers in Parrot bytecode.
|
|
|