parrotcode: UNIX IO layer | |
Contents | C |
src/io/io_unix.c - UNIX IO layer
This is the Parrot UNIX IO layer. It implements unbuffered, low-level, UNIX-specific functionality.
As "UNIX" is already a generalization, it may be necessary to create separate OS-specific layers for UNIX flavors, to avoid over-complicating this file.
APitUE - W. Richard Stevens, AT&T SFIO, Perl5 (Nick Ing-Simmons)
static INTVAL flags_to_unix(INTVAL flags)
flags
suitable for passing to open()
and fopen()
in PIO_unix_open()
and PIO_unix_fdopen()
respectively.static INTVAL PIO_unix_init(Interp *interp, ParrotIOLayer *layer)
std*
IO handles.
Returns 0
on success and -1
on error.static ParrotIO *PIO_unix_open(Interp *interp, ParrotIOLayer *layer, const char *spath, INTVAL flags)
*spath
.
flags
is a bitwise or
combination of PIO_F_*
values.static INTVAL PIO_unix_async(Interp *interp, ParrotIOLayer *layer, ParrotIO *io, INTVAL b)
PARROT_ASYNC_DEVEL
is defined.O_ASYNC
flag on the IO file descriptor.static ParrotIO *PIO_unix_fdopen(Interp *interp, ParrotIOLayer *layer, PIOHANDLE fd, INTVAL flags)
ParrotIO
with file descriptor fd
.static INTVAL PIO_unix_close(Interp *interp, ParrotIOLayer *layer, ParrotIO *io)
*io
's file descriptor.INTVAL PIO_unix_isatty(PIOHANDLE fd)
fd
is a console/tty.INTVAL PIO_unix_getblksize(PIOHANDLE fd)
fstat()
and the stat
buffer are used if available.BLKSIZE
constant is returned if it was available at compile time,
otherwise PIO_BLKSIZE
is returned.static INTVAL PIO_unix_flush(Interp *interp, ParrotIOLayer *layer, ParrotIO *io)
flush
is to ask the kernel to sync()
.sync()
here?static size_t PIO_unix_read(Interp *interp, ParrotIOLayer *layer, ParrotIO *io, STRING ** buf)
read()
to return up to len
bytes in the memory starting at buffer
.static size_t PIO_unix_write(Interp *interp, ParrotIOLayer *layer, ParrotIO *io, STRING *)
write()
to write len
bytes from the memory starting at buffer
to the file descriptor in *io
.static PIOOFF_T PIO_unix_seek(Interp *interp, ParrotIOLayer *layer, ParrotIO *io, PIOOFF_T offset, INTVAL whence)
lseek()
to advance the read/write position on *io
's file descriptor to offset
bytes from the location indicated by whence
.static PIOOFF_T PIO_unix_tell(Interp *interp, ParrotIOLayer *layer, ParrotIO *io)
*io
's file discriptor.Define PARROT_NET_DEVEL
to enable networking.
These could be native extensions but they probably should be here if we wish to make them integrated with the async IO system.
Very minimal stubs for now, maybe someone will run with these.
STRING *PIO_sockaddr_in(Interp *interp, unsigned short port, STRING *addr)
PIO_sockaddr_in()
is not part of the layer and so must be extern
.htons()
,
inet_aton()
,
etc.) and take this out of platform specific compilationstatic ParrotIO *PIO_unix_socket(Interp *interp, ParrotIOLayer *layer, int fam, int type, int proto)
socket()
to create a socket with the specified address family,
socket type and protocol number.static INTVAL PIO_unix_connect(Interp *interp, ParrotIOLayer *layer, ParrotIO *io, STRING *r)
*io
's socket to address *r
.static INTVAL PIO_unix_bind(Interp *interp, ParrotIOLayer *layer, ParrotIO *io, STRING *l)
*io
's socket to the local address and port specified by *l
.static INTVAL PIO_unix_listen(Interp *interp, ParrotIOLayer *layer, ParrotIO *io, INTVAL sec)
STREAM
or SEQ
sockets.static ParrotIO *PIO_unix_accept(Interp *interp, ParrotIOLayer *layer, ParrotIO *io)
ParrotIO
socket.static INTVAL PIO_unix_send(Interp *interp, ParrotIOLayer *layer, ParrotIO *io, STRING *s)
*s
to *io
's connected socket.static INTVAL PIO_unix_recv(Interp *interp, ParrotIOLayer *layer, ParrotIO *io, STRING **s)
**s
from *io
's connected socket.static INTVAL PIO_unix_poll(Interp *interp, ParrotIOLayer *l, ParrotIO *io, int which, int sec, int usec)
static ParrotIO *PIO_unix_pipe(Interp *interp, ParrotIOLayer *l, STRING *cmd, int flags)
exec
for now.src/io/io_buf.c, src/io/io_passdown.c, src/io/io_stdio.c, src/io/io_unix.c, src/io/io_win32.c, src/io/io.c, src/io/io_private.h.
Initially written by Melvin Smith (mrjoltcola@mindspring.com).
|