View source with raw comments or as raw
    1/*  Part of SWI-Prolog
    2
    3    Author:        Jan Wielemaker
    4    E-mail:        J.Wielemaker@vu.nl
    5    WWW:           http://www.swi-prolog.org
    6    Copyright (c)  2000-2018, University of Amsterdam
    7                              VU University Amsterdam
    8                              CWI, Amsterdam
    9    All rights reserved.
   10
   11    Redistribution and use in source and binary forms, with or without
   12    modification, are permitted provided that the following conditions
   13    are met:
   14
   15    1. Redistributions of source code must retain the above copyright
   16       notice, this list of conditions and the following disclaimer.
   17
   18    2. Redistributions in binary form must reproduce the above copyright
   19       notice, this list of conditions and the following disclaimer in
   20       the documentation and/or other materials provided with the
   21       distribution.
   22
   23    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   24    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   25    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   26    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   27    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   28    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   29    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   30    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   31    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   32    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   33    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   34    POSSIBILITY OF SUCH DAMAGE.
   35*/
   36
   37:- module(socket,
   38          [ tcp_socket/1,               % -Socket
   39            tcp_close_socket/1,         % +Socket
   40            tcp_open_socket/3,          % +Socket, -Read, -Write
   41            tcp_connect/2,              % +Socket, +Address
   42            tcp_connect/3,              % +Socket, +Address, -StreamPair
   43            tcp_connect/4,              % +Socket, +Address, -Read, -Write)
   44            tcp_bind/2,                 % +Socket, +Address
   45            tcp_accept/3,               % +Master, -Slave, -PeerName
   46            tcp_listen/2,               % +Socket, +BackLog
   47            tcp_fcntl/3,                % +Socket, +Command, ?Arg
   48            tcp_setopt/2,               % +Socket, +Option
   49            tcp_getopt/2,               % +Socket, ?Option
   50            tcp_host_to_address/2,      % ?HostName, ?Ip-nr
   51            tcp_select/3,               % +Inputs, -Ready, +Timeout
   52            gethostname/1,              % -HostName
   53
   54            tcp_open_socket/2,          % +Socket, -StreamPair
   55
   56            udp_socket/1,               % -Socket
   57            udp_receive/4,              % +Socket, -Data, -Sender, +Options
   58            udp_send/4,                 % +Socket, +Data, +Sender, +Options
   59
   60            negotiate_socks_connection/2% +DesiredEndpoint, +StreamPair
   61          ]).   62:- use_module(library(shlib)).   63:- use_module(library(debug)).   64:- use_module(library(lists)).

Network socket (TCP and UDP) library

The library(socket) provides TCP and UDP inet-domain sockets from SWI-Prolog, both client and server-side communication. The interface of this library is very close to the Unix socket interface, also supported by the MS-Windows winsock API. SWI-Prolog applications that wish to communicate with multiple sources have three options:

Client applications

Using this library to establish a TCP connection to a server is as simple as opening a file. See also http_open/3.

