]> gitweb.factorcode.org Git - factor.git/commitdiff
io.sockets: make host-name a hook and throw correct errors.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 16 Jul 2015 20:14:17 +0000 (13:14 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 16 Jul 2015 20:15:14 +0000 (13:15 -0700)
basis/io/sockets/sockets.factor
basis/io/sockets/unix/unix.factor
basis/io/sockets/windows/windows.factor

index db968e1a7ca474080d3cd9da8dd2f20fb9c7f579..ff01ecf037b1f3e852e14509d7e4535387a9ebfd 100644 (file)
@@ -442,10 +442,7 @@ M: object resolve-localhost
     { T{ ipv4 f "0.0.0.0" } }
     ? ;
 
-: host-name ( -- string )
-    256 <byte-array> dup dup length gethostname
-    zero? [ "gethostname failed" throw ] unless
-    ascii alien>string ;
+HOOK: host-name os ( -- string )
 
 M: inet (client) resolve-host (client) ;
 
index 83ab45feae1af56e9fb075a49eafad4c49f495b6..5c57d304648c277e9048661d510f97405ce31d9c 100644 (file)
@@ -1,10 +1,10 @@
 ! Copyright (C) 2004, 2008 Slava Pestov, Ivan Tikhonov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors alien alien.c-types alien.data alien.strings
-arrays classes.struct combinators destructors io.backend.unix
-io.encodings.utf8 io.files io.pathnames io.sockets.private kernel
-libc locals math namespaces sequences system unix
-unix.ffi vocabs ;
+arrays byte-arrays classes.struct combinators destructors
+io.backend.unix io.encodings.ascii io.encodings.utf8 io.files
+io.pathnames io.sockets.private kernel libc locals math
+namespaces sequences system unix unix.ffi vocabs ;
 EXCLUDE: io => read write ;
 EXCLUDE: io.sockets => accept ;
 IN: io.sockets.unix
@@ -182,4 +182,8 @@ M: local parse-sockaddr
     drop
     path>> utf8 alien>string <local> ;
 
+M: unix host-name
+    256 [ <byte-array> dup ] keep gethostname io-error
+    ascii alien>string ;
+
 os linux? [ "io.sockets.unix.linux" require ] when
index 82eb08a83ebd4dea78cc7a4561673c2090e843f9..e45eef239356f0c0857c2de92f5bb5e2c02db7f5 100755 (executable)
@@ -1,10 +1,13 @@
 ! Copyright (C) 2007, 2009 Slava Pestov, Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien alien.c-types alien.data classes.struct
-combinators destructors io.backend io.files.windows io.ports
-io.sockets io.sockets.icmp io.sockets.private kernel libc locals
-math sequences system windows.errors windows.handles
-windows.kernel32 windows.types windows.winsock ;
+
+USING: accessors alien alien.c-types alien.data alien.strings
+byte-arrays classes.struct combinators destructors io.backend
+io.encodings.ascii io.files.windows io.ports io.sockets
+io.sockets.icmp io.sockets.private kernel libc locals math
+sequences system windows.errors windows.handles windows.kernel32
+windows.types windows.winsock ;
+
 FROM: namespaces => get ;
 IN: io.sockets.windows
 
@@ -318,3 +321,7 @@ M: windows (send) ( packet addrspec datagram -- )
         [ wait-for-socket drop ]
         bi
     ] with-destructors ;
+
+M: windows host-name
+    256 [ <byte-array> dup ] keep gethostname socket-error
+    ascii alien>string ;