io.sockets: make host-name a hook and throw correct errors.
parent
9946eefc88
commit
5d6632514a
|
@ -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) ;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 ;
|
||||
|
|
Loading…
Reference in New Issue