forked from cory/tildefriends
apps
core
deps
base64c
codemirror
crypt_blowfish
libsodium
libuv
.github
docs
img
include
m4
src
test
fixtures
benchmark-async-pummel.c
benchmark-async.c
benchmark-fs-stat.c
benchmark-getaddrinfo.c
benchmark-list.h
benchmark-loop-count.c
benchmark-million-async.c
benchmark-million-timers.c
benchmark-multi-accept.c
benchmark-ping-pongs.c
benchmark-ping-udp.c
benchmark-pound.c
benchmark-pump.c
benchmark-queue-work.c
benchmark-sizes.c
benchmark-spawn.c
benchmark-tcp-write-batch.c
benchmark-thread.c
benchmark-udp-pummel.c
blackhole-server.c
echo-server.c
run-benchmarks.c
run-tests.c
runner-unix.c
runner-unix.h
runner-win.c
runner-win.h
runner.c
runner.h
task.h
test-active.c
test-async-null-cb.c
test-async.c
test-barrier.c
test-callback-order.c
test-callback-stack.c
test-close-fd.c
test-close-order.c
test-condvar.c
test-connect-unspecified.c
test-connection-fail.c
test-cwd-and-chdir.c
test-default-loop-close.c
test-delayed-accept.c
test-dlerror.c
test-eintr-handling.c
test-embed.c
test-emfile.c
test-env-vars.c
test-error.c
test-fail-always.c
test-fork.c
test-fs-copyfile.c
test-fs-event.c
test-fs-fd-hash.c
test-fs-open-flags.c
test-fs-poll.c
test-fs-readdir.c
test-fs.c
test-get-currentexe.c
test-get-loadavg.c
test-get-memory.c
test-get-passwd.c
test-getaddrinfo.c
test-gethostname.c
test-getnameinfo.c
test-getsockname.c
test-getters-setters.c
test-gettimeofday.c
test-handle-fileno.c
test-homedir.c
test-hrtime.c
test-idle.c
test-idna.c
test-ip-name.c
test-ip4-addr.c
test-ip6-addr.c
test-ipc-heavy-traffic-deadlock-bug.c
test-ipc-send-recv.c
test-ipc.c
test-list.h
test-loop-alive.c
test-loop-close.c
test-loop-configure.c
test-loop-handles.c
test-loop-stop.c
test-loop-time.c
test-metrics.c
test-multiple-listen.c
test-mutexes.c
test-not-readable-nor-writable-on-read-error.c
test-not-writable-after-shutdown.c
test-osx-select.c
test-pass-always.c
test-ping-pong.c
test-pipe-bind-error.c
test-pipe-close-stdout-read-stdin.c
test-pipe-connect-error.c
test-pipe-connect-multiple.c
test-pipe-connect-prepare.c
test-pipe-getsockname.c
test-pipe-pending-instances.c
test-pipe-sendmsg.c
test-pipe-server-close.c
test-pipe-set-fchmod.c
test-pipe-set-non-blocking.c
test-platform-output.c
test-poll-close-doesnt-corrupt-stack.c
test-poll-close.c
test-poll-closesocket.c
test-poll-multiple-handles.c
test-poll-oob.c
test-poll.c
test-process-priority.c
test-process-title-threadsafe.c
test-process-title.c
test-queue-foreach-delete.c
test-random.c
test-readable-on-eof.c
test-ref.c
test-run-nowait.c
test-run-once.c
test-semaphore.c
test-shutdown-close.c
test-shutdown-eof.c
test-shutdown-simultaneous.c
test-shutdown-twice.c
test-signal-multiple-loops.c
test-signal-pending-on-close.c
test-signal.c
test-socket-buffer-size.c
test-spawn.c
test-stdio-over-pipes.c
test-strscpy.c
test-tcp-alloc-cb-fail.c
test-tcp-bind-error.c
test-tcp-bind6-error.c
test-tcp-close-accept.c
test-tcp-close-reset.c
test-tcp-close-while-connecting.c
test-tcp-close.c
test-tcp-connect-error-after-write.c
test-tcp-connect-error.c
test-tcp-connect-timeout.c
test-tcp-connect6-error.c
test-tcp-create-socket-early.c
test-tcp-flags.c
test-tcp-oob.c
test-tcp-open.c
test-tcp-read-stop-start.c
test-tcp-read-stop.c
test-tcp-shutdown-after-write.c
test-tcp-try-write-error.c
test-tcp-try-write.c
test-tcp-unexpected-read.c
test-tcp-write-after-connect.c
test-tcp-write-fail.c
test-tcp-write-queue-order.c
test-tcp-write-to-half-open-connection.c
test-tcp-writealot.c
test-test-macros.c
test-thread-equal.c
test-thread.c
test-threadpool-cancel.c
test-threadpool.c
test-timer-again.c
test-timer-from-check.c
test-timer.c
test-tmpdir.c
test-tty-duplicate-key.c
test-tty-escape-sequence-processing.c
test-tty.c
test-udp-alloc-cb-fail.c
test-udp-bind.c
test-udp-connect.c
test-udp-connect6.c
test-udp-create-socket-early.c
test-udp-dgram-too-big.c
test-udp-ipv6.c
test-udp-mmsg.c
test-udp-multicast-interface.c
test-udp-multicast-interface6.c
test-udp-multicast-join.c
test-udp-multicast-join6.c
test-udp-multicast-ttl.c
test-udp-open.c
test-udp-options.c
test-udp-send-and-recv.c
test-udp-send-hang-loop.c
test-udp-send-immediate.c
test-udp-send-unreachable.c
test-udp-sendmmsg-error.c
test-udp-try-send.c
test-uname.c
test-walk-handles.c
test-watcher-cross-stop.c
tools
.gitattributes
.gitignore
.mailmap
.readthedocs.yaml
AUTHORS
CMakeLists.txt
CONTRIBUTING.md
ChangeLog
LICENSE
LICENSE-docs
LINKS.md
MAINTAINERS.md
Makefile.am
README.md
SUPPORTED_PLATFORMS.md
autogen.sh
configure.ac
libuv-static.pc.in
libuv.pc.in
uv_win_longpath.manifest
perfetto
quickjs
smoothie
split
sqlite
xopt
docs
src
tools
.dockerignore
Dockerfile
LICENSE
Makefile
README.md
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3621 ed5197a5-7fde-0310-b194-c3ffbd925b24
126 lines
3.8 KiB
C
126 lines
3.8 KiB
C
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to
|
|
* deal in the Software without restriction, including without limitation the
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
* sell copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
* IN THE SOFTWARE.
|
|
*/
|
|
|
|
#include "uv.h"
|
|
#include "task.h"
|
|
|
|
|
|
static int get_tty_fd(void) {
|
|
/* Make sure we have an FD that refers to a tty */
|
|
#ifdef _WIN32
|
|
HANDLE handle;
|
|
handle = CreateFileA("conin$",
|
|
GENERIC_READ | GENERIC_WRITE,
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
NULL,
|
|
OPEN_EXISTING,
|
|
FILE_ATTRIBUTE_NORMAL,
|
|
NULL);
|
|
if (handle == INVALID_HANDLE_VALUE)
|
|
return -1;
|
|
return _open_osfhandle((intptr_t) handle, 0);
|
|
#else /* unix */
|
|
return open("/dev/tty", O_RDONLY, 0);
|
|
#endif
|
|
}
|
|
|
|
|
|
TEST_IMPL(handle_fileno) {
|
|
int r;
|
|
int tty_fd;
|
|
struct sockaddr_in addr;
|
|
uv_os_fd_t fd;
|
|
uv_tcp_t tcp;
|
|
uv_udp_t udp;
|
|
uv_pipe_t pipe;
|
|
uv_tty_t tty;
|
|
uv_idle_t idle;
|
|
uv_loop_t* loop;
|
|
|
|
loop = uv_default_loop();
|
|
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));
|
|
|
|
r = uv_idle_init(loop, &idle);
|
|
ASSERT(r == 0);
|
|
r = uv_fileno((uv_handle_t*) &idle, &fd);
|
|
ASSERT(r == UV_EINVAL);
|
|
uv_close((uv_handle_t*) &idle, NULL);
|
|
|
|
r = uv_tcp_init(loop, &tcp);
|
|
ASSERT(r == 0);
|
|
r = uv_fileno((uv_handle_t*) &tcp, &fd);
|
|
ASSERT(r == UV_EBADF);
|
|
r = uv_tcp_bind(&tcp, (const struct sockaddr*) &addr, 0);
|
|
ASSERT(r == 0);
|
|
r = uv_fileno((uv_handle_t*) &tcp, &fd);
|
|
ASSERT(r == 0);
|
|
uv_close((uv_handle_t*) &tcp, NULL);
|
|
r = uv_fileno((uv_handle_t*) &tcp, &fd);
|
|
ASSERT(r == UV_EBADF);
|
|
|
|
r = uv_udp_init(loop, &udp);
|
|
ASSERT(r == 0);
|
|
r = uv_fileno((uv_handle_t*) &udp, &fd);
|
|
ASSERT(r == UV_EBADF);
|
|
r = uv_udp_bind(&udp, (const struct sockaddr*) &addr, 0);
|
|
ASSERT(r == 0);
|
|
r = uv_fileno((uv_handle_t*) &udp, &fd);
|
|
ASSERT(r == 0);
|
|
uv_close((uv_handle_t*) &udp, NULL);
|
|
r = uv_fileno((uv_handle_t*) &udp, &fd);
|
|
ASSERT(r == UV_EBADF);
|
|
|
|
r = uv_pipe_init(loop, &pipe, 0);
|
|
ASSERT(r == 0);
|
|
r = uv_fileno((uv_handle_t*) &pipe, &fd);
|
|
ASSERT(r == UV_EBADF);
|
|
r = uv_pipe_bind(&pipe, TEST_PIPENAME);
|
|
ASSERT(r == 0);
|
|
r = uv_fileno((uv_handle_t*) &pipe, &fd);
|
|
ASSERT(r == 0);
|
|
uv_close((uv_handle_t*) &pipe, NULL);
|
|
r = uv_fileno((uv_handle_t*) &pipe, &fd);
|
|
ASSERT(r == UV_EBADF);
|
|
|
|
tty_fd = get_tty_fd();
|
|
if (tty_fd < 0) {
|
|
fprintf(stderr, "Cannot open a TTY fd");
|
|
fflush(stderr);
|
|
} else {
|
|
r = uv_tty_init(loop, &tty, tty_fd, 0);
|
|
ASSERT(r == 0);
|
|
ASSERT(uv_is_readable((uv_stream_t*) &tty));
|
|
ASSERT(!uv_is_writable((uv_stream_t*) &tty));
|
|
r = uv_fileno((uv_handle_t*) &tty, &fd);
|
|
ASSERT(r == 0);
|
|
uv_close((uv_handle_t*) &tty, NULL);
|
|
r = uv_fileno((uv_handle_t*) &tty, &fd);
|
|
ASSERT(r == UV_EBADF);
|
|
ASSERT(!uv_is_readable((uv_stream_t*) &tty));
|
|
ASSERT(!uv_is_writable((uv_stream_t*) &tty));
|
|
}
|
|
|
|
uv_run(loop, UV_RUN_DEFAULT);
|
|
|
|
MAKE_VALGRIND_HAPPY();
|
|
return 0;
|
|
}
|