nvim_runtime_lua

uv.uv_tcp_t

uv_tcp_t - TCP handle

[uv_handle_t][] and [uv_stream_t][] functions also apply.

TCP handles are used to represent both TCP streams and servers.

Methods10

function uv_tcp_t.open(sock: integer) -> (success 0 | nil, err nil | string, err_name uv.error_name | nil)

Open an existing file descriptor or SOCKET as a TCP handle. Note: The passed file descriptor or SOCKET is not checked for its type, but it's required that it represents a valid stream socket.

function uv_tcp_t.nodelay(enable: boolean) -> (success 0 | nil, err nil | string, err_name uv.error_name | nil)

Enable / disable Nagle's algorithm.

function uv_tcp_t.keepalive(enable: boolean, delay: nil | integer, intvl: nil | integer, cnt: nil | integer) -> (success 0 | nil, err nil | string, err_name uv.error_name | nil)

Enable / disable TCP keep-alive. delay is the initial delay in seconds, intvl is the time in seconds between individual keep-alive probes, and cnt is the number of probes to send before assuming the connection is dead. ignored when enable is false. Note: intvl and cnt are only supported with Libuv >= 1.52.0.

function uv_tcp_t.simultaneous_accepts(enable: boolean) -> (success 0 | nil, err nil | string, err_name uv.error_name | nil)

Enable / disable simultaneous asynchronous accept requests that are queued by the operating system when listening for new TCP connections.

This setting is used to tune a TCP server for the desired performance. Having simultaneous accepts can significantly improve the rate of accepting connections (which is why it is enabled by default) but may lead to uneven load distribution in multi-process setups.

function uv_tcp_t.bind(host: string, port: integer, flags: { ipv6only: boolean } | nil) -> (success 0 | nil, err nil | string, err_name uv.error_name | nil)

Bind the handle to an host and port. host should be an IP address and not a domain name. Any flags are set with a table with field ipv6only equal to true or false.

When the port is already taken, you can expect to see an EADDRINUSE error from either uv.tcp_bind(), uv.listen() or uv.tcp_connect(). That is, a successful call to this function does not guarantee that the call to uv.listen() or uv.tcp_connect() will succeed as well.

Use a port of 0 to let the OS assign an ephemeral port. You can look it up later using uv.tcp_getsockname().

function uv_tcp_t.getpeername() -> (address uv.socketinfo | nil, err nil | string, err_name uv.error_name | nil)

Get the address of the peer connected to the handle.

See [Constants][] for supported address family output values.

function uv_tcp_t.getsockname() -> (address uv.socketinfo | nil, err nil | string, err_name uv.error_name | nil)

Get the current address to which the handle is bound.

See [Constants][] for supported address family output values.

function uv_tcp_t.connect(host: string, port: integer, callback: fun(err: nil | string) -> nil) -> (connect uv.uv_connect_t | nil, err nil | string, err_name uv.error_name | nil)

Establish an IPv4 or IPv6 TCP connection. Example

local client = uv.new_tcp()
client:connect("127.0.0.1", 8080, function (err)
  -- check error and carry on.
end)
function uv_tcp_t.write_queue_size()
Deprecated
Please use `uv.stream_get_write_queue_size()` instead.
function uv_tcp_t.close_reset(callback: fun() -> nil | nil) -> (success 0 | nil, err nil | string, err_name uv.error_name | nil)

Resets a TCP connection by sending a RST packet. This is accomplished by setting the SO_LINGER socket option with a linger interval of zero and then calling uv.close(). Due to some platform inconsistencies, mixing of uv.shutdown() and uv.tcp_close_reset() calls is not allowed.