Home Explore Blog CI



neovim

21th chunk of `runtime/doc/luvref.txt`
fb1e1532f4b1b4ca4737b158db5f08b0150c48c17b0c49e30000000100000fa0
                          *uv.accept()*

                > method form `stream:accept(client_stream)`

                Parameters:
                - `stream`: `userdata` for sub-type of |uv_stream_t|
                - `client_stream`: `userdata` for sub-type of |uv_stream_t|

                This call is used in conjunction with |uv.listen()| to accept
                incoming connections. Call this function after receiving a
                callback to accept the connection.

                When the connection callback is called it is guaranteed that
                this function will complete successfully the first time. If
                you attempt to use it more than once, it may fail. It is
                suggested to only call this function once per connection call.

                Returns: `0` or `fail`

                    >lua
                    server:listen(128, function (err)
                      local client = uv.new_tcp()
                      server:accept(client)
                    end)
<

uv.read_start({stream}, {callback})                            *uv.read_start()*

                > method form `stream:read_start(callback)`

                Parameters:
                - `stream`: `userdata` for sub-type of |uv_stream_t|
                - `callback`: `callable`
                  - `err`: `nil` or `string`
                  - `data`: `string` or `nil`

                Read data from an incoming stream. The callback will be made
                several times until there is no more data to read or
                |uv.read_stop()| is called. When we've reached EOF, `data`
                will be `nil`.

                Returns: `0` or `fail`

                    >lua
                    stream:read_start(function (err, chunk)
                      if err then
                        -- handle read error
                      elseif chunk then
                        -- handle data
                      else
                        -- handle disconnect
                      end
                    end)
<

uv.read_stop({stream})                                          *uv.read_stop()*

                > method form `stream:read_stop()`

                Parameters:
                - `stream`: `userdata` for sub-type of |uv_stream_t|

                Stop reading data from the stream. The read callback will no
                longer be called.

                This function is idempotent and may be safely called on a
                stopped stream.

                Returns: `0` or `fail`

uv.write({stream}, {data} [, {callback}])                           *uv.write()*

                > method form `stream:write(data, [callback])`

                Parameters:
                - `stream`: `userdata` for sub-type of |uv_stream_t|
                - `data`: `buffer`
                - `callback`: `callable` or `nil`
                  - `err`: `nil` or `string`

                Write data to stream.

                `data` can either be a Lua string or a table of strings. If a
                table is passed in, the C backend will use writev to send all
                strings in a single system call.

                The optional `callback` is for knowing when the write is
                complete.

                Returns: `uv_write_t userdata` or `fail`

uv.write2({stream}, {data}, {send_handle} [, {callback}])          *uv.write2()*

                > method form `stream:write2(data, send_handle, [callback])`

                Parameters:
                - `stream`: `userdata` for sub-type of |uv_stream_t|
                - `data`: `buffer`
                - `send_handle`: `userdata` for sub-type of |uv_stream_t|
                - `callback`: `callable` or `nil`
                  - `err`: `nil` or `string`

                Extended write function for sending handles over a pipe. The
                pipe must be initialized with `ipc` option `true`.

                Returns: `uv_write_t userdata` or `fail`

   

Title: Libuv Stream Read and Write Functions
Summary
This section details libuv stream functions for reading and writing data. It covers `uv.accept()`, used to accept incoming connections after calling `uv.listen()`. It also describes `uv.read_start()`, which starts reading data from an incoming stream using a callback, and `uv.read_stop()`, which halts the data reading. Furthermore, it explains `uv.write()`, allowing writing data to a stream, and `uv.write2()`, which extends the write function to send handles over a pipe initialized with the 'ipc' option set to true.