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_pmc
ParrotIO
PMC.STRING *PIO_make_io_string
buf
parameter can:strstart
tells this function to allocate the STRING memory.ParrotIO *PIO_new
flags
and mode
are set in the returned ParrotIO
.iotype
is unused.void PIO_destroy
void PIO_init
STD*
handles.void PIO_finish
void PIO_internal_shutdown
INTVAL PIO_init_stacks
INTVAL PIO_base_init
INIT {}
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_peek
INTVAL PIO_pioctl
PIOCTL*
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_open
ParrotIO
PMC for *spath
.PMC *PIO_fdopen
ParrotIO
PMC for *spath
on an existing,
open file descriptor.STD*
IO handles onto the OS IO handles (0,
1,
2).INTVAL PIO_close
ParrotIO
PMC *pmc
.void PIO_flush
ParrotIO
PMC *pmc
.STRING *PIO_reads
STRING*
holding up to len
bytes.INTVAL PIO_read
len
bytes from *pmc
and copies them into *buffer
.INTVAL PIO_write
len
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_printf
stdout
.INTVAL PIO_eprintf
stderr
.PIOHANDLE PIO_getfd
*pmc
's file descriptor,
or 0
if it is not defined.PIO_STD*
Functions PMC *PIO_STDIN
ParrotIO
PMC for stdin
.PMC *PIO_STDOUT
ParrotIO
PMC for stdout
.PMC *PIO_STDERR
ParrotIO
PMC for stderr
.void Parrot_IOData_mark
trace_active_PMCs()
to mark the IO data live.These are used to create offsets for the seek
op.
PIOOFF_T PIO_make_offset
offset
.PIOOFF_T PIO_make_offset32
hi
is shifted 32 bytes to the left and or
ed together with lo
.
This allows 64-bit seeks with only 32-bit INTVALS
.PIOOFF_T PIO_make_offset_pmc
get_integer
vtable method on *pmc
.INTVAL PIO_poll
*pmc
for the events in which
every sec
seconds + usec
microseconds.PMC *PIO_socket
INTVAL 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_accept
ParrotIO
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.
|