[svn:parrot] r37834 - trunk/src/io
Infinoid at svn.parrot.org
Infinoid at svn.parrot.org
Wed Apr 1 05:22:40 UTC 2009
Author: Infinoid
Date: Wed Apr 1 05:22:39 2009
New Revision: 37834
URL: https://trac.parrot.org/parrot/changeset/37834
Log:
[io] Consolidate socket constant mappings
* The mappings from parrot socket constants to system socket constants are identical between the unix and win32 implementations. Consolidate them into the api source file.
Modified:
trunk/src/io/socket_api.c
trunk/src/io/socket_unix.c
trunk/src/io/socket_win32.c
Modified: trunk/src/io/socket_api.c
==============================================================================
--- trunk/src/io/socket_api.c Wed Apr 1 05:02:30 2009 (r37833)
+++ trunk/src/io/socket_api.c Wed Apr 1 05:22:39 2009 (r37834)
@@ -34,6 +34,75 @@
*/
+
+/*
+ * Mapping between PIO_PF_* constants and system-specific PF_* constants.
+ *
+ * Uses -1 for unsupported protocols.
+ */
+
+static int pio_pf[PIO_PF_MAX+1] = {
+# ifdef PF_LOCAL
+ PF_LOCAL, /* PIO_PF_LOCAL */
+# else
+ -1, /* PIO_PF_LOCAL */
+# endif
+# ifdef PF_UNIX
+ PF_UNIX, /* PIO_PF_UNIX */
+# else
+ -1, /* PIO_PF_UNIX */
+# endif
+# ifdef PF_INET
+ PF_INET, /* PIO_PF_INET */
+# else
+ -1, /* PIO_PF_INET */
+# endif
+# ifdef PF_INET6
+ PF_INET6, /* PIO_PF_INET6 */
+# else
+ -1, /* PIO_PF_INET6 */
+# endif
+};
+
+/*
+ * Mapping between PIO_SOCK_* constants and system-specific SOCK_* constants.
+ * Uses -1 for unsupported socket types.
+ */
+
+static int pio_sock[PIO_SOCK_MAX+1] = {
+# ifdef SOCK_PACKET
+ SOCK_PACKET, /* PIO_SOCK_PACKET */
+# else
+ -1, /* PIO_SOCK_PACKET */
+# endif
+# ifdef SOCK_STREAM
+ SOCK_STREAM, /* PIO_SOCK_STREAM */
+# else
+ -1, /* PIO_SOCK_STREAM */
+# endif
+# ifdef SOCK_DGRAM
+ SOCK_DGRAM, /* PIO_SOCK_DGRAM */
+# else
+ -1, /* PIO_SOCK_DGRAM */
+# endif
+# ifdef SOCK_RAW
+ SOCK_RAW, /* PIO_SOCK_RAW */
+# else
+ -1, /* PIO_SOCK_RAW */
+# endif
+# ifdef SOCK_RDM
+ SOCK_RDM, /* PIO_SOCK_RDM */
+# else
+ -1, /* PIO_SOCK_RDM */
+# endif
+# ifdef SOCK_SEQPACKET
+ SOCK_SEQPACKET, /* PIO_SOCK_SEQPACKET */
+# else
+ -1, /* PIO_SOCK_SEQPACKET */
+# endif
+};
+
+
PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
@@ -91,6 +160,20 @@
ASSERT_ARGS(Parrot_io_socket)
PMC *new_socket;
+ /* convert Parrot's family to system family */
+ if (fam < 0 || fam >= PIO_PF_MAX)
+ return -1;
+ fam = pio_pf[fam];
+ if (fam < 0)
+ return -1;
+
+ /* convert Parrot's socket type to system type */
+ if (type < 0 || type >= PIO_SOCK_MAX)
+ return -1;
+ type = pio_sock[type];
+ if (type < 0)
+ return -1;
+
if (PMC_IS_NULL(socket))
new_socket = Parrot_io_new_socket_pmc(interp,
PIO_F_SOCKET|PIO_F_READ|PIO_F_WRITE);
Modified: trunk/src/io/socket_unix.c
==============================================================================
--- trunk/src/io/socket_unix.c Wed Apr 1 05:02:30 2009 (r37833)
+++ trunk/src/io/socket_unix.c Wed Apr 1 05:22:39 2009 (r37834)
@@ -114,73 +114,6 @@
# if PARROT_NET_DEVEL
/*
- * Mapping between PIO_PF_* constants and system-specific PF_* constants.
- *
- * Uses -1 for unsupported protocols.
- */
-
-static int pio_pf[PIO_PF_MAX+1] = {
-# ifdef PF_LOCAL
- PF_LOCAL, /* PIO_PF_LOCAL */
-# else
- -1, /* PIO_PF_LOCAL */
-# endif
-# ifdef PF_UNIX
- PF_UNIX, /* PIO_PF_UNIX */
-# else
- -1, /* PIO_PF_UNIX */
-# endif
-# ifdef PF_INET
- PF_INET, /* PIO_PF_INET */
-# else
- -1, /* PIO_PF_INET */
-# endif
-# ifdef PF_INET6
- PF_INET6, /* PIO_PF_INET6 */
-# else
- -1, /* PIO_PF_INET6 */
-# endif
-};
-
-/*
- * Mapping between PIO_SOCK_* constants and system-specific SOCK_* constants.
- * Uses -1 for unsupported socket types.
- */
-
-static int pio_sock[PIO_SOCK_MAX+1] = {
-# ifdef SOCK_PACKET
- SOCK_PACKET, /* PIO_SOCK_PACKET */
-# else
- -1, /* PIO_SOCK_PACKET */
-# endif
-# ifdef SOCK_STREAM
- SOCK_STREAM, /* PIO_SOCK_STREAM */
-# else
- -1, /* PIO_SOCK_STREAM */
-# endif
-# ifdef SOCK_DGRAM
- SOCK_DGRAM, /* PIO_SOCK_DGRAM */
-# else
- -1, /* PIO_SOCK_DGRAM */
-# endif
-# ifdef SOCK_RAW
- SOCK_RAW, /* PIO_SOCK_RAW */
-# else
- -1, /* PIO_SOCK_RAW */
-# endif
-# ifdef SOCK_RDM
- SOCK_RDM, /* PIO_SOCK_RDM */
-# else
- -1, /* PIO_SOCK_RDM */
-# endif
-# ifdef SOCK_SEQPACKET
- SOCK_SEQPACKET, /* PIO_SOCK_SEQPACKET */
-# else
- -1, /* PIO_SOCK_SEQPACKET */
-# endif
-};
-
-/*
=item C<INTVAL Parrot_io_socket_unix(PARROT_INTERP, PMC *s, int fam, int type,
int proto)>
@@ -199,20 +132,6 @@
{
ASSERT_ARGS(Parrot_io_socket_unix)
int sock, i = 1;
- /* convert Parrot's family to system family */
- if (fam < 0 || fam >= PIO_PF_MAX)
- return -1;
- fam = pio_pf[fam];
- if (fam < 0)
- return -1;
-
- /* convert Parrot's socket type to system type */
- if (type < 0 || type >= PIO_SOCK_MAX)
- return -1;
- type = pio_sock[type];
- if (type < 0)
- return -1;
-
sock = socket(fam, type, proto);
if (sock >= 0) {
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &i, sizeof (i));
Modified: trunk/src/io/socket_win32.c
==============================================================================
--- trunk/src/io/socket_win32.c Wed Apr 1 05:02:30 2009 (r37833)
+++ trunk/src/io/socket_win32.c Wed Apr 1 05:22:39 2009 (r37834)
@@ -60,73 +60,6 @@
PARROT_SOCKET((p))->remote))
/*
- * Mapping between PIO_PF_* constants and system-specific PF_* constants.
- *
- * Uses -1 for unsupported protocols.
- */
-
-static int pio_pf[PIO_PF_MAX+1] = {
-# ifdef PF_LOCAL
- PF_LOCAL, /* PIO_PF_LOCAL */
-# else
- -1, /* PIO_PF_LOCAL */
-# endif
-# ifdef PF_UNIX
- PF_UNIX, /* PIO_PF_UNIX */
-# else
- -1, /* PIO_PF_UNIX */
-# endif
-# ifdef PF_INET
- PF_INET, /* PIO_PF_INET */
-# else
- -1, /* PIO_PF_INET */
-# endif
-# ifdef PF_INET6
- PF_INET6, /* PIO_PF_INET6 */
-# else
- -1, /* PIO_PF_INET6 */
-# endif
-};
-
-/*
- * Mapping between PIO_SOCK_* constants and system-specific SOCK_* constants.
- * Uses -1 for unsupported socket types.
- */
-
-static int pio_sock[PIO_SOCK_MAX+1] = {
-# ifdef SOCK_PACKET
- SOCK_PACKET, /* PIO_SOCK_PACKET */
-# else
- -1, /* PIO_SOCK_PACKET */
-# endif
-# ifdef SOCK_STREAM
- SOCK_STREAM, /* PIO_SOCK_STREAM */
-# else
- -1, /* PIO_SOCK_STREAM */
-# endif
-# ifdef SOCK_DGRAM
- SOCK_DGRAM, /* PIO_SOCK_DGRAM */
-# else
- -1, /* PIO_SOCK_DGRAM */
-# endif
-# ifdef SOCK_RAW
- SOCK_RAW, /* PIO_SOCK_RAW */
-# else
- -1, /* PIO_SOCK_RAW */
-# endif
-# ifdef SOCK_RDM
- SOCK_RDM, /* PIO_SOCK_RDM */
-# else
- -1, /* PIO_SOCK_RDM */
-# endif
-# ifdef SOCK_SEQPACKET
- SOCK_SEQPACKET, /* PIO_SOCK_SEQPACKET */
-# else
- -1, /* PIO_SOCK_SEQPACKET */
-# endif
-};
-
-/*
=item C<INTVAL Parrot_io_socket_win32(PARROT_INTERP, PMC * s, int fam,
int type, int proto)>
More information about the parrot-commits
mailing list