Function in io::net::tcp compiler

set_nodelay

fn set_nodelay(Stream s, bool enabled) -> Result<unit, IoError>
Import
use io::net::tcp::{set_nodelay};
Source: compiler/src/builtin_docs/io/net/tcp.hy

Turns TCP_NODELAY on or off for a TCP stream.

With enabled == true small writes are sent at once instead of being held back to be combined (Nagle’s algorithm). Works on streams that a package such as coil-tls has attached to, since they share the socket. Returns Err(IoError::InvalidInput) for a listener or a stream that is not TCP.

Parameters#

NameType
sStream
enabledbool

Returns#

Result<unit, IoError>

Examples#

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

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

See also#

  • accept: Accepts one pending connection on listener without waiting.
  • connect: Opens a TCP connection to host on port.
  • connect_timeout: Opens a TCP connection to host on port, giving up after ms milliseconds.
  • 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.
  • shutdown: Shuts down the reading half, the writing half, or both halves of a TCP stream.
↑ ↓ navigate ↵ open