NAME ^

src/io/io_passdown.c - IO layer handling

DESCRIPTION ^

This is a set of helper functions which search for the first implementation of a function in the layer-stack, call it with the appropriate arguments and return the value returned.

Functions ^

*/

#include <parrot/parrot.h> #include "io_private.h"

/* HEADERIZER HFILE: src/io/io_private.h */

/*

FUNCDOC: PIO_open_down

Looks for the implementation of Open and calls it if found, returning its return value.

Returns NULL if no implementation is found.

*/

PARROT_WARN_UNUSED_RESULT PARROT_CAN_RETURN_NULL ParrotIO * PIO_open_down(PARROT_INTERP, NULLOK(ParrotIOLayer *layer), NOTNULL(const char *name), INTVAL flags) { while (layer) { if (layer->api->Open) return layer->api->Open(interp, layer, name, flags); layer = PIO_DOWNLAYER(layer); } return NULL; }

/*

FUNCDOC: PIO_open_async_down

Looks for the implementation of Open_ASync and calls it if found, returning its return value.

Returns NULL if no implementation is found.

*/

PARROT_WARN_UNUSED_RESULT PARROT_CAN_RETURN_NULL ParrotIO * PIO_open_async_down(PARROT_INTERP, NULLOK(ParrotIOLayer *layer), NOTNULL(const char *name), NOTNULL(const char *mode), NOTNULL(DummyCodeRef *dummy)) { while (layer) { if (layer->api->Open_ASync) return layer->api->Open_ASync(interp, layer, name, mode, dummy); layer = PIO_DOWNLAYER(layer); } return NULL; }

/*

PIO_fdopen_down

Looks for the implementation of FDOpen and calls it if found, returning its return value.

Returns NULL if no implementation is found.

*/

PARROT_WARN_UNUSED_RESULT PARROT_CAN_RETURN_NULL ParrotIO * PIO_fdopen_down(PARROT_INTERP, NULLOK(ParrotIOLayer *layer), PIOHANDLE fd, INTVAL flags) { while (layer) { if (layer->api->FDOpen) return layer->api->FDOpen(interp, layer, fd, flags); layer = PIO_DOWNLAYER(layer); } return NULL; }

PARROT_WARN_UNUSED_RESULT size_t PIO_peek_down(PARROT_INTERP, NULLOK(ParrotIOLayer *layer), NOTNULL(ParrotIO *io), NOTNULL(STRING **buf)) { while (layer) { if (layer->api->Peek) return layer->api->Peek(interp, layer, io, buf); layer = PIO_DOWNLAYER(layer); } return 0; }

/*

FUNCDOC: PIO_close_down

Looks for the implementation of Close and calls it if found, returning its return value.

Returns -1 if no implementation is found.

*/

PARROT_WARN_UNUSED_RESULT INTVAL PIO_close_down(PARROT_INTERP, NULLOK(ParrotIOLayer *layer), NOTNULL(ParrotIO *io)) { while (layer) { if (layer->api->Close) return layer->api->Close(interp, layer, io); layer = PIO_DOWNLAYER(layer); } return -1; }

/*

PIO_write_down

Looks for the implementation of Write and calls it if found, returning its return value.

Returns 0 if no implementation is found.

*/

PARROT_WARN_UNUSED_RESULT size_t PIO_write_down(PARROT_INTERP, NULLOK(ParrotIOLayer *layer), NOTNULL(ParrotIO *io), NOTNULL(STRING *s)) { while (layer) { if (layer->api->Write) return layer->api->Write(interp, layer, io, s); layer = PIO_DOWNLAYER(layer); } return 0; }

/*

FUNCDOC: PIO_write_async_down

Looks for the implementation of WriteASync and calls it if found, returning its return value.

Returns 0 if no implementation is found.

*/

PARROT_WARN_UNUSED_RESULT size_t PIO_write_async_down(PARROT_INTERP, NULLOK(ParrotIOLayer *layer), NOTNULL(ParrotIO *io), NOTNULL(STRING *s), NOTNULL(DummyCodeRef *dummy)) { while (layer) { if (layer->api->Write_ASync) return layer->api->Write_ASync(interp, layer, io, s, dummy); layer = PIO_DOWNLAYER(layer); } return 0; }

/*

FUNCDOC: PIO_read_down

Looks for the implementation of Read and calls it if found, returning its return value.

Returns 0 if no implementation is found.

*/

