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

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 the layer stack is searched downwards until a non-NULL function pointer is found for that particular slot.
This file implements the generic functionality. Specific layers are in separate files: io/io_buf.c, io/io_stdio.c, io/io_unix.c, io/io_win32.c, and io/io_layers.c.
The ParrotIO PMC provides the class-based interface that is used in Parrot ops.
The ParrotIO struct is defined in io/io_private.h.

PMC *new_io_pmc(theINTERP, ParrotIO *io)ParrotIO PMC.STRING *PIO_make_io_string(Interp *, STRING **buf, size_t default_len)buf parameter can be either: 1) Point to a NULL STRING
2) Point to a real STRING
3) Point to a fake STRING with (strstart, bufused) holding the *buffer
information.
ParrotIOTable alloc_pio_array(int numhandles)PIO_init() to allocate an interpreter's IO handle table with room for numhandles IO handles.int realloc_pio_array(ParrotIOTable *table, int numhandles)-1.ParrotIO *PIO_new(theINTERP, INTVAL iotype, INTVAL flags, INTVAL mode)flags and mode are set in the returned ParrotIO.iotype is unused.void PIO_destroy(theINTERP, PMC *pmc)void PIO_init(theINTERP)STD* handles.void PIO_finish(theINTERP)void PIO_internal_shutdown(theINTERP)INTVAL PIO_init_stacks(theINTERP)INTVAL PIO_base_init(theINTERP, ParrotIOLayer *l)INIT {} block.0.ParrotIO interface 
INTVAL PIO_parse_open_flags(const char *flagstr)*flagstr for Perl-style file open mode flags (<, >, >>, +<, +>) and returns the combined generic bit flags.INTVAL PIO_peek(theINTERP, PMC *pmc, void *buffer) Iterate down the stack to the first layer implementing "Peek" API
INTVAL PIO_pioctl(theINTERP, PMC *pmc, INTVAL cmd, INTVAL arg)PIOCTL* values in include/parrot/io.h.0 on success and a negative value on error. "get" operations will 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(theINTERP, PMC *pmc, size_t bufsize)*pmc to bufsize. Returns 0 if the buffering was enabled.INTVAL PIO_setlinebuf(theINTERP, PMC *pmc)*pmc. Returns 0 if line buffering was successfully set, or already enabled.PMC *PIO_open(theINTERP, ParrotIOLayer *layer, const char *spath, const char *sflags)ParrotIO PMC for *spath.PMC *PIO_fdopen(theINTERP, ParrotIOLayer *layer, PIOHANDLE fd, const char *sflags)ParrotIO PMC for *spath on an existing, open file descriptor.STD* IO handles onto the OS IO handles (0,1,2).INTVAL PIO_close(theINTERP, PMC *pmc)ParrotIO PMC *pmc.void PIO_flush(theINTERP, PMC *pmc)ParrotIO PMC *pmc.STRING *PIO_reads(theINTERP, PMC *pmc, size_t len)STRING* holding up to len bytes.INTVAL PIO_read(theINTERP, PMC *pmc, void *buffer, size_t len)len bytes from *pmc and copys them into *buffer.INTVAL PIO_write(theINTERP, PMC *pmc, const void *buffer, size_t len)len bytes from *buffer to *pmc.PIOOFF_T PIO_seek(theINTERP, PMC *pmc, PIOOFF_T offset, INTVAL w)*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(theINTERP, PMC *pmc)*pmc.INTVAL PIO_eof(theINTERP, PMC *pmc)*pmc's current read/write position is EOF.INTVAL PIO_puts(theINTERP, PMC *pmc, const char *s)*s tp *pmc. C string version.INTVAL PIO_putps(theINTERP, PMC *pmc, STRING *s)*s tp *pmc. Parrot string version.INTVAL PIO_fprintf(theINTERP, PMC *pmc, const char *s, ...)*pmc.INTVAL PIO_printf(theINTERP, const char *s, ...)stdout.INTVAL PIO_eprintf(theINTERP, const char *s, ...)stderr.PIOHANDLE PIO_getfd(theINTERP, PMC *pmc)*pmc's file descriptor, or 0 if it is not defined.PIO_STD* Functions 
The PIO_STD* functions are defined using the theINTERP macro. The prototype is protected with an identity macro.
PMC *PIO_STDIN ID((theINTERP))ParrotIO PMC for stdin.PMC *PIO_STDOUT ID((theINTERP))ParrotIO PMC for stdout.PMC *PIO_STDERR ID((theINTERP))ParrotIO PMC for stderr.
void Parrot_IOData_mark(theINTERP, ParrotIOData *piodata)trace_active_PMCs() to mark the IO data live.
These are used to create offsets for the seek op.
PIOOFF_T PIO_make_offset(INTVAL offset)offset.PIOOFF_T PIO_make_offset32(INTVAL hi, INTVAL lo)hi 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_pmc(theINTERP, PMC *pmc)get_integer vtable method on *pmc.
INTVAL PIO_poll(theINTERP, PMC *pmc, INTVAL which, INTVAL sec, INTVAL usec)*pmc for the events in which every sec seconds + usec microseconds.PMC *PIO_socket(theINTERP, INTVAL fam, INTVAL type, INTVAL proto)INTVAL PIO_recv(theINTERP, PMC *pmc, STRING **buf)*pmc in *buf.INTVAL PIO_send(theINTERP, PMC *pmc, STRING *buf)*buf to the connected socket *pmc.INTVAL PIO_connect(theINTERP, PMC *pmc, STRING *address)*pmc to *address.INTVAL PIO_bind(theINTERP, PMC *pmc, STRING *address)*pmc's socket to the local address and port specified by *address.INTVAL PIO_listen(theINTERP, PMC *pmc, INTVAL backlog)*pmc.INTVAL PIO_accept(theINTERP, PMC *pmc)ParrotIO socket.INTVAL PIO_isatty(theINTERP, PMC *pmc)*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 Perl5.7 and Nick Ing-Simmons' work.

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