HELP: resolve-host
{ $values { "addrspec" "an address specifier" } { "seq" "a sequence of address specifiers" } }
{ $description "Resolves host names to IP addresses." }
+{ $errors "Throws an " { $link addrinfo-error } " if the host name cannot be resolved." }
{ $examples
{ $code
"\"www.facebook.com\" resolve-host . "
}
} ;
-
HELP: with-local-address
{ $values { "addr" "an " { $link inet4 } " or " { $link inet6 } " address specifier" } { "quot" quotation } }
{ $description "Client sockets opened within the scope of the quotation passed to this combinator will have their local address bound to the given address." }
-USING: io.sockets io.sockets.private sequences math tools.test
-namespaces accessors kernel destructors calendar io.timeouts
+USING: continuations io.sockets io.sockets.private sequences math
+tools.test namespaces accessors kernel destructors calendar io.timeouts
io.encodings.utf8 io concurrency.promises threads
io.streams.string present system ;
IN: io.sockets.tests
[ 80 ] [ "http" protocol-port ] unit-test
[ f ] [ f protocol-port ] unit-test
+
+[ t ] [
+ [ "you-cant-resolve-me!" resolve-host ] [ addrinfo-error? ] recover
+] unit-test
M: inet6 protocol drop 0 ;
+ERROR: addrinfo-error n string ;
+
<PRIVATE
GENERIC: (get-local-address) ( handle remote -- sockaddr )
[ addrinfo>addrspec ] map
sift ;
-HOOK: addrinfo-error io-backend ( n -- )
+HOOK: addrinfo-error-string io-backend ( n -- string )
: prepare-addrinfo ( -- addrinfo )
addrinfo <struct>
C: <inet> inet
M: string resolve-host
- f prepare-addrinfo f void* <ref>
- [ getaddrinfo addrinfo-error ] keep void* deref addrinfo memory>struct
+ f prepare-addrinfo f void* <ref> [
+ getaddrinfo 0 or [
+ dup addrinfo-error-string addrinfo-error
+ ] unless-zero
+ ] keep void* deref addrinfo memory>struct
[ parse-addrinfo-list ] keep freeaddrinfo ;
M: string with-port <inet> ;
! 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
-classes.struct combinators destructors io.backend.unix
+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 ;
: set-socket-option ( fd level opt -- )
[ handle-fd ] 2dip 1 int <ref> dup byte-length setsockopt io-error ;
-M: unix addrinfo-error ( n -- )
- [ gai_strerror throw ] unless-zero ;
+M: unix addrinfo-error-string ( n -- string )
+ gai_strerror ;
M: unix sockaddr-of-family ( alien af -- addrspec )
{
: set-ioctl-socket ( handle cmd arg -- )\r
[ handle>> ] 2dip ulong <ref> ioctlsocket socket-error ;\r
\r
-M: windows addrinfo-error ( n -- )\r
- winsock-return-check ;\r
+M: windows addrinfo-error-string ( n -- string )\r
+ n>win32-error-string ;\r
\r
M: windows sockaddr-of-family ( alien af -- addrspec )\r
{\r