with the specified
properties. The resulting handles can be passed to
|uv.tcp_open()|, used with |uv.spawn()|, or for any other
purpose.
See |luv-constants| for supported `socktype` input values.
When `protocol` is set to 0 or nil, it will be automatically
chosen based on the socket's domain and type. When `protocol`
is specified as a string, it will be looked up using the
`getprotobyname(3)` function (examples: `"ip"`, `"icmp"`,
`"tcp"`, `"udp"`, etc).
Flags:
- `nonblock`: Opens the specified socket handle for
`OVERLAPPED` or `FIONBIO`/`O_NONBLOCK` I/O usage. This is
recommended for handles that will be used by libuv, and not
usually recommended otherwise.
Equivalent to `socketpair(2)` with a domain of `AF_UNIX`.
Returns: `table` or `fail`
- `[1, 2]` : `integer` (file descriptor)
>lua
-- Simple read/write with tcp
local fds = uv.socketpair(nil, nil, {nonblock=true}, {nonblock=true})
local sock1 = uv.new_tcp()
sock1:open(fds[1])
local sock2 = uv.new_tcp()
sock2:open(fds[2])
sock1:write("hello")
sock2:read_start(function(err, chunk)
assert(not err, err)
print(chunk)
end)
<
==============================================================================
`uv_pipe_t` — Pipe handle *luv-pipe-handle* *uv_pipe_t*
> |uv_handle_t| and |uv_stream_t| functions also apply.
Pipe handles provide an abstraction over local domain sockets on Unix and
named pipes on Windows.
>lua
local pipe = uv.new_pipe(false)
pipe:bind('/tmp/sock.test')
pipe:listen(128, function()
local client = uv.new_pipe(false)
pipe:accept(client)
client:write("hello!\n")
client:close()
end)
<
uv.new_pipe([{ipc}]) *uv.new_pipe()*
Parameters:
- `ipc`: `boolean` or `nil` (default: `false`)
Creates and initializes a new |uv_pipe_t|. Returns the Lua
userdata wrapping it. The `ipc` argument is a boolean to
indicate if this pipe will be used for handle passing between
processes.
Returns: `uv_pipe_t userdata` or `fail`
uv.pipe_open({pipe}, {fd}) *uv.pipe_open()*
> method form `pipe:open(fd)`
Parameters:
- `pipe`: `uv_pipe_t userdata`
- `fd`: `integer`
Open an existing file descriptor or |uv_handle_t| as a
pipe.
Returns: `0` or `fail`
Note: The file descriptor is set to non-blocking mode.
uv.pipe_bind({pipe}, {name}) *uv.pipe_bind()*
> method form `pipe:bind(name)`
Parameters:
- `pipe`: `uv_pipe_t userdata`
- `name`: `string`
Bind the pipe to a file path (Unix) or a name (Windows).
Returns: `0` or `fail`
Note: Paths on Unix get truncated to
sizeof(sockaddr_un.sun_path) bytes, typically between 92 and
108 bytes.
uv.pipe_connect({pipe}, {name} [, {callback}]) *uv.pipe_connect()*
> method form `pipe:connect(name, [callback])`
Parameters:
- `pipe`: `uv_pipe_t userdata`
- `name`: `string`
- `callback`: `callable` or `nil`
- `err`: `nil` or `string`
Connect