diff --git a/examples/io/httpd.pir b/examples/io/httpd.pir
index 3970d37..2def929 100644
a
|
b
|
|
93 | 93 | |
94 | 94 | .include "stat.pasm" |
95 | 95 | .include 'except_types.pasm' |
| 96 | .include 'socket.pasm' |
96 | 97 | |
97 | 98 | .sub main :main |
98 | 99 | .local pmc listener, work, fp |
… |
… |
|
112 | 113 | |
113 | 114 | # TODO provide sys/socket constants |
114 | 115 | listener = new 'Socket' |
115 | | listener.'socket'(2, 1, 6) # PF_INET, SOCK_STREAM, tcp |
| 116 | listener.'socket'(.PIO_PF_INET, .PIO_SOCK_STREAM, .PIO_PROTO_TCP) # PF_INET, SOCK_STREAM, tcp |
116 | 117 | unless listener goto ERR_NO_SOCKET |
117 | 118 | |
118 | 119 | # Pack a sockaddr_in structure with IP and port |
diff --git a/include/parrot/io.h b/include/parrot/io.h
index 54fcaaf..03facfb 100644
a
|
b
|
|
905 | 905 | #define PIOCTL_LINEBUF 1 |
906 | 906 | #define PIOCTL_BLKBUF 2 |
907 | 907 | |
| 908 | /* |
| 909 | * Enum definition of constants for Socket.socket. |
| 910 | * Happens to be same for corresponding values on Linux. Other implementations |
| 911 | * of socket API may have to map this values to system specific. |
| 912 | */ |
908 | 913 | |
| 914 | /* &gen_from_enum(socket.pasm) */ |
| 915 | typedef enum { |
| 916 | PIO_PF_LOCAL = 0, |
| 917 | PIO_PF_UNIX = 1, |
| 918 | PIO_PF_INET = 2, |
| 919 | PIO_PF_INET6 = 3, |
| 920 | PIO_PF_MAX = 4 /* last elem */ |
| 921 | } Socket_Protocol_Family; |
| 922 | |
| 923 | typedef enum { |
| 924 | PIO_SOCK_STREAM = 1, |
| 925 | PIO_SOCK_DGRAM = 2, |
| 926 | PIO_SOCK_RAW = 3, |
| 927 | PIO_SOCK_RDM = 4, |
| 928 | PIO_SOCK_SEQPACKET = 5, |
| 929 | PIO_SOCK_PACKET = 10, |
| 930 | } Socket_Socket_Type; |
| 931 | |
| 932 | typedef enum { |
| 933 | PIO_PROTO_TCP = 6, |
| 934 | PIO_PROTO_UDP = 17, |
| 935 | } Socket_Protocol; |
| 936 | /* &end_gen */ |
909 | 937 | |
910 | 938 | #endif /* PARROT_IO_H_GUARD */ |
911 | 939 | |
diff --git a/src/io/socket_unix.c b/src/io/socket_unix.c
index 59f021f..b444e0c 100644
a
|
b
|
|
114 | 114 | # if PARROT_NET_DEVEL |
115 | 115 | |
116 | 116 | /* |
| 117 | * Mappping between PIO_PF_* constants and system-specific PF_* constants. |
| 118 | * |
| 119 | * Uses -1 for unsupported protocols. |
| 120 | */ |
| 121 | |
| 122 | static int pio_pf[PIO_PF_MAX+1] = { |
| 123 | PF_LOCAL, /* PIO_PF_LOCAL */ |
| 124 | PF_UNIX, /* PIO_PF_UNIX */ |
| 125 | PF_INET, /* PIO_PF_INET */ |
| 126 | PF_INET6, /* PIO_PF_INET6 */ |
| 127 | }; |
| 128 | |
| 129 | /* |
117 | 130 | |
118 | 131 | =item C<INTVAL Parrot_io_socket_unix> |
119 | 132 | |
… |
… |
|
131 | 144 | { |
132 | 145 | ASSERT_ARGS(Parrot_io_socket_unix) |
133 | 146 | int i = 1; |
| 147 | /* convert Parrot's family to system family */ |
| 148 | if (fam < 0 || fam >= PIO_PF_MAX) |
| 149 | return -1; |
| 150 | fam = pio_pf[fam]; |
| 151 | if (fam < 0) |
| 152 | return -1; |
| 153 | |
134 | 154 | const int sock = socket(fam, type, proto); |
135 | 155 | if (sock >= 0) { |
136 | 156 | setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &i, sizeof (i)); |
diff --git a/src/io/socket_win32.c b/src/io/socket_win32.c
index 6b1b13a..d93b7f3 100644
a
|
b
|
|
60 | 60 | PARROT_SOCKET((p))->remote)) |
61 | 61 | |
62 | 62 | /* |
| 63 | * Mappping between PIO_PF_* constants and system-specific PF_* constants. |
| 64 | * |
| 65 | * Uses -1 for unsupported protocols. |
| 66 | */ |
| 67 | |
| 68 | static int pio_pf[PIO_PF_MAX+1] = { |
| 69 | PF_LOCAL, /* PIO_PF_LOCAL */ |
| 70 | PF_UNIX, /* PIO_PF_UNIX */ |
| 71 | PF_INET, /* PIO_PF_INET */ |
| 72 | PF_INET6, /* PIO_PF_INET6 */ |
| 73 | }; |
| 74 | |
| 75 | /* |
63 | 76 | |
64 | 77 | =item C<INTVAL Parrot_io_socket_win32> |
65 | 78 | |
… |
… |
|
77 | 90 | { |
78 | 91 | ASSERT_ARGS(Parrot_io_socket_win32) |
79 | 92 | int i = 1; |
| 93 | /* convert Parrot's family to system family */ |
| 94 | if (fam < 0 || fam >= PIO_PF_MAX) |
| 95 | return -1; |
| 96 | fam = pio_pf[fam]; |
| 97 | if (fam < 0) |
| 98 | return -1; |
| 99 | |
80 | 100 | const int sock = socket(fam, type, proto); |
81 | 101 | if (sock >= 0) { |
82 | 102 | setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&i, sizeof (i)); |