Skip to content

Commit

Permalink
Port over a patch from @ocharles that add get_proto_by_name to Socket…
Browse files Browse the repository at this point in the history
  • Loading branch information
leto committed Dec 12, 2012
1 parent 48a2a41 commit bc6d9e6
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CREDITS
Expand Up @@ -908,6 +908,11 @@ E: mestre.smash@gmail.com
N: OOLLEY kj
D: Miscellaneous cleanup and PDD07-conformance

N: Oliver Charles
D: Initial patch to add 'getprotobyname' to Socket PMC
U: ocharles
E: oliver@ocharles.org.uk

N: Ovid
D: Rename 'pbc_to_c' to 'pbc_to_exe'

Expand Down
9 changes: 9 additions & 0 deletions include/parrot/io.h
Expand Up @@ -277,6 +277,12 @@ Parrot_io_fprintf(PARROT_INTERP,
__attribute__nonnull__(3)
FUNC_MODIFIES(*pmc);

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
INTVAL Parrot_io_get_proto_by_name(PARROT_INTERP, ARGIN(STRING * name))
__attribute__nonnull__(1)
__attribute__nonnull__(2);

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PIOHANDLE Parrot_io_getfd(PARROT_INTERP, ARGIN(PMC *pmc))
Expand Down Expand Up @@ -718,6 +724,9 @@ INTVAL Parrot_io_write_byte_buffer_pmc(PARROT_INTERP,
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(pmc) \
, PARROT_ASSERT_ARG(s))
#define ASSERT_ARGS_Parrot_io_get_proto_by_name __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(name))
#define ASSERT_ARGS_Parrot_io_getfd __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(pmc))
Expand Down
23 changes: 23 additions & 0 deletions src/io/api.c
Expand Up @@ -2113,6 +2113,29 @@ Parrot_io_reencode_string_for_handle(PARROT_INTERP, ARGIN(PMC *handle), ARGIN_NU
}
}

/*
=item C<INTVAL Parrot_io_get_proto_by_name(PARROT_INTERP, STRING * name)>
Return a protocol number given a protocol name.
=cut
*/



PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
INTVAL
Parrot_io_get_proto_by_name(PARROT_INTERP, ARGIN(STRING * name))
{
ASSERT_ARGS(Parrot_io_get_proto_by_name)

return PIO_GET_PROTO_BY_NAME(interp, name);
}



/*
Expand Down
26 changes: 26 additions & 0 deletions src/platform/generic/io.c
Expand Up @@ -514,6 +514,32 @@ Parrot_io_internal_pipe(SHIM_INTERP, ARGMOD(PIOHANDLE *reader), ARGMOD(PIOHANDLE
return rv;
}

/*
=item C<INTVAL Parrot_io_get_proto_by_name(PARROT_INTERP, STRING *name)>
Return a protocol number based on the name of a protocol
=cut
*/

PARROT_WARN_UNUSED_RESULT
INTVAL
Parrot_io_get_proto_by_name(PARROT_INTERP, ARGIN(STRING *name))
{
ASSERT_ARGS(Parrot_io_get_proto_by_name)

char * const s = Parrot_str_to_cstring(interp, name);
struct protoent * const protoent = getprotobyname(s);
int proto_number;

Parrot_str_free_cstring(s);
proto_number = protoent->p_proto;
return proto_number;
}


/*
=back
Expand Down
17 changes: 17 additions & 0 deletions src/pmc/socket.pmc
Expand Up @@ -267,6 +267,23 @@ Test if the socket is closed.

/*

=item C<getprotobyname(STRING * name)>

C<getprotobyname> returns a protocol number suitable for passing to
C<socket>, based on the given protocol name. This is normal only
necessary when opening sockets in raw mode.

=cut

*/

METHOD getprotobyname(STRING * name) {
INTVAL proto = Parrot_io_get_proto_by_name(INTERP, name);
RETURN(INTVAL proto);
}

/*

=item C<connect(PMC * address)>

Connects a socket object to an address.
Expand Down

2 comments on commit bc6d9e6

@ocharles
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\o/ Thanks @leto !

@leto
Copy link
Member Author

@leto leto commented on bc6d9e6 Dec 12, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some POD to please our POD-checking tests, but it still needs some love.

Please sign in to comment.