>insecure
[ dup { [ secure? ] [ not ] } 1|| [ <secure> ] unless ] map ;
-: filter-ipv6 ( seq -- seq' )
- ipv6-supported? [ [ ipv6? not ] filter ] unless ;
-
: listen-on ( threaded-server -- addrspecs )
[ secure>> >secure ] [ insecure>> >insecure ] bi append
- [ resolve-host ] map concat filter-ipv6 ;
+ [ resolve-host ] map concat ;
: accepted-connection ( remote local -- )
[
USING: accessors alien.c-types alien.data alien.strings arrays
assocs byte-arrays classes classes.struct combinators
combinators.short-circuit continuations destructors fry generic
-grouping io.backend io.binary io.encodings io.encodings.ascii
-io.encodings.binary io.ports io.streams.duplex kernel math
-math.parser namespaces parser present sequences splitting
-strings summary system vocabs.loader vocabs.parser ;
+grouping init io.backend io.binary io.encodings
+io.encodings.ascii io.encodings.binary io.ports
+io.streams.duplex kernel math math.parser memoize namespaces
+parser present sequences splitting strings summary system
+vocabs.loader vocabs.parser ;
IN: io.sockets
<< {
: send ( packet addrspec datagram -- )
check-send (send) ;
+MEMO: ipv6-supported? ( -- ? )
+ [ "::1" 0 <inet6> binary <server> dispose t ] [ drop f ] recover ;
+
+[ \ ipv6-supported? reset-memoized ipv6-supported? drop ]
+"ipv6-support-check" add-startup-hook
+
GENERIC: resolve-host ( addrspec -- seq )
+HOOK: resolve-localhost os ( -- obj )
+
TUPLE: hostname { host ?string read-only } ;
TUPLE: inet < hostname port ;
M: local resolve-host 1array ;
M: f resolve-host
- drop { T{ ipv6 f "::" } T{ ipv4 f "0.0.0.0" } } ;
+ drop resolve-localhost ;
+
+M: object resolve-localhost
+ ipv6-supported? [
+ { T{ ipv4 f "0.0.0.0" } T{ ipv6 f "::" } }
+ ] [
+ { T{ ipv4 f "0.0.0.0" } }
+ ] if ;
: host-name ( -- string )
256 <byte-array> dup dup length gethostname
[ invalid-local-address ] if
] dip with-variable ; inline
-: ipv6-supported? ( -- ? )
- [ "::1" 0 <inet6> binary <server> dispose t ] [ drop f ] recover ;
-
{
{ [ os unix? ] [ "io.sockets.unix" require ] }
{ [ os windows? ] [ "io.sockets.windows" require ] }
! Copyright (C) 2004, 2008 Slava Pestov, Ivan Tikhonov.
! See http://factorcode.org/license.txt for BSD license.
-USING: alien alien.c-types alien.strings generic kernel math
-threads sequences byte-arrays io.binary io.backend.unix
-io.streams.duplex io.backend io.pathnames io.sockets.private
-io.files.private io.encodings.utf8 math.parser continuations
-libc combinators system accessors destructors unix locals init
-classes.struct alien.data unix.ffi ;
-
+USING: accessors alien alien.c-types alien.data alien.strings
+byte-arrays classes.struct combinators continuations
+destructors generic init io.backend io.backend.unix io.binary
+io.encodings.utf8 io.files.private io.pathnames
+io.sockets.private io.streams.duplex kernel libc locals math
+math.parser sequences system threads unix unix.ffi
+vocabs.loader ;
EXCLUDE: namespaces => bind ;
EXCLUDE: io => read write ;
EXCLUDE: io.sockets => accept ;
-
IN: io.sockets.unix
: socket-fd ( domain type protocol -- fd )
M: local parse-sockaddr
drop
path>> utf8 alien>string <local> ;
+
+os linux? [ "io.sockets.unix.linux" require ] when