]> gitweb.factorcode.org Git - factor.git/commitdiff
Don't try to use ipv6 addresses if an OS can't bind to them
authorDoug Coleman <doug.coleman@gmail.com>
Tue, 21 Sep 2010 04:53:18 +0000 (23:53 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Tue, 21 Sep 2010 04:53:18 +0000 (23:53 -0500)
basis/io/servers/connection/connection.factor
basis/io/sockets/sockets.factor

index a6e13090a188e5b1469db946e811b82c523c55c9..e16f94e5056530b95ba6e7ab8741878df718e0aa 100644 (file)
@@ -87,9 +87,12 @@ M: f (>insecure) ;
     >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 ;
+    [ resolve-host ] map concat filter-ipv6 ;
 
 : accepted-connection ( remote local -- )
     [
index b1175a9bb57c32bd474811723dd40515e1468044..220587ef1fc596a19194b61c66a36455800d8294 100644 (file)
@@ -6,7 +6,7 @@ arrays io.encodings io.ports io.streams.duplex io.encodings.ascii
 alien.strings io.binary accessors destructors classes byte-arrays
 parser alien.c-types math.parser splitting grouping math assocs
 summary system vocabs.loader combinators present fry vocabs.parser
-classes.struct alien.data strings ;
+classes.struct alien.data strings io.encodings.binary ;
 IN: io.sockets
 
 << {
@@ -380,6 +380,9 @@ M: invalid-local-address summary
         [ 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 ] }