Ticket #527: socket6.patch

File socket6.patch, 4.6 KB (added by bacek, 13 years ago)

Lookup table for PIO_SOCK

  • include/parrot/io.h

    commit 4bb61f538a25a4f55b27d6e71c690df5980fbf68
    Author: Vasily Chekalkin <bacek@bacek.com>
    Date:   Wed Apr 1 07:08:12 2009 +1100
    
        Implement lookup table for PIO_SOCK_* constants
    
    diff --git a/include/parrot/io.h b/include/parrot/io.h
    index 3460363..77c9c6e 100644
    a b  
    922922} Socket_Protocol_Family; 
    923923 
    924924typedef enum { 
     925    PIO_SOCK_PACKET     = 0, 
    925926    PIO_SOCK_STREAM     = 1, 
    926927    PIO_SOCK_DGRAM      = 2, 
    927928    PIO_SOCK_RAW        = 3, 
    928929    PIO_SOCK_RDM        = 4, 
    929930    PIO_SOCK_SEQPACKET  = 5, 
    930     PIO_SOCK_PACKET     = 10, 
     931    PIO_SOCK_MAX        = 6 /* last element */ 
    931932} Socket_Socket_Type; 
    932933 
    933934typedef enum { 
  • src/io/socket_unix.c

    diff --git a/src/io/socket_unix.c b/src/io/socket_unix.c
    index b7d02f0..35b0be0 100644
    a b  
    114114#  if PARROT_NET_DEVEL 
    115115 
    116116/* 
    117  * Mappping between PIO_PF_* constants and system-specific PF_* constants. 
     117 * Mapping between PIO_PF_* constants and system-specific PF_* constants. 
    118118 * 
    119119 * Uses -1 for unsupported protocols. 
    120120 */ 
     
    143143}; 
    144144 
    145145/* 
     146 * Mapping between PIO_SOCK_* constants and system-specific SOCK_* constants. 
     147 * Uses -1 for unsupported socket types. 
     148 */ 
     149 
     150static int pio_sock[PIO_SOCK_MAX+1] = { 
     151#   ifdef SOCK_PACKET 
     152    SOCK_PACKET,    /* PIO_SOCK_PACKET */ 
     153#   else 
     154    -1,             /* PIO_SOCK_PACKET */ 
     155#   endif 
     156#   ifdef SOCK_STREAM 
     157    SOCK_STREAM,    /* PIO_SOCK_STREAM */ 
     158#   else 
     159    -1,             /* PIO_SOCK_STREAM */ 
     160#   endif 
     161#   ifdef SOCK_DGRAM 
     162    SOCK_DGRAM,     /* PIO_SOCK_DGRAM */ 
     163#   else 
     164    -1,             /* PIO_SOCK_DGRAM */ 
     165#   endif 
     166#   ifdef SOCK_RAW 
     167    SOCK_RAW,       /* PIO_SOCK_RAW */ 
     168#   else 
     169    -1,             /* PIO_SOCK_RAW */ 
     170#   endif 
     171#ifdef SOCK_RDM 
     172    SOCK_RDM,      /* PIO_SOCK_RDM */ 
     173#   else 
     174    -1,            /* PIO_SOCK_RDM */ 
     175#   endif 
     176#   ifdef SOCK_SEQPACKET 
     177    SOCK_SEQPACKET, /* PIO_SOCK_SEQPACKET */ 
     178#   else 
     179    -1,             /* PIO_SOCK_SEQPACKET */ 
     180#   endif 
     181}; 
     182 
     183/* 
    146184 
    147185=item C<INTVAL Parrot_io_socket_unix(PARROT_INTERP, PMC *s, int fam, int type, 
    148186int proto)> 
     
    168206    if (fam < 0) 
    169207        return -1; 
    170208 
     209    /* convert Parrot's socket type to system type */ 
     210    if (type < 0 || type >= PIO_SOCK_MAX) 
     211        return -1; 
     212    type = pio_sock[type]; 
     213    if (type < 0) 
     214        return -1; 
     215 
    171216    sock = socket(fam, type, proto); 
    172217    if (sock >= 0) { 
    173218        setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &i, sizeof (i)); 
  • src/io/socket_win32.c

    diff --git a/src/io/socket_win32.c b/src/io/socket_win32.c
    index a6e3403..c48b9d3 100644
    a b  
    6060                PARROT_SOCKET((p))->remote)) 
    6161 
    6262/* 
    63  * Mappping between PIO_PF_* constants and system-specific PF_* constants. 
     63 * Mapping between PIO_PF_* constants and system-specific PF_* constants. 
    6464 * 
    6565 * Uses -1 for unsupported protocols. 
    6666 */ 
     
    8989}; 
    9090 
    9191/* 
     92 * Mapping between PIO_SOCK_* constants and system-specific SOCK_* constants. 
     93 * Uses -1 for unsupported socket types. 
     94 */ 
     95 
     96static int pio_sock[PIO_SOCK_MAX+1] = { 
     97#   ifdef SOCK_PACKET 
     98    SOCK_PACKET,    /* PIO_SOCK_PACKET */ 
     99#   else 
     100    -1,             /* PIO_SOCK_PACKET */ 
     101#   endif 
     102#   ifdef SOCK_STREAM 
     103    SOCK_STREAM,    /* PIO_SOCK_STREAM */ 
     104#   else 
     105    -1,             /* PIO_SOCK_STREAM */ 
     106#   endif 
     107#   ifdef SOCK_DGRAM 
     108    SOCK_DGRAM,     /* PIO_SOCK_DGRAM */ 
     109#   else 
     110    -1,             /* PIO_SOCK_DGRAM */ 
     111#   endif 
     112#   ifdef SOCK_RAW 
     113    SOCK_RAW,       /* PIO_SOCK_RAW */ 
     114#   else 
     115    -1,             /* PIO_SOCK_RAW */ 
     116#   endif 
     117#ifdef SOCK_RDM 
     118    SOCK_RDM,      /* PIO_SOCK_RDM */ 
     119#   else 
     120    -1,            /* PIO_SOCK_RDM */ 
     121#   endif 
     122#   ifdef SOCK_SEQPACKET 
     123    SOCK_SEQPACKET, /* PIO_SOCK_SEQPACKET */ 
     124#   else 
     125    -1,             /* PIO_SOCK_SEQPACKET */ 
     126#   endif 
     127}; 
     128 
     129/* 
    92130 
    93131=item C<INTVAL Parrot_io_socket_win32(PARROT_INTERP, PMC * s, int fam, 
    94132int type, int proto)> 
     
    114152    if (fam < 0) 
    115153        return -1; 
    116154 
     155    /* convert Parrot's socket type to system type */ 
     156    if (type < 0 || type >= PIO_SOCK_MAX) 
     157        return -1; 
     158    type = pio_sock[type]; 
     159    if (type < 0) 
     160        return -1; 
     161 
    117162    sock = socket(fam, type, proto); 
    118163    if (sock >= 0) { 
    119164        setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&i, sizeof (i));