(index ("tcp-listen" 0) ("tcp-listener?" 1384) ("tcp-close" 1545) ("tcp-accept" 1673) ("tcp-accept-ready?" 2527) ("tcp-listener-port" 2722) ("tcp-listener-socket" 2967) ("tcp-listener-fileno" 3199) ("tcp-connect" 3352) ("tcp-connect/ai" 5240) ("tcp-addresses" 6469) ("tcp-port-numbers" 6867) ("tcp-abandon-port" 7228) ("tcp-port->socket" 7569) ("tcp-buffer-size" 7871) ("tcp-read-timeout" 8999) ("tcp-write-timeout" 9342) ("tcp-connect-timeout" 9689) ("tcp-accept-timeout" 10031) ("tcp-bind-ipv6-only" 10376))
(def (sig (procedure "(tcp-listen TCPPORT [BACKLOG [HOST]])" (id tcp-listen))) (p "Creates and returns a TCP listener object that listens for connections on " (tt "TCPPORT") ", which should be an exact integer. " (tt "BACKLOG") " specifies the number of maximally pending connections (and defaults to 10).") (p "If the optional argument " (tt "HOST") " is given and not " (tt "#f") ", then only incoming connections for the given host (or IP) are accepted.") (p "When " (tt "HOST") " is " (tt "#f") " (the default), the behavior is system-dependent.  It " (i "should") " listen on all IPv4 and IPv6 addresses if possible, or just on IPv4 if IPv6 is disabled.  This is true on OS X and Windows.  Unfortunately, certain systems may always prefer to listen on IPv4 only (particularly those using recent glibc, like Ubuntu).") (p "Special note when " (tt "HOST") " is " (tt "#f") ".  If you have set " (tt "(tcp-bind-ipv6-only #t)") ", or if " (tt "tcp-bind-ipv6-only") " is not supported by your OS, we " (i "always") " listen on " (tt "\"0.0.0.0\"") " to IPv4 only.  This is done because users will expect " (tt "(tcp-listen port)") " to listen at least on IPv4.  To listen to IPv6 only in this case, explicitly specify a " (tt "HOST") " of " (tt "\"::\"") ".") (p "Long story short, setting " (tt "HOST") " to " (tt "#f") " will more likely than not give you an IPv4-only listener."))
(def (sig (procedure "(tcp-listener? X)" (id tcp-listener?))) (p "Returns " (tt "#t") " if " (tt "X") " is a TCP listener object, or " (tt "#f") " otherwise."))
(def (sig (procedure "(tcp-close LISTENER)" (id tcp-close))) (p "Reclaims any resources associated with " (tt "LISTENER") "."))
(def (sig (procedure "(tcp-accept LISTENER)" (id tcp-accept))) (p "Waits until a connection is established on the port on which " (tt "LISTENER") " is listening and returns two values: an input- and output-port that can be used to communicate with the remote process. The current value of " (tt "tcp-accept-timeout") " is used to determine the maximal number of milliseconds (if any) to wait until a connection is established. When a client connects any read- and write-operations on the returned ports will use the current values (at the time of the connection) of " (tt "tcp-read-timeout") " and " (tt "tcp-write-timeout") ", respectively, to determine the maximal number of milliseconds to wait for input/output before a timeout error is signalled.") (p "Note: this operation and any I/O on the ports returned will not block other running threads."))
(def (sig (procedure "(tcp-accept-ready? LISTENER)" (id tcp-accept-ready?))) (p "Returns " (tt "#t") " if there are any connections pending on " (tt "LISTENER") ", or " (tt "#f") " otherwise."))
(def (sig (procedure "(tcp-listener-port LISTENER)" (id tcp-listener-port))) (p "Returns the port number assigned to " (tt "LISTENER") ". (If you pass " (tt "0") " to " (tt "tcp-listen") ", then the system will choose a port-number for you.)"))
(def (sig (procedure "(tcp-listener-socket LISTENER)" (id tcp-listener-socket))) (p "Returns the socket object associated with " (tt "LISTENER") ".  This procedure is an addition over " (int-link "/man/4/Unit tcp" "Unit tcp") "."))
(def (sig (procedure "(tcp-listener-fileno LISTENER)" (id tcp-listener-fileno))) (p "Returns the file-descriptor associated with " (tt "LISTENER") "."))
(def (sig (procedure "(tcp-connect HOSTNAME [TCPPORT])" (id tcp-connect))) (p "Establishes a client-side TCP connection to the machine with the node name or IP address " (tt "HOSTNAME") " (a string) at " (tt "TCPPORT") " (an exact integer or a service name) and returns two values: an input- and output-port for communicating with the remote process.") (p "If the " (tt "TCPPORT") " is omitted, the port is parsed from the " (tt "HOSTNAME") " string.  The format expected is " (tt "\"HOST:PORT\"") ", or " (tt "\"[HOST]:PORT\"") " if " (tt "HOST") " is an IPv6 string.  The " (tt "PORT") " can either be a string representation of an integer or a service name which is translated to an integer using " (tt "address-information") " from " (int-link "/egg/socket" "socket") ".") (p "Address resolution is performed using " (tt "address-information") ", which may return multiple addresses for a given hostname, including both IPv6 and IPv4 addresses.  " (tt "tcp-connect") " will try each of these in turn until one succeeds.  See " (tt "tcp-connect/ai") " for more information. For example, connecting to " (tt "\"localhost:ssh\"") " may connect to " (tt "\"[::1]:22\"") ", " (tt "\"[fe80::1%lo0]:22\"") ", and " (tt "\"127.0.0.1:22\"") " in turn, until an ssh listener is contacted.") (p "The current value of " (tt "tcp-connect-timeout") " is used to determine the maximum number of milliseconds (if any) to wait until the connection is established. When the connection takes place any read- and write-operations on the returned ports will use the current values (at the time of the call to " (tt "tcp-connect") ") of " (tt "tcp-read-timeout") " and " (tt "tcp-write-timeout") ", respectively, to determine the maximum number of milliseconds to wait for input/output before a timeout error is signalled.") (p "Note: any I/O on the ports returned will not block other running threads."))
(def (sig (procedure "(tcp-connect/ai ais)" (id tcp-connect/ai))) (p "Takes a list of " (tt "addrinfo") " objects, obtained from " (tt "address-information") " in the " (int-link "/egg/socket" "socket egg") ", and connects to each in turn until one succeeds.  If a timeout occurs during connection, or a transient error (connection refused, host unreachable) occurs, the next address in the list will be tried.  If all addresses fail, the last error encountered is propagated to the caller.  If a fatal socket error occurs then we terminate immediately.") (p (tt "(tcp-connect host port)") " is equivalent to") (pre "(tcp-connect/ai (address-information host port))") (p "which may include IPv6 and IPv4 addresses.  To connect instead to " (tt "localhost:22") " over IPv4 only:") (pre "(tcp-connect/ai (address-information \"localhost\" 22 family: af/inet))") (p "and to try to connect to the first HTTP mirror that accepts your connection:") (pre "(tcp-connect/ai\n (append (address-information \"athena.example.com\" 80)\n         (address-information \"achilles.example.com\" 80)\n         (address-information \"aphrodite.example.com\" 80)))") (p "Keeping the connect timeout low is probably a good idea in the last case."))
(def (sig (procedure "(tcp-addresses PORT)" (id tcp-addresses))) (p "Returns two values for the input- or output-port " (tt "PORT") " (which should be a port returned by either " (tt "tcp-accept") " or " (tt "tcp-connect") "): the IP address of the local and the remote machine that are connected over the socket associated with " (tt "PORT") ". The returned addresses are IPv4 or IPv6 strings."))
(def (sig (procedure "(tcp-port-numbers PORT)" (id tcp-port-numbers))) (p "Returns two values for the input- or output-port " (tt "PORT") " (which should be a port returned by either " (tt "tcp-accept") " or " (tt "tcp-connect") "): the TCP port numbers of the local and the remote machine that are connected over the socket associated with " (tt "PORT") "."))
(def (sig (procedure "(tcp-abandon-port PORT)" (id tcp-abandon-port))) (p "Marks the socket port " (tt "PORT") " as abandoned.  This is mainly useful to close down an input or output port without shutting down that side of the connection.  See " (tt "socket-abandon-port") " in " (int-link "/egg/socket" "socket") " for more information."))
(def (sig (procedure "(tcp-port->socket PORT)" (id tcp-port->socket))) (p "Return the socket object associated with TCP input or output port " (tt "PORT") ".") (p "It is also possible to use " (tt "port->fileno") " from " (int-link "/man/4/posix" "Unit posix") " with TCP ports created by this egg."))
(def (sig (parameter "tcp-buffer-size" (id tcp-buffer-size))) (p "Sets the size of the output buffer. By default no output-buffering for TCP output is done, but to improve performance by minimizing the number of TCP packets, buffering may be turned on by setting this parameter to an exact integer greater than zero.  For best performance, it should be a power of 2 such as 128, 1024 or 4096.  A buffer size of " (tt "#f") " turns buffering off.  The setting of this parameter takes effect at the time when the I/O ports for a particular socket are created, i.e. when " (tt "tcp-connect") " or " (tt "tcp-accept") " is called.") (p "See " (tt "socket-receive-buffer-size") " and " (tt "socket-send-size") " in the " (int-link "/egg/socket" "socket egg") " for additional send and receive tuning that can be done with TCP ports.  This parameter is itself equivalent to " (tt "socket-send-buffer-size") ".") (p "Note that since output is not immediately written to the associated socket, you may need to call " (tt "flush-output") " once you want the output to be transmitted. Closing the output port will flush automatically."))
(def (sig (parameter "tcp-read-timeout" (id tcp-read-timeout))) (p "Determines the timeout for TCP read operations in milliseconds. A timeout of " (tt "#f") " disables timeout checking. The default read timeout is 60000, i.e. 1 minute. If timeout occurs while reading, a condition object of kind " (tt "(exn i/o net timeout)") " is thrown."))
(def (sig (parameter "tcp-write-timeout" (id tcp-write-timeout))) (p "Determines the timeout for TCP write operations in milliseconds. A timeout of " (tt "#f") " disables timeout checking. The default write timeout is 60000, i.e. 1 minute. If timeout occurs while writing, a condition object of kind " (tt "(exn i/o net timeout)") " is thrown."))
(def (sig (parameter "tcp-connect-timeout" (id tcp-connect-timeout))) (p "Determines the timeout for " (tt "tcp-connect") " operations in milliseconds. A timeout of " (tt "#f") " disables timeout checking and is the default. If timeout occurs while trying to connect, a condition object of kind " (tt "(exn i/o net timeout)") " is thrown."))
(def (sig (parameter "tcp-accept-timeout" (id tcp-accept-timeout))) (p "Determines the timeout for " (tt "tcp-accept") " operations in milliseconds. A timeout of " (tt "#f") " disables timeout checking and is the default. If timeout occurs while waiting for connections, a condition object of kind " (tt "(exn i/o net timeout)") " is thrown."))
(def (sig (parameter "tcp-bind-ipv6-only" (id tcp-bind-ipv6-only))) (p "When " (tt "#f") ", the default, IPv6 listening sockets will accept IPv6 or IPv4 connections when possible.  This is only relevant when listening on the unspecified address \"::\".  When " (tt "#t") ", IPv6 listeners will not accept IPv4 connections.") (p "This option is ignored when unsupported, such as on Windows 2000 and XP, whose IPv4 and IPv6 stacks are separate."))
