diff --git a/basis/io/sockets/sockets.factor b/basis/io/sockets/sockets.factor index a9f8912136..865239a934 100644 --- a/basis/io/sockets/sockets.factor +++ b/basis/io/sockets/sockets.factor @@ -8,7 +8,7 @@ grouping init io.backend io.binary io.encodings.ascii io.encodings.binary io.pathnames io.ports io.streams.duplex kernel locals math math.parser memoize namespaces present 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 << { @@ -112,8 +112,6 @@ TUPLE: inet4 < ipv4 { port integer read-only } ; : ( host port -- inet4 ) over check-ipv4 inet4 boa ; -: ( -- inet4 ) f 0 ; - M: ipv4 with-port [ host>> ] dip ; M: inet4 parse-sockaddr ( sockaddr-in addrspec -- newaddrspec ) @@ -357,24 +355,6 @@ CONSTANT: datagram-size 65536 : send ( bytes addrspec datagram -- ) check-send (send) ; inline -: ( -- datagram ) - ; - -: ( -- datagram ) - ; - -: with-random-local-datagram ( quot -- ) - [ ] dip with-disposal ; inline - -: with-random-local-broadcast ( quot -- ) - [ ] 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? ( -- ? ) [ "::1" 0 binary dispose t ] [ drop f ] recover ; @@ -455,6 +435,30 @@ M: invalid-local-address summary : protocol-port ( protocol -- port ) [ f getservbyname [ port>> htons ] [ f ] if* ] [ f ] if* ; + +GENERIC: ( inet -- inet4 ) +M: inet4 drop f 0 ; +M: inet drop resolve-localhost random ; +M: inet6 drop f 0 ; + +: ( inet -- datagram ) + ; + +: ( inet -- datagram ) + ; + +: with-random-local-datagram ( quot -- ) + [ dup ] dip with-disposal ; inline + +: with-random-local-broadcast ( quot -- ) + [ dup ] 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 windows? ] [ "io.sockets.windows" require ] }