]> gitweb.factorcode.org Git - factor.git/commitdiff
Only return ipv4 addresses for binding to on linux.
authorDoug Coleman <doug.coleman@gmail.com>
Thu, 23 Sep 2010 18:19:15 +0000 (13:19 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Thu, 23 Sep 2010 18:20:18 +0000 (13:20 -0500)
basis/io/servers/connection/connection.factor
basis/io/sockets/sockets.factor
basis/io/sockets/unix/linux/authors.txt [new file with mode: 0644]
basis/io/sockets/unix/linux/linux.factor [new file with mode: 0644]
basis/io/sockets/unix/linux/platforms.txt [new file with mode: 0644]
basis/io/sockets/unix/unix.factor

index 861a621de4c18d6b20eb583a529b1863fb907222..fbe5421ceae7e2c74ed1221c606d57353aacf952 100644 (file)
@@ -87,12 +87,9 @@ 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 filter-ipv6 ;
+    [ resolve-host ] map concat ;
 
 : accepted-connection ( remote local -- )
     [
index efafef9d31f0fab1163d860bad6baaa6061fcc0b..b2860b7f4abb7e9c1dc269c751f3bdc70db82ecb 100644 (file)
@@ -4,10 +4,11 @@
 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
 
 << {
@@ -349,8 +350,16 @@ SYMBOL: remote-address
 : 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 ;
@@ -378,7 +387,14 @@ M: inet6 resolve-host 1array ;
 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
@@ -407,9 +423,6 @@ 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 ] }
diff --git a/basis/io/sockets/unix/linux/authors.txt b/basis/io/sockets/unix/linux/authors.txt
new file mode 100644 (file)
index 0000000..7c1b2f2
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
diff --git a/basis/io/sockets/unix/linux/linux.factor b/basis/io/sockets/unix/linux/linux.factor
new file mode 100644 (file)
index 0000000..a2c4d96
--- /dev/null
@@ -0,0 +1,9 @@
+! Copyright (C) 2010 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: io.sockets kernel system ;
+IN: io.sockets.unix.linux
+
+! Linux seems to use the same port-space for ipv4 and ipv6.
+
+M: linux resolve-localhost { T{ ipv4 f "0.0.0.0" } } ;
+
diff --git a/basis/io/sockets/unix/linux/platforms.txt b/basis/io/sockets/unix/linux/platforms.txt
new file mode 100644 (file)
index 0000000..a08e1f3
--- /dev/null
@@ -0,0 +1 @@
+linux
index ee8563e27a715237b07781a2585e8046b0cf2d93..4d6c6992113ac758b84a6da8fd7201dc894b8ceb 100644 (file)
@@ -1,16 +1,15 @@
 ! 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 )
@@ -185,3 +184,5 @@ M: local make-sockaddr
 M: local parse-sockaddr
     drop
     path>> utf8 alien>string <local> ;
+
+os linux? [ "io.sockets.unix.linux" require ] when