io.sockets: make host-name a hook and throw correct errors.

db4
John Benediktsson 2015-07-16 13:14:17 -07:00
parent 9946eefc88
commit 5d6632514a
3 changed files with 21 additions and 13 deletions

View File

@ -442,10 +442,7 @@ M: object resolve-localhost
{ T{ ipv4 f "0.0.0.0" } } { T{ ipv4 f "0.0.0.0" } }
? ; ? ;
: host-name ( -- string ) HOOK: host-name os ( -- string )
256 <byte-array> dup dup length gethostname
zero? [ "gethostname failed" throw ] unless
ascii alien>string ;
M: inet (client) resolve-host (client) ; M: inet (client) resolve-host (client) ;

View File

@ -1,10 +1,10 @@
! Copyright (C) 2004, 2008 Slava Pestov, Ivan Tikhonov. ! Copyright (C) 2004, 2008 Slava Pestov, Ivan Tikhonov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien alien.c-types alien.data alien.strings USING: accessors alien alien.c-types alien.data alien.strings
arrays classes.struct combinators destructors io.backend.unix arrays byte-arrays classes.struct combinators destructors
io.encodings.utf8 io.files io.pathnames io.sockets.private kernel io.backend.unix io.encodings.ascii io.encodings.utf8 io.files
libc locals math namespaces sequences system unix io.pathnames io.sockets.private kernel libc locals math
unix.ffi vocabs ; namespaces sequences system unix unix.ffi vocabs ;
EXCLUDE: io => read write ; EXCLUDE: io => read write ;
EXCLUDE: io.sockets => accept ; EXCLUDE: io.sockets => accept ;
IN: io.sockets.unix IN: io.sockets.unix
@ -182,4 +182,8 @@ M: local parse-sockaddr
drop drop
path>> utf8 alien>string <local> ; 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 os linux? [ "io.sockets.unix.linux" require ] when

View File

@ -1,10 +1,13 @@
! Copyright (C) 2007, 2009 Slava Pestov, Doug Coleman. ! Copyright (C) 2007, 2009 Slava Pestov, Doug Coleman.
! See http://factorcode.org/license.txt for BSD license. ! 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 USING: accessors alien alien.c-types alien.data alien.strings
io.sockets io.sockets.icmp io.sockets.private kernel libc locals byte-arrays classes.struct combinators destructors io.backend
math sequences system windows.errors windows.handles io.encodings.ascii io.files.windows io.ports io.sockets
windows.kernel32 windows.types windows.winsock ; 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 ; FROM: namespaces => get ;
IN: io.sockets.windows IN: io.sockets.windows
@ -318,3 +321,7 @@ M: windows (send) ( packet addrspec datagram -- )
[ wait-for-socket drop ] [ wait-for-socket drop ]
bi bi
] with-destructors ; ] with-destructors ;
M: windows host-name
256 [ <byte-array> dup ] keep gethostname socket-error
ascii alien>string ;