Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update libuv to 1.41.0 #534

Merged
merged 7 commits into from
Apr 18, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .ci/bindcov.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ for fn in `grep -oP "UV_EXTERN [^\(]+ uv_[^\(]+\(" deps/libuv/include/uv.h | sed
continue
fi
# count all uses
count=`grep -o "$fn" src/*.c | wc -l`
count=`grep -o "\b$fn\b" src/*.c | wc -l`
# check if a luv_ version exists
grep -Fq "l$fn" src/*.c
grep -q "\bl$fn\b" src/*.c
bound=$?
# not bound
if [ ! $bound -eq 0 ] ; then
Expand Down
2 changes: 1 addition & 1 deletion deps/libuv
Submodule libuv updated 68 files
+17 −0 .github/workflows/sanitizer.yml
+2 −0 .mailmap
+12 −1 AUTHORS
+12 −2 CMakeLists.txt
+80 −1 ChangeLog
+2 −5 Makefile.am
+10 −0 README.md
+2 −2 SUPPORTED_PLATFORMS.md
+2 −1 configure.ac
+18 −0 docs/src/pipe.rst
+44 −17 docs/src/poll.rst
+7 −5 docs/src/process.rst
+5 −0 docs/src/stream.rst
+20 −4 docs/src/tcp.rst
+7 −5 docs/src/udp.rst
+12 −3 include/uv.h
+1 −1 include/uv/version.h
+1 −0 src/timer.c
+1 −1 src/unix/async.c
+3 −3 src/unix/bsd-ifaddrs.c
+2 −3 src/unix/core.c
+31 −13 src/unix/fs.c
+0 −6 src/unix/internal.h
+33 −28 src/unix/linux-core.c
+17 −20 src/unix/linux-syscalls.c
+2 −2 src/unix/linux-syscalls.h
+54 −0 src/unix/pipe.c
+9 −0 src/unix/poll.c
+1 −63 src/unix/process.c
+1 −0 src/unix/proctitle.c
+1 −1 src/unix/signal.c
+3 −9 src/unix/stream.c
+51 −2 src/unix/tcp.c
+19 −0 src/uv-common.c
+4 −0 src/uv-common.h
+24 −25 src/win/fs.c
+2 −2 src/win/internal.h
+213 −15 src/win/pipe.c
+0 −96 src/win/process-stdio.c
+3 −10 src/win/stream.c
+137 −6 src/win/tcp.c
+2 −0 test/benchmark-pump.c
+1 −0 test/blackhole-server.c
+3 −2 test/echo-server.c
+27 −9 test/run-tests.c
+22 −18 test/task.h
+17 −13 test/test-close-fd.c
+3 −0 test/test-error.c
+3 −0 test/test-fs-copyfile.c
+3 −0 test/test-fs-event.c
+3 −0 test/test-fs-readdir.c
+108 −42 test/test-fs.c
+2 −2 test/test-getaddrinfo.c
+6 −1 test/test-ipc.c
+21 −9 test/test-list.h
+178 −43 test/test-ping-pong.c
+3 −0 test/test-pipe-connect-error.c
+6 −2 test/test-pipe-getsockname.c
+39 −14 test/test-pipe-set-non-blocking.c
+1 −0 test/test-platform-output.c
+99 −0 test/test-poll-multiple-handles.c
+7 −1 test/test-shutdown-eof.c
+64 −60 test/test-spawn.c
+47 −2 test/test-tcp-bind-error.c
+1 −1 test/test-tcp-connect-timeout.c
+3 −0 test/test-tty.c
+1 −1 test/test-udp-connect.c
+3 −5 tools/make_dist_html.py
36 changes: 36 additions & 0 deletions docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,42 @@ where `r` is `READABLE` and `w` is `WRITABLE`. This function is blocking.

**Returns:** `0` or `fail`

### `uv.pipe(read_flags, write_flags)`

**Parameters:**
- `read_flags`: `table` or `nil`
- `nonblock`: `boolean` (default: `false`)
- `write_flags`: `table` or `nil`
- `nonblock`: `boolean` (default: `false`)

Create a pair of connected pipe handles. Data may be written to the `write` fd and read from the `read` fd. The resulting handles can be passed to `pipe_open`, used with `spawn`, or for any other purpose.

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 `pipe(2)` with the `O_CLOEXEC` flag set.

**Returns:** `table` or `fail`
- `read` : `integer` (file descriptor)
- `write` : `integer` (file descriptor)

```lua
-- Simple read/write with pipe_open
local fds = uv.pipe({nonblock=true}, {nonblock=true})

local read_pipe = uv.new_pipe()
read_pipe:open(fds.read)

local write_pipe = uv.new_pipe()
write_pipe:open(fds.write)

write_pipe:write("hello")
read_pipe:read_start(function(err, chunk)
assert(not err, err)
print(chunk)
end)
```

## `uv_tty_t` — TTY handle

[`uv_tty_t`]: #uv_tty_t--tty-handle
Expand Down
3 changes: 3 additions & 0 deletions src/luv.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ static const luaL_Reg luv_functions[] = {
{"pipe_pending_instances", luv_pipe_pending_instances},
{"pipe_pending_count", luv_pipe_pending_count},
{"pipe_pending_type", luv_pipe_pending_type},
#if LUV_UV_VERSION_GEQ(1, 41, 0)
{"pipe", luv_pipe},
#endif

// tty.c
{"new_tty", luv_new_tty},
Expand Down
32 changes: 32 additions & 0 deletions src/pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,35 @@ static int luv_pipe_chmod(lua_State* L) {
return luv_result(L, ret);
}
#endif

#if LUV_UV_VERSION_GEQ(1,41,0)
static int luv_pipe(lua_State* L) {
luv_ctx_t* ctx = luv_context(L);
int read_flags = 0, write_flags = 0;
uv_file fds[2];
int ret;
if (lua_type(L, 3) == LUA_TTABLE) {
lua_getfield(L, 3, "nonblock");
if (lua_toboolean(L, -1)) read_flags |= UV_NONBLOCK_PIPE;
lua_pop(L, 1);
} else if (!lua_isnoneornil(L, 3)) {
luv_arg_type_error(L, 3, "table or nil expected, got %s");
}
if (lua_type(L, 4) == LUA_TTABLE) {
lua_getfield(L, 4, "nonblock");
if (lua_toboolean(L, -1)) write_flags |= UV_NONBLOCK_PIPE;
lua_pop(L, 1);
} else if (!lua_isnoneornil(L, 4)) {
luv_arg_type_error(L, 4, "table or nil expected, got %s");
}
ret = uv_pipe(fds, read_flags, write_flags);
if (ret < 0) return luv_error(L, ret);
// return as a table with 'read' and 'write' keys containing the corresponding fds
lua_createtable(L, 0, 2);
lua_pushinteger(L, fds[0]);
lua_setfield(L, -2, "read");
lua_pushinteger(L, fds[1]);
lua_setfield(L, -2, "write");
return 1;
}
#endif
75 changes: 75 additions & 0 deletions tests/test-pipe.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,79 @@ return require('lib/tap')(function (test)

pipe:close()
end, "1.16.0")

test("pipe ping pong", function(print, p, expect, uv)
local PING = "PING\n"
local NUM_PINGS = 4

local fds = assert(uv.pipe({nonblock=true}, {nonblock=true}))
assert(uv.guess_handle(fds.read) == "pipe")
assert(uv.guess_handle(fds.write) == "pipe")

local ponger = assert(uv.new_pipe())
assert(ponger:open(fds.read))

local pinger = assert(uv.new_pipe())
assert(pinger:open(fds.write))

local ping = function()
assert(pinger:write(PING, expect(function(err)
assert(not err, err)
end)))
end

local pongs = 0
ping()

assert(ponger:read_start(function(err, chunk)
assert(not err, err)
if chunk == nil then
return
end
assert(chunk == PING)
pongs = pongs + 1
if pongs == NUM_PINGS then
ponger:close()
pinger:close()
else
ping()
end
end))
end, "1.41.0")

test("pipe close fd", function(print, p, expect, uv)
local fds = assert(uv.pipe())

local pipe_handle = assert(uv.new_pipe())
assert(pipe_handle:open(fds.read))
-- pipe_open takes ownership of the file descriptor
fds.read = nil

assert(uv.fs_write(fds.write, "PING"))
assert(uv.fs_close(fds.write))
fds.write = nil

local read_cb_called = 0
local read_cb = expect(function(err, chunk)
assert(not err, err)
read_cb_called = read_cb_called + 1
if read_cb_called == 1 then
assert(chunk == "PING")
pipe_handle:read_stop()
elseif read_cb_called == 2 then
assert(chunk == nil)
pipe_handle:close()
end
end, 2)

assert(pipe_handle:read_start(read_cb))
uv.run()
assert(read_cb_called == 1)

assert(pipe_handle:read_start(read_cb))
uv.run()
assert(read_cb_called == 2)

assert(pipe_handle:is_closing())
end, "1.41.0")
end)