Home Explore Blog CI



neovim

34th chunk of `runtime/doc/luvref.txt`
7317c293ce2c3f94c32856ddb0c6f3511a6eaaada31e83b30000000100000fa0

                port number.

                Returns: `uv_udp_send_t userdata` or `fail`

uv.udp_try_send({udp}, {data}, {host}, {port})               *uv.udp_try_send()*

                > method form `udp:try_send(data, host, port)`

                Parameters:
                - `udp`: `uv_udp_t userdata`
                - `data`: `buffer`
                - `host`: `string`
                - `port`: `integer`

                Same as |uv.udp_send()|, but won't queue a send request if it
                can't be completed immediately.

                Returns: `integer` or `fail`

uv.udp_try_send2({udp}, {messages}, {flags})                *uv.udp_try_send2()*

                > method form `udp:try_send2(messages, flags)`

                Parameters:
                - `udp`: `uv_udp_t userdata`
                - `messages`: `table`
                  - `[1, 2, 3, ..., n]` : `table`
                    - `data` : `buffer`
                    - `addr` : `table`
                      - `ip` : `string`
                      - `port` : `integer`
                - `flags`: `nil` (see below)
                - `port`: `integer`

                Like `uv.udp_try_send()`, but can send multiple datagrams.
                Lightweight abstraction around `sendmmsg(2)`, with a
                `sendmsg(2)` fallback loop for platforms that do not support
                the former. The `udp` handle must be fully initialized, either
                from a `uv.udp_bind` call, another call that will bind
                automatically (`udp_send`, `udp_try_send`, etc), or from
                `uv.udp_connect`. `messages` should be an array-like table,
                where `addr` must be specified if the `udp` has not been
                connected via `udp_connect`. Otherwise, `addr` must be `nil`.

                `flags` is reserved for future extension and must currently be
                `nil` or `0` or `{}`.

                Returns the number of messages sent successfully. An error will only be returned
                if the first datagram failed to be sent.

                Returns: `integer` or `fail`
                >lua
                  -- If client:connect(...) was not called
                  local addr = { ip = "127.0.0.1", port = 1234 }
                  client:try_send2({
                    { data = "Message 1", addr = addr },
                    { data = "Message 2", addr = addr },
                  })
                  -- If client:connect(...) was called
                  client:try_send2({
                    { data = "Message 1" },
                    { data = "Message 2" },
                  })
<
uv.udp_recv_start({udp}, {callback})                       *uv.udp_recv_start()*

                > method form `udp:recv_start(callback)`

                Parameters:
                - `udp`: `uv_udp_t userdata`
                - `callback`: `callable`
                  - `err`: `nil` or `string`
                  - `data`: `string` or `nil`
                  - `addr`: `table` or `nil`
                    - `ip`: `string`
                    - `port`: `integer`
                    - `family`: `string`
                  - `flags`: `table`
                    - `partial`: `boolean` or `nil`
                    - `mmsg_chunk`: `boolean` or `nil`

                Prepare for receiving data. If the socket has not previously
                been bound with |uv.udp_bind()| it is bound to `0.0.0.0` (the
                "all interfaces" IPv4 address) and a random port number.

                See |luv-constants| for supported address `family` output values.

                Returns: `0` or `fail`

uv.udp_recv_stop({udp})                                     *uv.udp_recv_stop()*

                > method form `udp:recv_stop()`

                Parameters:
                - `udp`: `uv_udp_t userdata`

                Stop listening for incoming datagrams.

                Returns: `0` or `fail`

uv.udp_connect({udp}, {host}, {port})     

Title: Libuv UDP Functions: Sending Multiple Datagrams and Receiving Data
Summary
This section details functions for sending multiple UDP datagrams at once using `uv.udp_try_send2()`, which abstracts the `sendmmsg(2)` system call. It also describes how to start and stop receiving UDP data with `uv.udp_recv_start()` and `uv.udp_recv_stop()`, respectively, including details on the callback function and returned data.