io.sockets: Fix send-once for inet6.

db4
Doug Coleman 2016-03-07 16:58:56 -08:00
parent 05a8ac2423
commit 027a9fb1a2
1 changed files with 25 additions and 21 deletions

View File

@ -8,7 +8,7 @@ grouping init io.backend io.binary io.encodings.ascii
io.encodings.binary io.pathnames io.ports io.streams.duplex io.encodings.binary io.pathnames io.ports io.streams.duplex
kernel locals math math.parser memoize namespaces present kernel locals math math.parser memoize namespaces present
sequences sequences.private splitting strings summary system sequences sequences.private splitting strings summary system
vocabs vocabs.parser ip-parser ip-parser.private ; vocabs vocabs.parser ip-parser ip-parser.private random ;
IN: io.sockets IN: io.sockets
<< { << {
@ -112,8 +112,6 @@ TUPLE: inet4 < ipv4 { port integer read-only } ;
: <inet4> ( host port -- inet4 ) : <inet4> ( host port -- inet4 )
over check-ipv4 inet4 boa ; over check-ipv4 inet4 boa ;
: <random-local-inet4> ( -- inet4 ) f 0 <inet4> ;
M: ipv4 with-port [ host>> ] dip <inet4> ; M: ipv4 with-port [ host>> ] dip <inet4> ;
M: inet4 parse-sockaddr ( sockaddr-in addrspec -- newaddrspec ) M: inet4 parse-sockaddr ( sockaddr-in addrspec -- newaddrspec )
@ -357,24 +355,6 @@ CONSTANT: datagram-size 65536
: send ( bytes addrspec datagram -- ) : send ( bytes addrspec datagram -- )
check-send (send) ; inline check-send (send) ; inline
: <random-local-datagram> ( -- datagram )
<random-local-inet4> <datagram> ;
: <random-local-broadcast> ( -- datagram )
<random-local-inet4> <broadcast> ;
: with-random-local-datagram ( quot -- )
[ <random-local-datagram> ] dip with-disposal ; inline
: with-random-local-broadcast ( quot -- )
[ <random-local-broadcast> ] dip with-disposal ; inline
: send-once ( bytes addrspec -- )
[ send ] with-random-local-datagram ;
: broadcast-once ( bytes addrspec -- )
[ send ] with-random-local-broadcast ;
MEMO: ipv6-supported? ( -- ? ) MEMO: ipv6-supported? ( -- ? )
[ "::1" 0 <inet6> binary <server> dispose t ] [ drop f ] recover ; [ "::1" 0 <inet6> binary <server> dispose t ] [ drop f ] recover ;
@ -455,6 +435,30 @@ M: invalid-local-address summary
: protocol-port ( protocol -- port ) : protocol-port ( protocol -- port )
[ f getservbyname [ port>> htons ] [ f ] if* ] [ f ] if* ; [ f getservbyname [ port>> htons ] [ f ] if* ] [ f ] if* ;
GENERIC: <random-local-inet> ( inet -- inet4 )
M: inet4 <random-local-inet> drop f 0 <inet4> ;
M: inet <random-local-inet> drop resolve-localhost random ;
M: inet6 <random-local-inet> drop f 0 <inet6> ;
: <random-local-datagram> ( inet -- datagram )
<random-local-inet> <datagram> ;
: <random-local-broadcast> ( inet -- datagram )
<random-local-inet> <broadcast> ;
: with-random-local-datagram ( quot -- )
[ dup <random-local-datagram> ] dip with-disposal ; inline
: with-random-local-broadcast ( quot -- )
[ dup <random-local-broadcast> ] dip with-disposal ; inline
: send-once ( bytes addrspec -- )
[ send ] with-random-local-datagram ;
: broadcast-once ( bytes addrspec -- )
[ send ] with-random-local-broadcast ;
{ {
{ [ os unix? ] [ "io.sockets.unix" require ] } { [ os unix? ] [ "io.sockets.unix" require ] }
{ [ os windows? ] [ "io.sockets.windows" require ] } { [ os windows? ] [ "io.sockets.windows" require ] }