Skip to content

Commit

Permalink
Fix Parrot_io_socket semantics to return 1 on success. Add in a Parro…
Browse files Browse the repository at this point in the history
…t_io_socket_handle legacy wrapper with the old behavior. Re-implement Socket.socket. Some TODO notes.
  • Loading branch information
Whiteknight committed Jun 15, 2012
1 parent eca5d48 commit 9aeede6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
13 changes: 13 additions & 0 deletions include/parrot/io.h
Expand Up @@ -505,6 +505,17 @@ void Parrot_io_socket_connect(PARROT_INTERP,
FUNC_MODIFIES(*pmc)
FUNC_MODIFIES(*address);

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
INTVAL Parrot_io_socket_handle(PARROT_INTERP,
ARGMOD_NULLOK(PMC *socket),
INTVAL fam,
INTVAL type,
INTVAL proto)
__attribute__nonnull__(1)
FUNC_MODIFIES(*socket);

PARROT_EXPORT
void Parrot_io_socket_initialize(PARROT_INTERP, ARGMOD(PMC *socket))
__attribute__nonnull__(2)
Expand Down Expand Up @@ -767,6 +778,8 @@ INTVAL Parrot_io_write_byte_buffer_pmc(PARROT_INTERP,
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(pmc) \
, PARROT_ASSERT_ARG(address))
#define ASSERT_ARGS_Parrot_io_socket_handle __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_io_socket_initialize __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(socket))
#define ASSERT_ARGS_Parrot_io_socket_listen __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
Expand Down
18 changes: 17 additions & 1 deletion src/io/api.c
Expand Up @@ -338,6 +338,20 @@ the socket was successfully created.
*/

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
INTVAL
Parrot_io_socket_handle(PARROT_INTERP, ARGMOD_NULLOK(PMC *socket), INTVAL fam,
INTVAL type, INTVAL proto)
{
ASSERT_ARGS(Parrot_io_socket_handle)
Parrot_io_socket(interp, socket, fam, type, proto);
/* For historical reasons, this function always returns 0 to signal
unconditional success */
return 0;
}

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
Expand All @@ -363,7 +377,9 @@ Parrot_io_socket(PARROT_INTERP, ARGMOD_NULLOK(PMC *socket), INTVAL fam,
SETATTR_Socket_type(interp, new_socket, type);
SETATTR_Socket_protocol(interp, new_socket, proto);

return 0;
/* TODO: How do we signal errors here? */

return 1;
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/io/socket.c
Expand Up @@ -202,7 +202,7 @@ io_socket_setup_vtable(PARROT_INTERP, ARGMOD_NULLOK(IO_VTABLE *vtable), INTVAL i
if (vtable == NULL)
vtable = &(interp->piodata->vtables[idx]);
vtable->number = idx;
vtable->flags = PIO_VF_DEFAULT_BUFFERS | PIO_VF_FLUSH_ON_CLOSE;
vtable->flags = PIO_VF_FLUSH_ON_CLOSE;
vtable->name = "Socket";
vtable->read_b = io_socket_read_b;
vtable->write_b = io_socket_write_b;
Expand Down
5 changes: 3 additions & 2 deletions src/pmc/socket.pmc
Expand Up @@ -186,8 +186,9 @@ Returns whether the Socket is currently open.


METHOD socket(INTVAL fam, INTVAL type, INTVAL proto) {
// TODO: What to do here?
RETURN(PMC * SELF);
if (Parrot_io_socket(INTERP, SELF, fam, type, proto))
RETURN(PMC * SELF);
RETURN(PMC * PMCNULL);
}

/*
Expand Down

0 comments on commit 9aeede6

Please sign in to comment.