dump_swi_homepage :-
    setup_call_cleanup(
        tcp_connect(www.swi-prolog.org:http, Stream, []),
        ( format(Stream,
                 'GET / HTTP/1.1~n\c
                  Host: www.swi-prolog.org~n\c
                  Connection: close~n~n', []),
          flush_output(Stream),
          copy_stream_data(Stream, current_output)
        ),
        close(S)).

To deal with timeouts and multiple connections, threads, wait_for_input/3 and/or non-blocking streams (see tcp_fcntl/3) can be used.

Server applications

The typical sequence for generating a server application is given below. To close the server, use close/1 on AcceptFd.

create_server(Port) :-
      tcp_socket(Socket),
      tcp_bind(Socket, Port),
      tcp_listen(Socket, 5),
      tcp_open_socket(Socket, AcceptFd, _),
      <dispatch>

There are various options for <dispatch>. The most commonly used option is to start a Prolog thread to handle the connection. Alternatively, input from multiple clients can be handled in a single thread by listening to these clients using wait_for_input/3. Finally, on Unix systems, we can use fork/1 to handle the connection in a new process. Note that fork/1 and threads do not cooperate well. Combinations can be realised but require good understanding of POSIX thread and fork-semantics.

Below is the typical example using a thread. Note the use of setup_call_cleanup/3 to guarantee that all resources are reclaimed, also in case of failure or exceptions.

dispatch(AcceptFd) :-
        tcp_accept(AcceptFd, Socket, _Peer),
        thread_create(process_client(Socket, Peer), _,
                      [ detached(true)
                      ]),
        dispatch(AcceptFd).

process_client(Socket, Peer) :-
        setup_call_cleanup(
            tcp_open_socket(Socket, StreamPair),
            handle_service(In, StreamPair),
            close(StreamPair)).

handle_service(StreamPair) :-
        ...

Socket exceptions

Errors that are trapped by the low-level library are mapped to an exception of the shape below. In this term, Code is a lower case atom that corresponds to the C macro name, e.g., epipe for a broken pipe. Message is the human readable string for the error code returned by the OS or the same as Code if the OS does not provide this functionality. Note that Code is derived from a static set of macros that may or may not be defines for the target OS. If the macro name is not known, Code is ERROR_nnn, where nnn is an integer.

error(socket_error(Code, Message), _)

Note that on Windows Code is a wsa* code which makes it hard to write portable code that handles specific socket errors. Even on POSIX systems the exact set of errors produced by the network stack is not defined.

TCP socket predicates

*/

  171:- multifile
  172    tcp_connect_hook/3,             % +Socket, +Addr, -In, -Out
  173    tcp_connect_hook/4,             % +Socket, +Addr, -Stream
  174    proxy_for_url/3,                % +URL, +Host, -ProxyList
  175    try_proxy/4.                    % +Proxy, +Addr, -Socket, -Stream
  176
  177:- predicate_options(tcp_connect/3, 3,
  178                     [ bypass_proxy(boolean),
  179                       nodelay(boolean)
  180                     ]).  181
  182:- use_foreign_library(foreign(socket), install_socket).  183:- public tcp_debug/1.                  % set debugging.
 tcp_socket(-SocketId) is det
Creates an INET-domain stream-socket and unifies an identifier to it with SocketId. On MS-Windows, if the socket library is not yet initialised, this will also initialise the library.
 tcp_close_socket(+SocketId) is det
Closes the indicated socket, making SocketId invalid. Normally, sockets are closed by closing both stream handles returned by open_socket/3. There are two cases where tcp_close_socket/1 is used because there are no stream-handles:
 tcp_open_socket(+SocketId, -StreamPair) is det
Create streams to communicate to SocketId. If SocketId is a master socket (see tcp_bind/2), StreamPair should be used for tcp_accept/3. If SocketId is a connected (see tcp_connect/2) or accepted socket (see tcp_accept/3), StreamPair is unified to a stream pair (see stream_pair/3) that can be used for reading and writing. The stream or pair must be closed with close/1, which also closes SocketId.
  217tcp_open_socket(Socket, Stream) :-
  218    tcp_open_socket(Socket, In, Out),
  219    (   var(Out)
  220    ->  Stream = In
  221    ;   stream_pair(Stream, In, Out)
  222    ).
 tcp_open_socket(+SocketId, -InStream, -OutStream) is det
Similar to tcp_open_socket/2, but creates two separate sockets where tcp_open_socket/2 would have created a stream pair.
deprecated
- New code should use tcp_open_socket/2 because closing a stream pair is much easier to perform safely.
 tcp_bind(SocketId, ?Address) is det
Bind the socket to Address on the current machine. This operation, together with tcp_listen/2 and tcp_accept/3 implement the server-side of the socket interface. Address is either an plain Port or a term HostPort. The first form binds the socket to the given port on all interfaces, while the second only binds to the matching interface. A typical example is below, causing the socket to listen only on port 8080 on the local machine's network.
  tcp_bind(Socket, localhost:8080)

If Port is unbound, the system picks an arbitrary free port and unifies Port with the selected port number. Port is either an integer or the name of a registered service. See also tcp_connect/4.

 tcp_listen(+SocketId, +BackLog) is det
Tells, after tcp_bind/2, the socket to listen for incoming requests for connections. Backlog indicates how many pending connection requests are allowed. Pending requests are requests that are not yet acknowledged using tcp_accept/3. If the indicated number is exceeded, the requesting client will be signalled that the service is currently not available. A commonly used default value for Backlog is 5.
 tcp_accept(+Socket, -Slave, -Peer) is det
This predicate waits on a server socket for a connection request by a client. On success, it creates a new socket for the client and binds the identifier to Slave. Peer is bound to the IP-address of the client.
 tcp_connect(+SocketId, +HostAndPort) is det
Connect SocketId. After successful completion, tcp_open_socket/3 can be used to create I/O-Streams to the remote socket. This predicate is part of the low level client API. A connection to a particular host and port is realised using these steps:
    tcp_socket(Socket),
    tcp_connect(Socket, Host:Port),
    tcp_open_socket(Socket, StreamPair)

Typical client applications should use the high level interface provided by tcp_connect/3 which avoids resource leaking if a step in the process fails, and can be hooked to support proxies. For example:

    setup_call_cleanup(
        tcp_connect(Host:Port, StreamPair, []),
        talk(StreamPair),
        close(StreamPair))
  295                 /*******************************
  296                 *      HOOKABLE CONNECT        *
  297                 *******************************/
 tcp_connect(+Socket, +Address, -Read, -Write) is det
Connect a (client) socket to Address and return a bi-directional connection through the stream-handles Read and Write. This predicate may be hooked by defining tcp_connect_hook/4 with the same signature. Hooking can be used to deal with proxy connections. E.g.,
:- multifile socket:tcp_connect_hook/4.

socket:tcp_connect_hook(Socket, Address, Read, Write) :-
    proxy(ProxyAdress),
    tcp_connect(Socket, ProxyAdress),
    tcp_open_socket(Socket, Read, Write),
    proxy_connect(Address, Read, Write).
deprecated
- New code should use tcp_connect/3 called as tcp_connect(+Address, -StreamPair, +Options).
  320tcp_connect(Socket, Address, Read, Write) :-
  321    tcp_connect_hook(Socket, Address, Read, Write),
  322    !.
  323tcp_connect(Socket, Address, Read, Write) :-
  324    tcp_connect(Socket, Address),
  325    tcp_open_socket(Socket, Read, Write).
 tcp_connect(+Address, -StreamPair, +Options) is det
tcp_connect(+Socket, +Address, -StreamPair) is det
Establish a TCP communication as a client. The +,-,+ mode is the preferred way for a client to establish a connection. This predicate can be hooked to support network proxies. To use a proxy, the hook proxy_for_url/3 must be defined. Permitted options are:
bypass_proxy(+Boolean)
Defaults to false. If true, do not attempt to use any proxies to obtain the connection
nodelay(+Boolean)
Defaults to false. If true, set nodelay on the resulting socket using tcp_setopt(Socket, nodelay)

The +,+,- mode is deprecated and does not support proxies. It behaves like tcp_connect/4, but creates a stream pair (see stream_pair/3).

Errors
- proxy_error(tried(ResultList)) is raised by mode (+,-,+) if proxies are defines by proxy_for_url/3 but no proxy can establsh the connection. ResultList contains one or more terms of the form false(Proxy) for a hook that simply failed or error(Proxy, ErrorTerm) for a hook that raised an exception.
See also
- library(http/http_proxy) defines a hook that allows to connect through HTTP proxies that support the CONNECT method.
  359% Main mode: +,-,+
  360tcp_connect(Address, StreamPair, Options) :-
  361    var(StreamPair),
  362    !,
  363    (   memberchk(bypass_proxy(true), Options)
  364    ->  tcp_connect_direct(Address, Socket, StreamPair)
  365    ;   findall(Result,
  366                try_a_proxy(Address, Result),
  367                ResultList),
  368        last(ResultList, Status)
  369    ->  (   Status = true(_Proxy, Socket, StreamPair)
  370        ->  true
  371        ;   throw(error(proxy_error(tried(ResultList)), _))
  372        )
  373    ;   tcp_connect_direct(Address, Socket, StreamPair)
  374    ),
  375    (   memberchk(nodelay(true), Options)
  376    ->  tcp_setopt(Socket, nodelay)
  377    ;   true
  378    ).
  379% backward compatibility mode +,+,-
  380tcp_connect(Socket, Address, StreamPair) :-
  381    tcp_connect_hook(Socket, Address, StreamPair0),
  382    !,
  383    StreamPair = StreamPair0.
  384tcp_connect(Socket, Address, StreamPair) :-
  385    tcp_connect(Socket, Address, Read, Write),
  386    stream_pair(StreamPair, Read, Write).
  387
  388
  389tcp_connect_direct(Address, Socket, StreamPair):-
  390    tcp_socket(Socket),
  391    catch(tcp_connect(Socket, Address, StreamPair),
  392          Error,
  393          ( tcp_close_socket(Socket),
  394            throw(Error)
  395          )).
 tcp_select(+ListOfStreams, -ReadyList, +TimeOut)
Same as the built-in wait_for_input/3. Used to allow for interrupts and timeouts on Windows. A redesign of the Windows socket interface makes it impossible to do better than Windows select() call underlying wait_for_input/3. As input multiplexing typically happens in a background thread anyway we accept the loss of timeouts and interrupts.
deprecated
- Use wait_for_input/3
  408tcp_select(ListOfStreams, ReadyList, TimeOut) :-
  409    wait_for_input(ListOfStreams, ReadyList, TimeOut).
  410
  411
  412                 /*******************************
  413                 *        PROXY SUPPORT         *
  414                 *******************************/
  415
  416try_a_proxy(Address, Result) :-
  417    format(atom(URL), 'socket://~w', [Address]),
  418    (   Address = Host:_
  419    ->  true
  420    ;   Host = Address
  421    ),
  422    proxy_for_url(URL, Host, Proxy),
  423    debug(socket(proxy), 'Socket connecting via ~w~n', [Proxy]),
  424    (   catch(try_proxy(Proxy, Address, Socket, Stream), E, true)
  425    ->  (   var(E)
  426        ->  !, Result = true(Proxy, Socket, Stream)
  427        ;   Result = error(Proxy, E)
  428        )
  429    ;   Result = false(Proxy)
  430    ),
  431    debug(socket(proxy), 'Socket: ~w: ~p', [Proxy, Result]).
 try_proxy(+Proxy, +TargetAddress, -Socket, -StreamPair) is semidet
Attempt a socket-level connection via the given proxy to TargetAddress. The Proxy argument must match the output argument of proxy_for_url/3. The predicate tcp_connect/3 (and http_open/3 from the library(http/http_open)) collect the results of failed proxies and raise an exception no proxy is capable of realizing the connection.

The default implementation recognises the values for Proxy described below. The library(http/http_proxy) adds proxy(Host,Port) which allows for HTTP proxies using the CONNECT method.

direct
Do not use any proxy
socks(Host, Port)
Use a SOCKS5 proxy
  452:- multifile
  453    try_proxy/4.  454
  455try_proxy(direct, Address, Socket, StreamPair) :-
  456    !,
  457    tcp_connect_direct(Address, Socket, StreamPair).
  458try_proxy(socks(Host, Port), Address, Socket, StreamPair) :-
  459    !,
  460    tcp_connect_direct(Host:Port, Socket, StreamPair),
  461    catch(negotiate_socks_connection(Address, StreamPair),
  462          Error,
  463          ( close(StreamPair, [force(true)]),
  464            throw(Error)
  465          )).
 proxy_for_url(+URL, +Hostname, -Proxy) is nondet
This hook can be implemented to return a proxy to try when connecting to URL. Returned proxies are tried in the order in which they are returned by the multifile hook try_proxy/4. Pre-defined proxy methods are:
direct
connect directly to the resource
proxy(Host, Port)
Connect to the resource using an HTTP proxy. If the resource is not an HTTP URL, then try to connect using the CONNECT verb, otherwise, use the GET verb.
socks(Host, Port)
Connect to the resource via a SOCKS5 proxy

These correspond to the proxy methods defined by PAC Proxy auto-config. Additional methods can be returned if suitable clauses for http:http_connection_over_proxy/6 or try_proxy/4 are defined.

  488:- multifile
  489    proxy_for_url/3.  490
  491
  492                 /*******************************
  493                 *            OPTIONS           *
  494                 *******************************/
 tcp_setopt(+SocketId, +Option) is det
Set options on the socket. Defined options are:
reuseaddr
Allow servers to reuse a port without the system being completely sure the port is no longer in use.
bindtodevice(+Device)
Bind the socket to Device (an atom). For example, the code below binds the socket to the loopback device that is typically used to realise the localhost. See the manual pages for setsockopt() and the socket interface (e.g., socket(7) on Linux) for details.
tcp_socket(Socket),
tcp_setopt(Socket, bindtodevice(lo))
nodelay
nodelay(true)
If true, disable the Nagle optimization on this socket, which is enabled by default on almost all modern TCP/IP stacks. The Nagle optimization joins small packages, which is generally desirable, but sometimes not. Please note that the underlying TCP_NODELAY setting to setsockopt() is not available on all platforms and systems may require additional privileges to change this option. If the option is not supported, tcp_setopt/2 raises a domain_error exception. See Wikipedia for details.
broadcast
UDP sockets only: broadcast the package to all addresses matching the address. The address is normally the address of the local subnet (i.e. 192.168.1.255). See udp_send/4.
ip_add_membership(+MultiCastGroup)
ip_add_membership(+MultiCastGroup, +LocalInterface)
ip_add_membership(+MultiCastGroup, +LocalInterface, +InterfaceIndex)
ip_drop_membership(+MultiCastGroup)
ip_drop_membership(+MultiCastGroup, +LocalInterface)
ip_drop_membership(+MultiCastGroup, +LocalInterface, +InterfaceIndex)
Join/leave a multicast group. Calls setsockopt() with the corresponding arguments.
dispatch(+Boolean)
In GUI environments (using XPCE or the Windows swipl-win.exe executable) this flags defines whether or not any events are dispatched on behalf of the user interface. Default is true. Only very specific situations require setting this to false.
sndbuf(+Integer)
Sets the send buffer size to Integer (bytes). On Windows this defaults (now) to 64kb. Higher latency links may benefit from increasing this further since the maximum theoretical throughput on a link is given by buffer-size / latency. See https://support.microsoft.com/en-gb/help/823764/slow-performance-occurs-when-you-copy-data-to-a-tcp-server-by-using-a for Microsoft's discussion
 tcp_fcntl(+Stream, +Action, ?Argument) is det
Interface to the fcntl() call. Currently only suitable to deal switch stream to non-blocking mode using:
  tcp_fcntl(Stream, setfl, nonblock),

An attempt to read from a non-blocking stream while there is no data available returns -1 (or end_of_file for read/1), but at_end_of_stream/1 fails. On actual end-of-input, at_end_of_stream/1 succeeds.

  572tcp_fcntl(Socket, setfl, nonblock) :-
  573    !,
  574    tcp_setopt(Socket, nonblock).
 tcp_getopt(+Socket, ?Option) is semidet
Get information about Socket. Defined properties are below. Requesting an unknown option results in a domain_error exception.
file_no(-File)
Get the OS file handle as an integer. This may be used for debugging and integration.
 tcp_host_to_address(?HostName, ?Address) is det
Translate between a machines host-name and it's (IP-)address. If HostName is an atom, it is resolved using getaddrinfo() and the IP-number is unified to Address using a term of the format ip(Byte1,Byte2,Byte3,Byte4). Otherwise, if Address is bound to an ip(Byte1,Byte2,Byte3,Byte4) term, it is resolved by gethostbyaddr() and the canonical hostname is unified with HostName.
To be done
- This function should support more functionality provided by gethostbyaddr, probably by adding an option-list.
 gethostname(-Hostname) is det
Return the canonical fully qualified name of this host. This is achieved by calling gethostname() and return the canonical name returned by getaddrinfo().
  605                 /*******************************
  606                 *            SOCKS             *
  607                 *******************************/
 negotiate_socks_connection(+DesiredEndpoint, +StreamPair) is det
Negotiate a connection to DesiredEndpoint over StreamPair. DesiredEndpoint should be in the form of either:
Errors
- socks_error(Details) if the SOCKS negotiation failed.
  619negotiate_socks_connection(Host:Port, StreamPair):-
  620    format(StreamPair, '~s', [[0x5,    % Version 5
  621                               0x1,    % 1 auth method supported
  622                               0x0]]), % which is 'no auth'
  623    flush_output(StreamPair),
  624    get_byte(StreamPair, ServerVersion),
  625    get_byte(StreamPair, AuthenticationMethod),
  626    (   ServerVersion =\= 0x05
  627    ->  throw(error(socks_error(invalid_version(5, ServerVersion)), _))
  628    ;   AuthenticationMethod =:= 0xff
  629    ->  throw(error(socks_error(invalid_authentication_method(
  630                                    0xff,
  631                                    AuthenticationMethod)), _))
  632    ;   true
  633    ),
  634    (   Host = ip(A,B,C,D)
  635    ->  AddressType = 0x1,                  % IPv4 Address
  636        format(atom(Address), '~s', [[A, B, C, D]])
  637    ;   AddressType = 0x3,                  % Domain
  638        atom_length(Host, Length),
  639        format(atom(Address), '~s~w', [[Length], Host])
  640    ),
  641    P1 is Port /\ 0xff,
  642    P2 is Port >> 8,
  643    format(StreamPair, '~s~w~s', [[0x5,   % Version 5
  644                                   0x1,   % Please establish a connection
  645                                   0x0,   % reserved
  646                                   AddressType],
  647                                  Address,
  648                                  [P2, P1]]),
  649    flush_output(StreamPair),
  650    get_byte(StreamPair, _EchoedServerVersion),
  651    get_byte(StreamPair, Status),
  652    (   Status =:= 0                        % Established!
  653    ->  get_byte(StreamPair, _Reserved),
  654        get_byte(StreamPair, EchoedAddressType),
  655        (   EchoedAddressType =:= 0x1
  656        ->  get_byte(StreamPair, _),        % read IP4
  657            get_byte(StreamPair, _),
  658            get_byte(StreamPair, _),
  659            get_byte(StreamPair, _)
  660        ;   get_byte(StreamPair, Length),   % read host name
  661            forall(between(1, Length, _),
  662                   get_byte(StreamPair, _))
  663        ),
  664        get_byte(StreamPair, _),            % read port
  665        get_byte(StreamPair, _)
  666    ;   throw(error(socks_error(negotiation_rejected(Status)), _))
  667    ).
  668
  669
  670                 /*******************************
  671                 *             MESSAGES         *
  672                 *******************************/
  673
  674/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  675The C-layer generates exceptions of the  following format, where Message
  676is extracted from the operating system.
  677
  678        error(socket_error(Code, Message), _)
  679- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  680
  681:- multifile
  682    prolog:error_message//1.  683
  684prolog:error_message(socket_error(_Code, Message)) -->
  685    [ 'Socket error: ~w'-[Message] ].
  686prolog:error_message(socks_error(Error)) -->
  687    socks_error(Error).
  688prolog:error_message(proxy_error(tried(Tried))) -->
  689    [ 'Failed to connect using a proxy.  Tried:'-[], nl],
  690    proxy_tried(Tried).
  691
  692socks_error(invalid_version(Supported, Got)) -->
  693    [ 'SOCKS: unsupported version: ~p (supported: ~p)'-
  694      [ Got, Supported ] ].
  695socks_error(invalid_authentication_method(Supported, Got)) -->
  696    [ 'SOCKS: unsupported authentication method: ~p (supported: ~p)'-
  697      [ Got, Supported ] ].
  698socks_error(negotiation_rejected(Status)) -->
  699    [ 'SOCKS: connection failed: ~p'-[Status] ].
  700
  701proxy_tried([]) --> [].
  702proxy_tried([H|T]) -->
  703    proxy_tried(H),
  704    proxy_tried(T).
  705proxy_tried(error(Proxy, Error)) -->
  706    [ '~w: '-[Proxy] ],
  707    '$messages':translate_message(Error).
  708proxy_tried(false(Proxy)) -->
  709    [ '~w: failed with unspecified error'-[Proxy] ]