nvim_runtime_lua

uv.uv_poll_t

uv_poll_t - Poll handle

[uv_handle_t][] functions also apply.

Poll handles are used to watch file descriptors for readability and writability, similar to the purpose of poll(2).

The purpose of poll handles is to enable integrating external libraries that rely on the event loop to signal it about the socket status changes, like c-ares or libssh2. Using uv_poll_t for any other purpose is not recommended; uv_tcp_t, uv_udp_t, etc. provide an implementation that is faster and more scalable than what can be achieved with uv_poll_t, especially on Windows.

It is possible that poll handles occasionally signal that a file descriptor is readable or writable even when it isn't. The user should therefore always be prepared to handle EAGAIN or equivalent when it attempts to read from or write to the fd.

It is not okay to have multiple active poll handles for the same socket, this can cause libuv to busyloop or otherwise malfunction.

The user should not close a file descriptor while it is being polled by an active poll handle. This can cause the handle to report an error, but it might also start polling another socket. However the fd can be safely closed immediately after a call to uv.poll_stop() or uv.close().

Note: On windows only sockets can be polled with poll handles. On Unix any file descriptor that would be accepted by poll(2) can be used.

Methods2

function uv_poll_t.start(events: nil | string, callback: fun(err: nil | string, events: nil | string) -> nil) -> (success 0 | nil, err nil | string, err_name uv.error_name | nil)

Starts polling the file descriptor. events are: "r", "w", "rw", "d", "rd", "wd", "rwd", "p", "rp", "wp", "rwp", "dp", "rdp", "wdp", or "rwdp" where r is READABLE, w is WRITABLE, d is DISCONNECT, and p is PRIORITIZED. As soon as an event is detected the callback will be called with status set to 0, and the detected events set on the events field.

The user should not close the socket while the handle is active. If the user does that anyway, the callback may be called reporting an error status, but this is not guaranteed. Note: Calling uv.poll_start() on a handle that is already active is fine. Doing so will update the events mask that is being watched for.

function uv_poll_t.stop() -> (success 0 | nil, err nil | string, err_name uv.error_name | nil)

Stop polling the file descriptor, the callback will no longer be called.