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

PMC *new_io_pmcParrotIO PMC.STRING *PIO_make_io_stringbuf parameter can:strstart tells this function to allocate the STRING memory.ParrotIO *PIO_newflags and mode are set in the returned ParrotIO.iotype is unused.PMC *PIO_dupvoid PIO_destroyvoid PIO_initSTD* handles.void PIO_finishvoid PIO_internal_shutdownINTVAL PIO_init_stacksINTVAL PIO_base_initINIT {} block.0.ParrotIO interface 
INTVAL PIO_parse_open_flags*flagstr for Perl-style file open mode flags (<,
>,
>>,
+<,
+>) and returns the combined generic bit flags.INTVAL PIO_peekINTVAL PIO_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.
--MelvinINTVAL PIO_setbuf*pmc to bufsize.
Returns 0 if the buffering was enabled.INTVAL PIO_setlinebuf*pmc.
Returns 0 if line buffering was successfully set,
or already enabled.PMC *PIO_openParrotIO PMC for *spath.PMC *PIO_fdopenParrotIO PMC for *spath on an existing,
open file descriptor.STD* IO handles onto the OS IO handles (0,
1,
2).INTVAL PIO_closeParrotIO PMC *pmc.void PIO_flushParrotIO PMC *pmc.STRING *PIO_readsSTRING* holding up to len bytes.INTVAL PIO_readlen bytes from *pmc and copies them into *buffer.INTVAL PIO_writelen bytes from *buffer to *pmc.PIOOFF_T 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.PIOOFF_T PIO_tell*pmc.INTVAL PIO_eof*pmc's current read/write position is EOF.INTVAL PIO_puts*s tp *pmc.
C string version.INTVAL PIO_putps*s to *pmc.
Parrot string version.INTVAL PIO_fprintf*pmc.INTVAL PIO_printfstdout.INTVAL PIO_eprintfstderr.PIOHANDLE PIO_getfd*pmc's file descriptor,
or 0 if it is not defined.PIO_STD* Functions 
PMC *PIO_STDINParrotIO PMC for stdin.PMC *PIO_STDOUTParrotIO PMC for stdout.PMC *PIO_STDERRParrotIO PMC for stderr.
void Parrot_IOData_marktrace_active_PMCs() to mark the IO data live.
These are used to create offsets for the seek op.
PIOOFF_T PIO_make_offsetoffset.PIOOFF_T 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.PIOOFF_T PIO_make_offset_pmcget_integer vtable method on *pmc.
INTVAL PIO_poll*pmc for the events in which every sec seconds + usec microseconds.PMC *PIO_socketINTVAL PIO_recv*pmc in *buf.
Returns -1 if it fails.INTVAL PIO_send*buf to the connected socket *pmc.
Returns -1 if it cannot send the message.INTVAL PIO_connect*pmc to *address.
Returns -1 on failure.INTVAL PIO_bind*pmc's socket to the local address and port specified by *address.
Returns -1 on failure.INTVAL PIO_listen*pmc.
Returns -1 on failure.PMC *PIO_acceptParrotIO socket.
Returns NULL on failure.INTVAL 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.
|
|
|