Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: d48b17a299
...
compare: 5d38b54d81
  • 5 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
6 src/io/api.c
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2001-2011, Parrot Foundation.
+Copyright (C) 2001-2012, Parrot Foundation.
=head1 NAME
@@ -211,7 +211,7 @@ Parrot_io_finish(PARROT_INTERP)
/*
-=item C<void Parrot_io_marl(PARROT_INTERP, ParrotIOData *piodata)>
+=item C<void Parrot_io_mark(PARROT_INTERP, ParrotIOData *piodata)>
Called from C<Parrot_gc_trace_root()> to mark the standard IO handles
(C<stdin>, C<stdout> and C<stderr>) and other global data for the IO
@@ -1833,7 +1833,7 @@ Parrot_io_socket_new(PARROT_INTERP, INTVAL flags)
Gets the current handle flags.
-=item C<void Parrot_io_get_flags(PARROT_INTERP, PMC *handle, INTVAL flags)>
+=item C<void Parrot_io_set_flags(PARROT_INTERP, PMC *handle, INTVAL flags)>
Sets the current handle flags.
View
30 src/io/filehandle.c
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2001-2010, Parrot Foundation.
+Copyright (C) 2001-2012, Parrot Foundation.
=head1 NAME
@@ -13,7 +13,7 @@ L<src/platform/xxx/io.c>.
=cut
-=head2 Functions
+=head2 IO_VTABLE Functions
=over 4
@@ -618,8 +618,8 @@ io_filehandle_get_piohandle(PARROT_INTERP, ARGIN(PMC *handle))
/*
-=item C<void Parrot_io_set_os_handle(PARROT_INTERP, PMC *filehandle, PIOHANDLE
-file_descriptor)>
+=item C<void io_filehandle_set_os_handle(PARROT_INTERP, PMC *filehandle,
+PIOHANDLE file_descriptor)>
Sets the C<os_handle> attribute of the FileHandle object, which stores the
low-level filehandle for the OS.
@@ -645,7 +645,8 @@ io_filehandle_set_os_handle(SHIM_INTERP, ARGMOD(PMC *filehandle), PIOHANDLE file
/*
-=item C<PIOHANDLE Parrot_io_get_os_handle(PARROT_INTERP, const PMC *filehandle)>
+=item C<PIOHANDLE io_filehandle_get_os_handle(PARROT_INTERP, const PMC
+*filehandle)>
Retrieve the C<os_handle> attribute of the FileHandle object, which stores the
low-level filehandle for the OS.
@@ -679,7 +680,7 @@ io_filehandle_get_os_handle(SHIM_INTERP, ARGIN(const PMC *filehandle))
/*
-=item C<PIOOFF_T Parrot_io_get_file_position(PARROT_INTERP, const PMC
+=item C<PIOOFF_T io_filehandle_get_file_position(PARROT_INTERP, const PMC
*filehandle)>
Get the C<file_pos> attribute of the FileHandle object, which stores
@@ -704,7 +705,7 @@ io_filehandle_get_file_position(SHIM_INTERP, ARGIN(const PMC *filehandle))
/*
-=item C<void Parrot_io_set_file_position(PARROT_INTERP, PMC *filehandle,
+=item C<void io_filehandle_set_file_position(PARROT_INTERP, PMC *filehandle,
PIOOFF_T file_pos)>
Get the C<file_pos> attribute of the FileHandle object, which stores the
@@ -729,6 +730,21 @@ io_filehandle_set_file_position(SHIM_INTERP, ARGMOD(PMC *filehandle), PIOOFF_T f
handle_struct->file_pos = file_pos;
}
+/*
+
+=item C<const IO_VTABLE * io_filehandle_convert_to_pipe(PARROT_INTERP, PMC
+*handle)>
+
+Convert FileHandle C<handle> from file mode to pipe mode by swapping vtables.
+Return the Pipe vtable.
+
+Notice that this function may go away when FileHandle and Pipe are separate
+PMC types.
+
+=cut
+
+*/
+
PARROT_CANNOT_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
const IO_VTABLE *
View
242 src/io/pipe.c
@@ -1,3 +1,21 @@
+/*
+Copyright (C) 2001-2012, Parrot Foundation.
+
+=head1 NAME
+
+src/io/pipe.c - IO_VTABLE and helpers for Pipes
+
+=head1 DESCRIPTION
+
+This file implements the IO_VTABLE for pipes and helper functions.
+
+=cut
+
+=head2 IO_VTABLE Functions
+
+=over 4
+
+*/
#include "parrot/parrot.h"
#include "io_private.h"
@@ -10,7 +28,7 @@
static void io_pipe_adv_position(PARROT_INTERP,
ARGMOD(PMC *handle),
- PIOOFF_T offset)
+ size_t offset)
__attribute__nonnull__(1)
__attribute__nonnull__(2)
FUNC_MODIFIES(*handle);
@@ -76,7 +94,7 @@ static INTVAL io_pipe_read_b(PARROT_INTERP,
FUNC_MODIFIES(*handle)
FUNC_MODIFIES(*buffer);
-static INTVAL io_pipe_seek(PARROT_INTERP,
+static PIOOFF_T io_pipe_seek(PARROT_INTERP,
ARGMOD(PMC *handle),
PIOOFF_T offset,
INTVAL whence)
@@ -90,7 +108,7 @@ static void io_pipe_set_flags(PARROT_INTERP,
__attribute__nonnull__(1)
__attribute__nonnull__(2);
-static PIOOFF_T io_pipe_set_position(PARROT_INTERP,
+static void io_pipe_set_position(PARROT_INTERP,
ARGMOD(PMC *handle),
PIOOFF_T pos)
__attribute__nonnull__(1)
@@ -173,16 +191,26 @@ static INTVAL io_pipe_write_b(PARROT_INTERP,
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: static */
+/*
+
+=item C<void io_pipe_setup_vtable(PARROT_INTERP, IO_VTABLE *vtable, INTVAL idx)>
+
+Set up the Pipe IO_VTABLE.
+
+=cut
+
+*/
+
void
io_pipe_setup_vtable(PARROT_INTERP, ARGMOD_NULLOK(IO_VTABLE *vtable), INTVAL idx)
{
ASSERT_ARGS(io_pipe_setup_vtable)
if (vtable == NULL)
- vtable = &(interp->piodata->vtables[idx]);
+ vtable = (IO_VTABLE *)(&(interp->piodata->vtables[idx]));
vtable->number = idx;
- vtable->flags = PIO_VF_DEFAULT_READ_BUF
- | PIO_VF_MULTI_READABLE
- | PIO_VF_FLUSH_ON_CLOSE;
+ vtable->flags = PIO_VF_DEFAULT_READ_BUF /* Use read buffers by default */
+ | PIO_VF_MULTI_READABLE /* Can read multiple times without hanging */
+ | PIO_VF_FLUSH_ON_CLOSE; /* Flush handle on close */
vtable->name = "Pipe";
vtable->read_b = io_pipe_read_b;
vtable->write_b = io_pipe_write_b;
@@ -203,6 +231,17 @@ io_pipe_setup_vtable(PARROT_INTERP, ARGMOD_NULLOK(IO_VTABLE *vtable), INTVAL idx
vtable->get_piohandle = io_pipe_get_piohandle;
}
+/*
+
+=item C<static INTVAL io_pipe_read_b(PARROT_INTERP, PMC *handle, char *buffer,
+size_t byte_length)>
+
+Read up to C<byte_length> bytes from the pipe.
+
+=cut
+
+*/
+
static INTVAL
io_pipe_read_b(PARROT_INTERP, ARGMOD(PMC *handle), ARGOUT(char *buffer), size_t byte_length)
{
@@ -218,6 +257,17 @@ io_pipe_read_b(PARROT_INTERP, ARGMOD(PMC *handle), ARGOUT(char *buffer), size_t
return bytes_read;
}
+/*
+
+=item C<static INTVAL io_pipe_write_b(PARROT_INTERP, PMC *handle, char *buffer,
+size_t byte_length)>
+
+Write bytes to the pipe.
+
+=cut
+
+*/
+
static INTVAL
io_pipe_write_b(PARROT_INTERP, ARGMOD(PMC *handle), ARGIN(char *buffer), size_t byte_length)
{
@@ -226,15 +276,35 @@ io_pipe_write_b(PARROT_INTERP, ARGMOD(PMC *handle), ARGIN(char *buffer), size_t
return Parrot_io_internal_write(interp, os_handle, buffer, byte_length);
}
+/*
+
+=item C<static INTVAL io_pipe_flush(PARROT_INTERP, PMC *handle)>
+
+Flush the pipe.
+
+=cut
+
+*/
+
static INTVAL
io_pipe_flush(PARROT_INTERP, ARGMOD(PMC *handle))
{
ASSERT_ARGS(io_pipe_flush)
- // TODO: In read mode, don't do what this does.
+ /* TODO: In read mode, don't do what this does. */
PIOHANDLE os_handle = io_filehandle_get_os_handle(interp, handle);
return Parrot_io_internal_flush(interp, os_handle);
}
+/*
+
+=item C<static INTVAL io_pipe_is_eof(PARROT_INTERP, PMC *handle)>
+
+Determine if the pipe thinks it's at the end of input.
+
+=cut
+
+*/
+
static INTVAL
io_pipe_is_eof(PARROT_INTERP, ARGMOD(PMC *handle))
{
@@ -246,6 +316,16 @@ io_pipe_is_eof(PARROT_INTERP, ARGMOD(PMC *handle))
return 0;
}
+/*
+
+=item C<static PIOOFF_T io_pipe_tell(PARROT_INTERP, PMC *handle)>
+
+Pipes don't keep track of position. Throw an exception.
+
+=cut
+
+*/
+
static PIOOFF_T
io_pipe_tell(PARROT_INTERP, ARGMOD(PMC *handle))
{
@@ -255,7 +335,18 @@ io_pipe_tell(PARROT_INTERP, ARGMOD(PMC *handle))
return (PIOOFF_T)0;
}
-static INTVAL
+/*
+
+=item C<static PIOOFF_T io_pipe_seek(PARROT_INTERP, PMC *handle, PIOOFF_T
+offset, INTVAL whence)>
+
+Pipes don't seek. Throw an exception.
+
+=cut
+
+*/
+
+static PIOOFF_T
io_pipe_seek(PARROT_INTERP, ARGMOD(PMC *handle), PIOOFF_T offset, INTVAL whence)
{
ASSERT_ARGS(io_pipe_seek)
@@ -266,20 +357,52 @@ io_pipe_seek(PARROT_INTERP, ARGMOD(PMC *handle), PIOOFF_T offset, INTVAL whence)
return 0;
}
+/*
+
+=item C<static void io_pipe_adv_position(PARROT_INTERP, PMC *handle, size_t
+offset)>
+
+Pipes don't keep track of position. Ignore.
+
+=cut
+
+*/
+
static void
-io_pipe_adv_position(PARROT_INTERP, ARGMOD(PMC *handle), PIOOFF_T offset)
+io_pipe_adv_position(PARROT_INTERP, ARGMOD(PMC *handle), size_t offset)
{
ASSERT_ARGS(io_pipe_adv_position)
/* Pipes don't keep track of file position internally. Ignore this. */
}
-static PIOOFF_T
+/*
+
+=item C<static void io_pipe_set_position(PARROT_INTERP, PMC *handle, PIOOFF_T
+pos)>
+
+Pipes don't keep track of position. Ignore.
+
+=cut
+
+*/
+
+static void
io_pipe_set_position(PARROT_INTERP, ARGMOD(PMC *handle), PIOOFF_T pos)
{
ASSERT_ARGS(io_pipe_set_position)
/* Pipes don't keep track of file position internally. Ignore. */
}
+/*
+
+=item C<PIOOFF_T io_pipe_(PARROT_INTERP, PMC *handle)>
+
+Pipes don't keep track of position. Return 0.
+
+=cut
+
+*/
+
static PIOOFF_T
io_pipe_get_position(PARROT_INTERP, ARGMOD(PMC *handle))
{
@@ -288,6 +411,17 @@ io_pipe_get_position(PARROT_INTERP, ARGMOD(PMC *handle))
return (PIOOFF_T)0;
}
+/*
+
+=item C<static INTVAL io_pipe_open(PARROT_INTERP, PMC *handle, STRING *path,
+INTVAL flags, STRING *mode)>
+
+Open the pipe with the command in C<path>.
+
+=cut
+
+*/
+
static INTVAL
io_pipe_open(PARROT_INTERP, ARGMOD(PMC *handle), ARGIN(STRING *path), INTVAL flags, ARGIN(STRING *mode))
{
@@ -328,6 +462,16 @@ io_pipe_open(PARROT_INTERP, ARGMOD(PMC *handle), ARGIN(STRING *path), INTVAL fla
return 1;
}
+/*
+
+=item C<static INTVAL io_pipe_is_open(PARROT_INTERP, PMC *handle)>
+
+Determine if the pipe is currently open.
+
+=cut
+
+*/
+
static INTVAL
io_pipe_is_open(PARROT_INTERP, ARGMOD(PMC *handle))
{
@@ -336,6 +480,16 @@ io_pipe_is_open(PARROT_INTERP, ARGMOD(PMC *handle))
return os_handle != PIO_INVALID_HANDLE;
}
+/*
+
+=item C<static INTVAL io_pipe_close(PARROT_INTERP, PMC *handle)>
+
+Close the pipe.
+
+=cut
+
+*/
+
static INTVAL
io_pipe_close(PARROT_INTERP, ARGMOD(PMC *handle))
{
@@ -358,6 +512,17 @@ io_pipe_close(PARROT_INTERP, ARGMOD(PMC *handle))
}
}
+/*
+
+=item C<static const STR_VTABLE * io_pipe_get_encoding(PARROT_INTERP, PMC
+*handle)>
+
+Get the encoding used by the pipe.
+
+=cut
+
+*/
+
PARROT_CAN_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
static const STR_VTABLE *
@@ -373,6 +538,16 @@ io_pipe_get_encoding(PARROT_INTERP, ARGIN(PMC *handle))
return NULL;
}
+/*
+
+=item C<static void io_pipe_set_flags(PARROT_INTERP, PMC *handle, INTVAL flags)>
+
+Set flags on the Pipe.
+
+=cut
+
+*/
+
static void
io_pipe_set_flags(PARROT_INTERP, ARGIN(PMC *handle), INTVAL flags)
{
@@ -380,6 +555,16 @@ io_pipe_set_flags(PARROT_INTERP, ARGIN(PMC *handle), INTVAL flags)
PARROT_FILEHANDLE(handle)->flags = flags;
}
+/*
+
+=item C<static INTVAL io_pipe_get_flags(PARROT_INTERP, PMC *handle)>
+
+Get the flags from the pipe.
+
+=cut
+
+*/
+
static INTVAL
io_pipe_get_flags(PARROT_INTERP, ARGIN(PMC *handle))
{
@@ -387,6 +572,16 @@ io_pipe_get_flags(PARROT_INTERP, ARGIN(PMC *handle))
return PARROT_FILEHANDLE(handle)->flags;
}
+/*
+
+=item C<static size_t io_pipe_total_size(PARROT_INTERP, PMC *handle)>
+
+Pipes have an unknown total size.
+
+=cut
+
+*/
+
static size_t
io_pipe_total_size(PARROT_INTERP, ARGIN(PMC *handle))
{
@@ -394,9 +589,34 @@ io_pipe_total_size(PARROT_INTERP, ARGIN(PMC *handle))
return PIO_UNKNOWN_SIZE;
}
+/*
+
+=item C<static PIOHANDLE io_pipe_get_piohandle(PARROT_INTERP, PMC *handle)>
+
+Get the stream descriptor for the pipe.
+
+=cut
+
+*/
+
static PIOHANDLE
io_pipe_get_piohandle(PARROT_INTERP, ARGIN(PMC *handle))
{
ASSERT_ARGS(io_pipe_get_piohandle)
return io_filehandle_get_os_handle(interp, handle);
}
+
+/*
+
+=back
+
+=cut
+
+*/
+
+/*
+ * Local variables:
+ * c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
+ */
View
204 src/io/socket.c
@@ -3,13 +3,13 @@ Copyright (C) 2001-2011, Parrot Foundation.
=head1 NAME
-src/io/socket.c - Socket I/O API
+src/io/socket.c - Socket IO_VTABLE
=head1 DESCRIPTION
-These are the primary interface functions for working with socket objects.
+This file implements the Socket IO_VTABLE and some helper routines.
-=head2 Networking Functions
+=head2 IO_VTABLE Functions
=over 4
@@ -32,7 +32,7 @@ These are the primary interface functions for working with socket objects.
static void io_socket_adv_position(PARROT_INTERP,
ARGMOD(PMC *handle),
- PIOOFF_T offset)
+ size_t offset)
__attribute__nonnull__(1)
__attribute__nonnull__(2)
FUNC_MODIFIES(*handle);
@@ -98,7 +98,7 @@ static INTVAL io_socket_read_b(PARROT_INTERP,
FUNC_MODIFIES(*handle)
FUNC_MODIFIES(*buffer);
-static INTVAL io_socket_seek(PARROT_INTERP,
+static PIOOFF_T io_socket_seek(PARROT_INTERP,
ARGMOD(PMC *handle),
PIOOFF_T offset,
INTVAL whence)
@@ -112,7 +112,7 @@ static void io_socket_set_flags(PARROT_INTERP,
__attribute__nonnull__(1)
__attribute__nonnull__(2);
-static PIOOFF_T io_socket_set_position(PARROT_INTERP,
+static void io_socket_set_position(PARROT_INTERP,
ARGMOD(PMC *handle),
PIOOFF_T pos)
__attribute__nonnull__(1)
@@ -195,15 +195,26 @@ static INTVAL io_socket_write_b(PARROT_INTERP,
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: static */
+/*
+
+=item C<void io_socket_setup_vtable(PARROT_INTERP, IO_VTABLE *vtable, INTVAL
+idx)>
+
+Setup the Socket IO_VTABLE.
+
+=cut
+
+*/
+
void
io_socket_setup_vtable(PARROT_INTERP, ARGMOD_NULLOK(IO_VTABLE *vtable), INTVAL idx)
{
ASSERT_ARGS(io_socket_setup_vtable)
if (vtable == NULL)
- vtable = &(interp->piodata->vtables[idx]);
+ vtable = (IO_VTABLE *)(&(interp->piodata->vtables[idx]));
vtable->number = idx;
- vtable->flags = PIO_VF_DEFAULT_READ_BUF
- | PIO_VF_FLUSH_ON_CLOSE;
+ vtable->flags = PIO_VF_DEFAULT_READ_BUF /* Use a read buffer by default */
+ | PIO_VF_FLUSH_ON_CLOSE; /* Flush the socket on close */
vtable->name = "Socket";
vtable->read_b = io_socket_read_b;
vtable->write_b = io_socket_write_b;
@@ -223,6 +234,18 @@ io_socket_setup_vtable(PARROT_INTERP, ARGMOD_NULLOK(IO_VTABLE *vtable), INTVAL i
vtable->total_size = io_socket_total_size;
}
+/*
+
+=item C<static INTVAL io_socket_read_b(PARROT_INTERP, PMC *handle, char *buffer,
+size_t byte_length)>
+
+Read a number of bytes from the socket with C<recv>. Notice that C<recv> may
+hang if there is no data to read, so don't call it too often.
+
+=cut
+
+*/
+
static INTVAL
io_socket_read_b(PARROT_INTERP, ARGMOD(PMC *handle), ARGOUT(char *buffer), size_t byte_length)
{
@@ -232,6 +255,17 @@ io_socket_read_b(PARROT_INTERP, ARGMOD(PMC *handle), ARGOUT(char *buffer), size_
return Parrot_io_internal_recv(interp, os_handle, buffer, byte_length);
}
+/*
+
+=item C<static INTVAL io_socket_write_b(PARROT_INTERP, PMC *handle, char
+*buffer, size_t byte_length)>
+
+Write a number of bytes to the socket with C<send>.
+
+=cut
+
+*/
+
static INTVAL
io_socket_write_b(PARROT_INTERP, ARGMOD(PMC *handle), ARGIN(char *buffer), size_t byte_length)
{
@@ -241,6 +275,16 @@ io_socket_write_b(PARROT_INTERP, ARGMOD(PMC *handle), ARGIN(char *buffer), size_
return Parrot_io_internal_send(interp, os_handle, buffer, byte_length);
}
+/*
+
+=item C<static INTVAL io_socket_flush(PARROT_INTERP, PMC *handle)>
+
+Flush the socket. Currently this does nothing.
+
+=cut
+
+*/
+
static INTVAL
io_socket_flush(PARROT_INTERP, ARGMOD(PMC *handle))
{
@@ -249,43 +293,94 @@ io_socket_flush(PARROT_INTERP, ARGMOD(PMC *handle))
return 0;
}
+/*
+
+=item C<static INTVAL io_socket_is_eof(PARROT_INTERP, PMC *handle)>
+
+Sockets do not have a concept of EOF. This throws an exception.
+
+=cut
+
+*/
+
static INTVAL
io_socket_is_eof(PARROT_INTERP, ARGMOD(PMC *handle))
{
ASSERT_ARGS(io_socket_is_eof)
- IO_VTABLE * const vtable = IO_GET_VTABLE(interp, handle);
+ const IO_VTABLE * const vtable = IO_GET_VTABLE(interp, handle);
IO_VTABLE_UNIMPLEMENTED(interp, vtable, "eof");
return 0;
}
+/*
+
+=item C<static PIOOFF_T io_socket_tell(PARROT_INTERP, PMC *handle)>
+
+Sockets do not have tell. Throw an exception.
+
+=cut
+
+*/
+
static PIOOFF_T
io_socket_tell(PARROT_INTERP, ARGMOD(PMC *handle))
{
ASSERT_ARGS(io_socket_tell)
- IO_VTABLE * const vtable = IO_GET_VTABLE(interp, handle);
+ const IO_VTABLE * const vtable = IO_GET_VTABLE(interp, handle);
IO_VTABLE_UNIMPLEMENTED(interp, vtable, "tell");
return (PIOOFF_T)0;
}
-static INTVAL
+/*
+
+=item C<static PIOOFF_T io_socket_seek(PARROT_INTERP, PMC *handle, PIOOFF_T
+offset, INTVAL whence)>
+
+Sockets do not have a concept of seek. Throw an exception.
+
+=cut
+
+*/
+
+static PIOOFF_T
io_socket_seek(PARROT_INTERP, ARGMOD(PMC *handle), PIOOFF_T offset, INTVAL whence)
{
ASSERT_ARGS(io_socket_seek)
UNUSED(offset);
UNUSED(whence);
- IO_VTABLE * const vtable = IO_GET_VTABLE(interp, handle);
+ const IO_VTABLE * const vtable = IO_GET_VTABLE(interp, handle);
IO_VTABLE_UNIMPLEMENTED(interp, vtable, "seek");
return 0;
}
+/*
+
+=item C<static void io_socket_adv_position(PARROT_INTERP, PMC *handle, size_t
+offset)>
+
+Do nothing. Sockets don't keep track of position.
+
+=item C<static void io_socket_set_position(PARROT_INTERP, PMC *handle, PIOOFF_T
+pos)>
+
+Do nothing. Sockets don't keep track of position.
+
+=item C<static PIOOFF_T io_socket_get_position(PARROT_INTERP, PMC *handle)>
+
+Do nothing. Sockets don't keep track of position.
+
+=cut
+
+*/
+
static void
-io_socket_adv_position(PARROT_INTERP, ARGMOD(PMC *handle), PIOOFF_T offset)
+io_socket_adv_position(PARROT_INTERP, ARGMOD(PMC *handle), size_t offset)
{
ASSERT_ARGS(io_socket_adv_position)
/* Socket doesn't keep track of position internally. Ignore this. */
}
-static PIOOFF_T
+static void
io_socket_set_position(PARROT_INTERP, ARGMOD(PMC *handle), PIOOFF_T pos)
{
ASSERT_ARGS(io_socket_set_position)
@@ -300,6 +395,17 @@ io_socket_get_position(PARROT_INTERP, ARGMOD(PMC *handle))
return (PIOOFF_T)0;
}
+/*
+
+=item C<static INTVAL io_socket_open(PARROT_INTERP, PMC *handle, STRING *path,
+INTVAL flags, STRING * mode)>
+
+Do nothing. Sockets use connect and accept instead of open.
+
+=cut
+
+*/
+
static INTVAL
io_socket_open(PARROT_INTERP, ARGMOD(PMC *handle), ARGIN(STRING *path),
INTVAL flags, ARGIN(STRING * mode))
@@ -312,6 +418,16 @@ io_socket_open(PARROT_INTERP, ARGMOD(PMC *handle), ARGIN(STRING *path),
return Parrot_io_internal_flush(interp, os_handle);
}
+/*
+
+=item C<static INTVAL io_socket_is_open(PARROT_INTERP, PMC *handle)>
+
+Determine if the socket is currently connected and open.
+
+=cut
+
+*/
+
static INTVAL
io_socket_is_open(PARROT_INTERP, ARGMOD(PMC *handle))
{
@@ -321,6 +437,16 @@ io_socket_is_open(PARROT_INTERP, ARGMOD(PMC *handle))
return os_handle != PIO_INVALID_HANDLE;
}
+/*
+
+=item C<static INTVAL io_socket_close(PARROT_INTERP, PMC *handle)>
+
+Disconnect the socket.
+
+=cut
+
+*/
+
static INTVAL
io_socket_close(PARROT_INTERP, ARGMOD(PMC *handle))
{
@@ -335,6 +461,21 @@ io_socket_close(PARROT_INTERP, ARGMOD(PMC *handle))
return result;
}
+/*
+
+=item C<static void io_socket_set_flags(PARROT_INTERP, PMC *handle, INTVAL
+flags)>
+
+Do nothing.
+
+=item C<static INTVAL io_socket_get_flags(PARROT_INTERP, PMC *handle)>
+
+Return C<PIO_F_WRITE | PIO_F_READ>. Sockets are always flagged r/w.
+
+=cut
+
+*/
+
static void
io_socket_set_flags(PARROT_INTERP, ARGIN(PMC *handle), INTVAL flags)
{
@@ -351,15 +492,35 @@ io_socket_get_flags(PARROT_INTERP, ARGIN(PMC *handle))
return PIO_F_WRITE | PIO_F_READ;
}
+/*
+
+=item C<static size_t io_socket_total_size(PARROT_INTERP, PMC *handle)>
+
+Return C<0>. Sockets do not have a concept of total size.
+
+=cut
+
+*/
+
static size_t
io_socket_total_size(PARROT_INTERP, ARGIN(PMC *handle))
{
ASSERT_ARGS(io_socket_total_size)
- IO_VTABLE * const vtable = IO_GET_VTABLE(interp, handle);
+ const IO_VTABLE * const vtable = IO_GET_VTABLE(interp, handle);
IO_VTABLE_UNIMPLEMENTED(interp, vtable, "total_size");
return (size_t)0;
}
+/*
+
+=item C<static PIOHANDLE io_socket_get_piohandle(PARROT_INTERP, PMC *handle)>
+
+Get the OS-level C<socket> object.
+
+=cut
+
+*/
+
static PIOHANDLE
io_socket_get_piohandle(PARROT_INTERP, ARGIN(PMC *handle))
{
@@ -369,6 +530,17 @@ io_socket_get_piohandle(PARROT_INTERP, ARGIN(PMC *handle))
return os_handle;
}
+/*
+
+=item C<static const STR_VTABLE * io_socket_get_encoding(PARROT_INTERP, PMC
+*handle)>
+
+Get the encoding of this socket, if one is set.
+
+=cut
+
+*/
+
PARROT_CAN_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
static const STR_VTABLE *
View
225 src/io/stringhandle.c
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2001-2010, Parrot Foundation.
+Copyright (C) 2001-2012, Parrot Foundation.
=head1 NAME
@@ -7,6 +7,13 @@ src/io/stringhandle.c - StringHandle vtables and helper routines
=head1 DESCRIPTION
+The StringHandle IO_VTABLE and helper methods.
+
+=cut
+
+=head2 IO_VTABLE Functions
+
+=over 4
=cut
@@ -23,7 +30,7 @@ src/io/stringhandle.c - StringHandle vtables and helper routines
static void io_stringhandle_adv_position(PARROT_INTERP,
ARGMOD(PMC *handle),
- PIOOFF_T offset)
+ size_t offset)
__attribute__nonnull__(1)
__attribute__nonnull__(2)
FUNC_MODIFIES(*handle);
@@ -91,7 +98,7 @@ static INTVAL io_stringhandle_read_b(PARROT_INTERP,
FUNC_MODIFIES(*handle)
FUNC_MODIFIES(*buffer);
-static INTVAL io_stringhandle_seek(PARROT_INTERP,
+static PIOOFF_T io_stringhandle_seek(PARROT_INTERP,
ARGMOD(PMC *handle),
PIOOFF_T offset,
INTVAL whence)
@@ -105,7 +112,7 @@ static void io_stringhandle_set_flags(PARROT_INTERP,
__attribute__nonnull__(1)
__attribute__nonnull__(2);
-static PIOOFF_T io_stringhandle_set_position(PARROT_INTERP,
+static void io_stringhandle_set_position(PARROT_INTERP,
ARGMOD(PMC *handle),
PIOOFF_T pos)
__attribute__nonnull__(1)
@@ -188,16 +195,27 @@ static INTVAL io_stringhandle_write_b(PARROT_INTERP,
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: static */
+/*
+
+=item C<void io_stringhandle_setup_vtable(PARROT_INTERP, IO_VTABLE *vtable,
+INTVAL idx)>
+
+Setup the Socket IO_VTABLE
+
+=cut
+
+*/
void
io_stringhandle_setup_vtable(PARROT_INTERP, ARGMOD_NULLOK(IO_VTABLE *vtable), INTVAL idx)
{
ASSERT_ARGS(io_stringhandle_setup_vtable)
- // TODO: readline and other operations requiring a buffer should be able to be
- // done on the stringhandle memory directly to save cycles. Consider a flag
- // PIO_VF_CUSTOM_BUFFER and new vtables to set up a custom buffer to be used
+ /* TODO: readline and other operations requiring a buffer should be able to be
+ done on the stringhandle memory directly to save cycles. Consider a flag
+ PIO_VF_CUSTOM_BUFFER and new vtables to set up a custom buffer to be used
+ */
if (vtable == NULL)
- vtable = &(interp->piodata->vtables[idx]);
+ vtable = (IO_VTABLE *)(&(interp->piodata->vtables[idx]));
vtable->number = idx;
vtable->flags =
PIO_VF_PATH_NOT_REQUIRED | /* StringHandle does not require a path to open */
@@ -224,6 +242,17 @@ io_stringhandle_setup_vtable(PARROT_INTERP, ARGMOD_NULLOK(IO_VTABLE *vtable), IN
vtable->get_piohandle = io_stringhandle_get_piohandle;
}
+/*
+
+=item C<static INTVAL io_stringhandle_read_b(PARROT_INTERP, PMC *handle, char
+*buffer, size_t byte_length)>
+
+Attempt to read C<byte_length> bytes from the stringhandle.
+
+=cut
+
+*/
+
static INTVAL
io_stringhandle_read_b(PARROT_INTERP, ARGMOD(PMC *handle), ARGOUT(char *buffer), size_t byte_length)
{
@@ -241,6 +270,17 @@ io_stringhandle_read_b(PARROT_INTERP, ARGMOD(PMC *handle), ARGOUT(char *buffer),
return byte_length;
}
+/*
+
+=item C<static INTVAL io_stringhandle_write_b(PARROT_INTERP, PMC *handle, char
+*buffer, size_t byte_length)>
+
+Write a number of bytes to the StringHandle.
+
+=cut
+
+*/
+
static INTVAL
io_stringhandle_write_b(PARROT_INTERP, ARGMOD(PMC *handle), ARGIN(char *buffer), size_t byte_length)
{
@@ -250,6 +290,7 @@ io_stringhandle_write_b(PARROT_INTERP, ARGMOD(PMC *handle), ARGIN(char *buffer),
GETATTR_StringHandle_stringhandle(interp, handle, old_string);
+ /* TODO: Only allocate more space if we don'thave enough available already */
new_string = io_get_new_empty_string(interp, encoding, -1, old_string->bufused + byte_length);
memcpy(new_string->_bufstart, old_string->_bufstart, old_string->bufused);
memcpy(((char*)new_string->_bufstart) + old_string->bufused, buffer, byte_length);
@@ -260,6 +301,16 @@ io_stringhandle_write_b(PARROT_INTERP, ARGMOD(PMC *handle), ARGIN(char *buffer),
return byte_length;
}
+/*
+
+=item C<static INTVAL io_stringhandle_flush(PARROT_INTERP, PMC *handle)>
+
+Clear the StringHandle.
+
+=cut
+
+*/
+
static INTVAL
io_stringhandle_flush(PARROT_INTERP, ARGMOD(PMC *handle))
{
@@ -268,6 +319,17 @@ io_stringhandle_flush(PARROT_INTERP, ARGMOD(PMC *handle))
return 0;
}
+/*
+
+=item C<static INTVAL io_stringhandle_is_eof(PARROT_INTERP, PMC *handle)>
+
+The StringHandle is at eof if the current read cursor is passed the end of the
+string contents.
+
+=cut
+
+*/
+
static INTVAL
io_stringhandle_is_eof(PARROT_INTERP, ARGMOD(PMC *handle))
{
@@ -279,6 +341,16 @@ io_stringhandle_is_eof(PARROT_INTERP, ARGMOD(PMC *handle))
return (UINTVAL)read_offs >= stringhandle->bufused;
}
+/*
+
+=item C<static PIOOFF_T io_stringhandle_tell(PARROT_INTERP, PMC *handle)>
+
+Get the current position of the cursor in the string.
+
+=cut
+
+*/
+
static PIOOFF_T
io_stringhandle_tell(PARROT_INTERP, ARGMOD(PMC *handle))
{
@@ -288,13 +360,25 @@ io_stringhandle_tell(PARROT_INTERP, ARGMOD(PMC *handle))
return (PIOOFF_T)read_offset;
}
-static INTVAL
+/*
+
+=item C<static PIOOFF_T io_stringhandle_seek(PARROT_INTERP, PMC *handle,
+PIOOFF_T offset, INTVAL whence)>
+
+Seek to the given position in the stringhandle.
+
+=cut
+
+*/
+
+static PIOOFF_T
io_stringhandle_seek(PARROT_INTERP, ARGMOD(PMC *handle), PIOOFF_T offset, INTVAL whence)
{
ASSERT_ARGS(io_stringhandle_seek)
INTVAL old_offs;
STRING *stringhandle;
INTVAL read_offs = 0;
+ /* TODO: Need more error checking */
switch (whence) {
case SEEK_SET:
/* Absolute seek, start from the beginning of the string */
@@ -315,17 +399,40 @@ io_stringhandle_seek(PARROT_INTERP, ARGMOD(PMC *handle), PIOOFF_T offset, INTVAL
"Cannot seek with mode %d", whence);
}
SETATTR_StringHandle_read_offset(interp, handle, read_offs);
- return 0; /* TODO: What should this be? */
+ return (PIOOFF_T)read_offs;
}
+/*
+
+=item C<static void io_stringhandle_adv_position(PARROT_INTERP, PMC *handle,
+size_t offset)>
+
+Do nothing. StringHandle keeps track of position directly and doesn't need
+to do it separately.
+
+=item C<static void io_stringhandle_set_position(PARROT_INTERP, PMC *handle,
+PIOOFF_T pos)>
+
+Do nothing. StringHandle keeps track of position directly and doesn't need to
+do it separately.
+
+=item C<static PIOOFF_T io_stringhandle_get_position(PARROT_INTERP, PMC
+*handle)>
+
+Fall back to io_stringhandle_tell;
+
+=cut
+
+*/
+
static void
-io_stringhandle_adv_position(PARROT_INTERP, ARGMOD(PMC *handle), PIOOFF_T offset)
+io_stringhandle_adv_position(PARROT_INTERP, ARGMOD(PMC *handle), size_t offset)
{
ASSERT_ARGS(io_stringhandle_adv_position)
/* StringHandle keeps track of position directly. Ignore this. */
}
-static PIOOFF_T
+static void
io_stringhandle_set_position(PARROT_INTERP, ARGMOD(PMC *handle), PIOOFF_T pos)
{
ASSERT_ARGS(io_stringhandle_set_position)
@@ -339,6 +446,17 @@ io_stringhandle_get_position(PARROT_INTERP, ARGMOD(PMC *handle))
return io_stringhandle_tell(interp, handle);
}
+/*
+
+=item C<static INTVAL io_stringhandle_open(PARROT_INTERP, PMC *handle, STRING
+*path, INTVAL flags, STRING *mode)>
+
+Open the StringHandle with the given mode and settings.
+
+=cut
+
+*/
+
static INTVAL
io_stringhandle_open(PARROT_INTERP, ARGMOD(PMC *handle), ARGIN(STRING *path), INTVAL flags, ARGIN(STRING *mode))
{
@@ -357,6 +475,16 @@ io_stringhandle_open(PARROT_INTERP, ARGMOD(PMC *handle), ARGIN(STRING *path), IN
return 1;
}
+/*
+
+=item C<static INTVAL io_stringhandle_is_open(PARROT_INTERP, PMC *handle)>
+
+Determine if the StringHandle currently thinks it is open.
+
+=cut
+
+*/
+
static INTVAL
io_stringhandle_is_open(PARROT_INTERP, ARGMOD(PMC *handle))
{
@@ -366,6 +494,16 @@ io_stringhandle_is_open(PARROT_INTERP, ARGMOD(PMC *handle))
return !STRING_IS_NULL(stringhandle);
}
+/*
+
+=item C<static INTVAL io_stringhandle_close(PARROT_INTERP, PMC *handle)>
+
+StringHandle doesn't really close. Reset the read offset.
+
+=cut
+
+*/
+
static INTVAL
io_stringhandle_close(PARROT_INTERP, ARGMOD(PMC *handle))
{
@@ -374,6 +512,16 @@ io_stringhandle_close(PARROT_INTERP, ARGMOD(PMC *handle))
return 1;
}
+/*
+
+=item C<static size_t io_stringhandle_total_size(PARROT_INTERP, PMC *handle)>
+
+Get the total size of the contents of the StringHandle.
+
+=cut
+
+*/
+
static size_t
io_stringhandle_total_size(PARROT_INTERP, ARGIN(PMC *handle))
{
@@ -385,6 +533,17 @@ io_stringhandle_total_size(PARROT_INTERP, ARGIN(PMC *handle))
return stringhandle->bufused;
}
+/*
+
+=item C<static PIOHANDLE io_stringhandle_get_piohandle(PARROT_INTERP, PMC
+*handle)>
+
+Throw an exception. StringHandle does not hold a valid PIOHANDLE.
+
+=cut
+
+*/
+
static PIOHANDLE
io_stringhandle_get_piohandle(PARROT_INTERP, ARGIN(PMC *handle))
{
@@ -394,6 +553,21 @@ io_stringhandle_get_piohandle(PARROT_INTERP, ARGIN(PMC *handle))
return PIO_INVALID_HANDLE;
}
+/*
+
+=item C<static void io_stringhandle_set_flags(PARROT_INTERP, PMC *handle, INTVAL
+flags)>
+
+Set the flags on the StringHandle.
+
+=item C<static INTVAL io_stringhandle_get_flags(PARROT_INTERP, PMC *handle)>
+
+Get the flags from the StringHandle.
+
+=cut
+
+*/
+
static void
io_stringhandle_set_flags(PARROT_INTERP, ARGIN(PMC *handle), INTVAL flags)
{
@@ -408,6 +582,17 @@ io_stringhandle_get_flags(PARROT_INTERP, ARGIN(PMC *handle))
return PARROT_STRINGHANDLE(handle)->flags;
}
+/*
+
+=item C<static const STR_VTABLE * io_stringhandle_get_encoding(PARROT_INTERP,
+PMC *handle)>
+
+Get the encoding from the StringHandle.
+
+=cut
+
+*/
+
PARROT_CAN_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
static const STR_VTABLE *
@@ -428,3 +613,19 @@ io_stringhandle_get_encoding(PARROT_INTERP, ARGIN(PMC *handle))
return Parrot_find_encoding_by_string(interp, encoding_str);
return Parrot_ascii_encoding_ptr;
}
+
+/*
+
+=back
+
+=cut
+
+*/
+
+/*
+ * Local variables:
+ * c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
+ */
+

No commit comments for this range

Something went wrong with that request. Please try again.