PARROT_WARN_UNUSED_RESULT size_t PIO_read_down(PARROT_INTERP, NULLOK(ParrotIOLayer *layer), NOTNULL(ParrotIO *io), NOTNULL(STRING **buf)) { while (layer) { if (layer->api->Read) return layer->api->Read(interp, layer, io, buf); layer = PIO_DOWNLAYER(layer); } return 0; }

/*

FUNCDOC: PIO_read_async_down

Looks for the implementation of Read_ASync and calls it if found, returning its return value.

Returns 0 if no implementation is found.

*/

PARROT_WARN_UNUSED_RESULT size_t PIO_read_async_down(PARROT_INTERP, NULLOK(ParrotIOLayer *layer), NOTNULL(ParrotIO *io), NOTNULL(STRING **buf), NOTNULL(DummyCodeRef *dummy)) { while (layer) { if (layer->api->Read_ASync) return layer->api->Read_ASync(interp, layer, io, buf, dummy); layer = PIO_DOWNLAYER(layer); } return 0; }

/*

FUNCDOC: PIO_flush_down

Looks for the implementation of Flush and calls it if found, returning its return value.

Returns 0 if no implementation is found.

*/

PARROT_WARN_UNUSED_RESULT INTVAL PIO_flush_down(PARROT_INTERP, NULLOK(ParrotIOLayer *layer), NOTNULL(ParrotIO *io)) { while (layer) { if (layer->api->Flush) layer->api->Flush(interp, layer, io); layer = PIO_DOWNLAYER(layer); } return 0; }

/*

FUNCDOC: PIO_seek_down

Looks for the implementation of Seek and calls it if found, returning its return value.

Returns -1 if no implementation is found.

*/

PARROT_WARN_UNUSED_RESULT PIOOFF_T PIO_seek_down(PARROT_INTERP, NULLOK(ParrotIOLayer *layer), NOTNULL(ParrotIO *io), PIOOFF_T offset, INTVAL whence) { while (layer) { if (layer->api->Seek) return layer->api->Seek(interp, layer, io, offset, whence); layer = PIO_DOWNLAYER(layer); } return -1; }

/*

FUNCDOC: PIO_tell_down

Looks for the implementation of Tell and calls it if found, returning its return value.

Returns 0 if no implementation is found.

*/

PARROT_WARN_UNUSED_RESULT PIOOFF_T PIO_tell_down(PARROT_INTERP, NULLOK(ParrotIOLayer *layer), NOTNULL(ParrotIO *io)) { while (layer) { if (layer->api->Tell) return layer->api->Tell(interp, layer, io); layer = PIO_DOWNLAYER(layer); } return 0; }

/*

FUNCDOC: PIO_setbuf_down

Looks for the implementation of SetBuf and calls it if found, returning its return value.

Returns -1 if no implementation is found.

*/

PARROT_WARN_UNUSED_RESULT INTVAL PIO_setbuf_down(PARROT_INTERP, NULLOK(ParrotIOLayer *layer), NOTNULL(ParrotIO *io), size_t bufsize) { while (layer) { if (layer->api->SetBuf) return layer->api->SetBuf(interp, layer, io, bufsize); layer = PIO_DOWNLAYER(layer); } return -1; }

/*

FUNCDOC: PIO_setlinebuf_down

Looks for the implementation of SetLineBuf and calls it if found, returning its return value.

Returns -1 if no implementation is found.

*/

PARROT_WARN_UNUSED_RESULT INTVAL PIO_setlinebuf_down(PARROT_INTERP, NULLOK(ParrotIOLayer *layer), NOTNULL(ParrotIO *io)) { while (layer) { if (layer->api->SetLineBuf) return layer->api->SetLineBuf(interp, layer, io); layer = PIO_DOWNLAYER(layer); } return -1; }

/*

FUNCDOC: PIO_eof_down

Looks for the implementation of Eof and calls it if found, returning its return value.

Returns -1 if no implementation is found.

*/

PARROT_WARN_UNUSED_RESULT INTVAL PIO_eof_down(PARROT_INTERP, NULLOK(ParrotIOLayer *layer), NOTNULL(ParrotIO *io)) { while (layer) { if (layer->api->Eof) return layer->api->Eof(interp, layer, io); layer = PIO_DOWNLAYER(layer); } return -1; }

/*

FUNCDOC: PIO_poll_down

Looks for the implementation of Poll and calls it if found, returning its return value.

Returns -1 if no implementation is found.

*/

