Function in io::net::tcp compiler

connect_timeout

fn connect_timeout(string host, int port, int ms) -> Result<Stream, IoError>
Import
use io::net::tcp::{connect_timeout};
Source: compiler/src/builtin_docs/io/net/tcp.hy

Opens a TCP connection to host on port, giving up after ms milliseconds.

Like connect, but name lookup and every address tried share one deadline of ms milliseconds; when it passes the result is Err(IoError::TimedOut). ms <= 0 waits forever. Needs --allow-net.

Parameters#

NameType
hoststring
portint
msint

Returns#

Result<Stream, IoError>

Examples#

use io::{IoError};
use io::net::tcp::{connect_timeout, listen, local_addr};
use tests::assert;
fn run() -> Result<unit, IoError> {
    let listener = listen("127.0.0.1", 0)?;
    let (_, port) = local_addr(listener)?;
    let _client = connect_timeout("127.0.0.1", port, 1000)?;
    return ();
}

fn main() {
    let ok = match run() {
        Result::Ok(_) => true,
        Result::Err(_) => false,
    };
    assert!(ok);
}

See also#

  • io::net::tcp::connect
  • accept: Accepts one pending connection on listener without waiting.
  • listen: Opens a TCP socket listening on host and port.
  • local_addr: Returns the local (host, port) of a TCP listener or connected TCP stream.
  • peer_addr: Returns the remote (host, port) of a connected TCP stream.
  • set_nodelay: Turns TCP_NODELAY on or off for a TCP stream.
  • shutdown: Shuts down the reading half, the writing half, or both halves of a TCP stream.
↑ ↓ navigate ↵ open