PARROT_WARN_UNUSED_RESULT INTVAL PIO_poll_down(PARROT_INTERP, NOTNULL(ParrotIOLayer *layer), NOTNULL(ParrotIO *io), INTVAL which, INTVAL sec, INTVAL usec) { while (layer) { if (layer->api->Poll) return layer->api->Poll(interp, layer, io, which, sec, usec); layer = PIO_DOWNLAYER(layer); } return -1; }

/*

FUNCDOC: PIO_socket_down

Looks for the implementation of Socket and calls it if found, returning its return value.

Returns NULL if no implementation is found.

*/

PARROT_WARN_UNUSED_RESULT PARROT_CAN_RETURN_NULL ParrotIO * PIO_socket_down(PARROT_INTERP, NOTNULL(ParrotIOLayer *layer), INTVAL fam, INTVAL type, INTVAL proto) { while (layer) { if (layer->api->Socket) return layer->api->Socket(interp, layer, fam, type, proto); layer = PIO_DOWNLAYER(layer); } return NULL; }

/*

FUNCDOC: PIO_recv_down

Looks for the implementation of Recv and calls it if found, returning its return value.

Returns -1 if no implementation is found.

*/

PARROT_WARN_UNUSED_RESULT INTVAL PIO_recv_down(PARROT_INTERP, NOTNULL(ParrotIOLayer *layer), NOTNULL(ParrotIO *io), NOTNULL(STRING **buf)) { while (layer) { if (layer->api->Recv) return layer->api->Recv(interp, layer, io, buf); layer = PIO_DOWNLAYER(layer); } return -1; }

/*

FUNCDOC: PIO_send_down

Looks for the implementation of Send and calls it if found, returning its return value.

Returns -1 if no implementation is found.

*/

PARROT_WARN_UNUSED_RESULT INTVAL PIO_send_down(PARROT_INTERP, NOTNULL(ParrotIOLayer *layer), NOTNULL(ParrotIO *io), NOTNULL(STRING *buf)) { while (layer) { if (layer->api->Send) return layer->api->Send(interp, layer, io, buf); layer = PIO_DOWNLAYER(layer); } return -1; }

/*

FUNCDOC: PIO_connect_down

Looks for the implementation of Connect and calls it if found, returning its return value.

Returns -1 if no implementation is found.

*/

PARROT_WARN_UNUSED_RESULT INTVAL PIO_connect_down(PARROT_INTERP, NOTNULL(ParrotIOLayer *layer), NOTNULL(ParrotIO *io), NOTNULL(STRING *address)) { while (layer) { if (layer->api->Connect) return layer->api->Connect(interp, layer, io, address); layer = PIO_DOWNLAYER(layer); } return -1; }

/*

FUNCDOC: PIO_bind_down

Looks for the implementation of Bind and calls it if found, returning its return value.

Returns -1 if no implementation is found.

*/

PARROT_WARN_UNUSED_RESULT INTVAL PIO_bind_down(PARROT_INTERP, NOTNULL(ParrotIOLayer *layer), NOTNULL(ParrotIO *io), NOTNULL(STRING *address)) { while (layer) { if (layer->api->Bind) return layer->api->Bind(interp, layer, io, address); layer = PIO_DOWNLAYER(layer); } return -1; }

/*

FUNCDOC: PIO_listen_down

Looks for the implementation of listen and calls it if found, returning its return value.

Returns -1 if no implementation is found.

*/

PARROT_WARN_UNUSED_RESULT INTVAL PIO_listen_down(PARROT_INTERP, NOTNULL(ParrotIOLayer *layer), NOTNULL(ParrotIO *io), INTVAL backlog) { while (layer) { if (layer->api->Listen) return layer->api->Listen(interp, layer, io, backlog); layer = PIO_DOWNLAYER(layer); } return -1; }

/*

FUNCDOC: PIO_accept_down

Looks for the implementation of Accept and calls it if found, returning its return value.

Returns -1 if no implementation is found.

*/

PARROT_WARN_UNUSED_RESULT PARROT_CAN_RETURN_NULL ParrotIO * PIO_accept_down(PARROT_INTERP, NOTNULL(ParrotIOLayer *layer), NOTNULL(ParrotIO *io)) { while (layer) { if (layer->api->Accept) return layer->api->Accept(interp, layer, io); layer = PIO_DOWNLAYER(layer); } return NULL; }

/*

SEE ALSO ^

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.

HISTORY ^

Initially written by Juergen Boemmels

Some ideas and goals from Perl5.7 and Nick Ing-Simmons' work.

*/

/* * Local variables: * c-file-style: "parrot" * End: * vim: expandtab shiftwidth=4: */


parrot