Browse Source

deps: upgrade libuv to 3ee4d3f

v0.11.5-release
Ben Noordhuis 12 years ago
parent
commit
0e48cb4998
  1. 24
      deps/uv/.gitignore
  2. 1
      deps/uv/AUTHORS
  3. 45
      deps/uv/ChangeLog
  4. 53
      deps/uv/Makefile
  5. 223
      deps/uv/Makefile.am
  6. 78
      deps/uv/README.md
  7. 25
      deps/uv/autogen.sh
  8. 169
      deps/uv/build.mk
  9. 21
      deps/uv/checksparse.sh
  10. 1
      deps/uv/common.gypi
  11. 48
      deps/uv/config-mingw.mk
  12. 207
      deps/uv/config-unix.mk
  13. 47
      deps/uv/configure.ac
  14. 0
      deps/uv/include/pthread-fixes.h
  15. 0
      deps/uv/include/stdint-msvc2008.h
  16. 0
      deps/uv/include/tree.h
  17. 0
      deps/uv/include/uv-bsd.h
  18. 2
      deps/uv/include/uv-darwin.h
  19. 365
      deps/uv/include/uv-errno.h
  20. 2
      deps/uv/include/uv-linux.h
  21. 0
      deps/uv/include/uv-sunos.h
  22. 0
      deps/uv/include/uv-unix.h
  23. 6
      deps/uv/include/uv-win.h
  24. 275
      deps/uv/include/uv.h
  25. 18
      deps/uv/src/fs-poll.c
  26. 80
      deps/uv/src/inet.c
  27. 60
      deps/uv/src/unix/aix.c
  28. 24
      deps/uv/src/unix/async.c
  29. 105
      deps/uv/src/unix/core.c
  30. 14
      deps/uv/src/unix/darwin-proctitle.c
  31. 81
      deps/uv/src/unix/darwin.c
  32. 88
      deps/uv/src/unix/error.c
  33. 95
      deps/uv/src/unix/freebsd.c
  34. 61
      deps/uv/src/unix/fs.c
  35. 4
      deps/uv/src/unix/fsevents.c
  36. 51
      deps/uv/src/unix/getaddrinfo.c
  37. 3
      deps/uv/src/unix/internal.h
  38. 10
      deps/uv/src/unix/kqueue.c
  39. 76
      deps/uv/src/unix/linux-core.c
  40. 39
      deps/uv/src/unix/linux-inotify.c
  41. 3
      deps/uv/src/unix/loop-watcher.c
  42. 6
      deps/uv/src/unix/loop.c
  43. 90
      deps/uv/src/unix/netbsd.c
  44. 91
      deps/uv/src/unix/openbsd.c
  45. 114
      deps/uv/src/unix/pipe.c
  46. 3
      deps/uv/src/unix/poll.c
  47. 95
      deps/uv/src/unix/process.c
  48. 10
      deps/uv/src/unix/proctitle.c
  49. 34
      deps/uv/src/unix/signal.c
  50. 176
      deps/uv/src/unix/stream.c
  51. 125
      deps/uv/src/unix/sunos.c
  52. 98
      deps/uv/src/unix/tcp.c
  53. 144
      deps/uv/src/unix/thread.c
  54. 15
      deps/uv/src/unix/threadpool.c
  55. 2
      deps/uv/src/unix/timer.c
  56. 16
      deps/uv/src/unix/tty.c
  57. 113
      deps/uv/src/unix/udp.c
  58. 193
      deps/uv/src/uv-common.c
  59. 12
      deps/uv/src/uv-common.h
  60. 2
      deps/uv/src/version.c
  61. 2
      deps/uv/src/win/core.c
  62. 9
      deps/uv/src/win/error.c
  63. 12
      deps/uv/src/win/fs-event.c
  64. 158
      deps/uv/src/win/fs.c
  65. 53
      deps/uv/src/win/getaddrinfo.c
  66. 13
      deps/uv/src/win/internal.h
  67. 2
      deps/uv/src/win/loop-watcher.c
  68. 155
      deps/uv/src/win/pipe.c
  69. 50
      deps/uv/src/win/poll.c
  70. 50
      deps/uv/src/win/process-stdio.c
  71. 136
      deps/uv/src/win/process.c
  72. 26
      deps/uv/src/win/signal.c
  73. 106
      deps/uv/src/win/stream.c
  74. 305
      deps/uv/src/win/tcp.c
  75. 74
      deps/uv/src/win/thread.c
  76. 7
      deps/uv/src/win/threadpool.c
  77. 3
      deps/uv/src/win/timer.c
  78. 75
      deps/uv/src/win/tty.c
  79. 187
      deps/uv/src/win/udp.c
  80. 125
      deps/uv/src/win/util.c
  81. 3
      deps/uv/test/benchmark-multi-accept.c
  82. 2
      deps/uv/test/benchmark-ping-pongs.c
  83. 18
      deps/uv/test/benchmark-pound.c
  84. 2
      deps/uv/test/benchmark-pump.c
  85. 4
      deps/uv/test/benchmark-spawn.c
  86. 7
      deps/uv/test/benchmark-udp-pummel.c
  87. 2
      deps/uv/test/blackhole-server.c
  88. 5
      deps/uv/test/dns-server.c
  89. 31
      deps/uv/test/echo-server.c
  90. 2
      deps/uv/test/task.h
  91. 5
      deps/uv/test/test-callback-stack.c
  92. 2
      deps/uv/test/test-condvar.c
  93. 6
      deps/uv/test/test-connection-fail.c
  94. 8
      deps/uv/test/test-cwd-and-chdir.c
  95. 6
      deps/uv/test/test-delayed-accept.c
  96. 17
      deps/uv/test/test-error.c
  97. 28
      deps/uv/test/test-fs-event.c
  98. 6
      deps/uv/test/test-fs-poll.c
  99. 341
      deps/uv/test/test-fs.c
  100. 4
      deps/uv/test/test-get-currentexe.c

24
deps/uv/.gitignore

@ -9,11 +9,31 @@ core
vgcore.* vgcore.*
.buildstamp .buildstamp
/libuv.so /.deps/
/.libs/
/aclocal.m4
/ar-lib
/autom4te.cache/
/config.guess
/config.log
/config.status
/config.sub
/configure
/depcomp
/install-sh
/libtool
/libuv.a
/libuv.dylib /libuv.dylib
/libuv.pc
/libuv.so
/ltmain.sh
/missing
/test-driver
Makefile
Makefile.in
# Generated by dtrace(1) when doing an in-tree build. # Generated by dtrace(1) when doing an in-tree build.
/src/unix/uv-dtrace.h /include/uv-dtrace.h
/out/ /out/
/build/gyp /build/gyp

1
deps/uv/AUTHORS

@ -90,3 +90,4 @@ Sean Silva <chisophugis@gmail.com>
Wynn Wilkes <wynnw@movenetworks.com> Wynn Wilkes <wynnw@movenetworks.com>
Linus Mårtensson <linus.martensson@sonymobile.com> Linus Mårtensson <linus.martensson@sonymobile.com>
Andrei Sedoi <bsnote@gmail.com> Andrei Sedoi <bsnote@gmail.com>
Navaneeth Kedaram Nambiathan <navaneethkn@gmail.com>

45
deps/uv/ChangeLog

@ -1,4 +1,47 @@
2013.06.27, Version 0.11.5 (Unstable) 2013.07.21, Version 0.11.6 (Unstable)
Changes since version 0.11.5:
* test: open stdout fd in write-only mode (Ben Noordhuis)
* windows: uv_spawn shouldn't reject reparse points (Bert Belder)
* windows: use WSAGetLastError(), not errno (Ben Noordhuis)
* build: darwin: disable -fstrict-aliasing warnings (Ben Noordhuis)
* test: fix signed/unsigned compiler warning (Ben Noordhuis)
* test: add 'start timer from check handle' test (Ben Noordhuis)
* build: `all` now builds static and dynamic lib (Ben Noordhuis)
* unix, windows: add extra fields to uv_stat_t (Saúl Ibarra Corretgé)
* build: add install target to the makefile (Navaneeth Kedaram Nambiathan)
* build: switch to autotools (Ben Noordhuis)
* build: use AM_PROG_AR conditionally (Ben Noordhuis)
* test: fix fs_fstat test on sunos (Ben Noordhuis)
* test: fix fs_chown when running as root (Ben Noordhuis)
* test: fix spawn_setgid_fails and spawn_setuid_fails (Ben Noordhuis)
* build: use AM_SILENT_RULES conditionally (Ben Noordhuis)
* build: add DTrace detection for autotools (Timothy J. Fontaine)
* linux,darwin,win: link-local IPv6 addresses (Miroslav Bajtoš)
* unix: fix build when !defined(PTHREAD_MUTEX_ERRORCHECK) (Ben Noordhuis)
* unix, windows: return error codes directly (Ben Noordhuis)
2013.06.27, Version 0.11.5 (Unstable), e3c63ff1627a14e96f54c1c62b0d68b446d8425b
Changes since version 0.11.4: Changes since version 0.11.4:

53
deps/uv/Makefile

@ -1,53 +0,0 @@
# 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.
SRCDIR ?= $(CURDIR)
ifeq (,$(builddir_name))
VPATH := $(SRCDIR)
include $(SRCDIR)/build.mk
else # Out of tree build.
# Drop all built-in rules.
.SUFFIXES:
.PHONY: $(builddir_name)
$(builddir_name): $(builddir_name)/.buildstamp
$(MAKE) -C $@ -f $(CURDIR)/Makefile $(MAKECMDGOALS) \
SRCDIR=$(CURDIR) builddir_name=
$(builddir_name)/.buildstamp:
mkdir -p $(dir $@)
touch $@
# Add no-op rules for Makefiles to stop make from trying to rebuild them.
Makefile:: ;
%.mk:: ;
# Turn everything else into a no-op rule that depends on the build directory.
%:: $(builddir_name) ;
.PHONY: clean distclean
clean distclean:
$(RM) -fr $(builddir_name)
endif

223
deps/uv/Makefile.am

@ -0,0 +1,223 @@
# Copyright (c) 2013, Ben Noordhuis <info@bnoordhuis.nl>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
ACLOCAL_AMFLAGS = -I m4
AM_CPPFLAGS = -I$(top_srcdir)/include \
-I$(top_srcdir)/src/unix \
-I$(top_srcdir)/src
include_HEADERS=include/uv.h include/uv-errno.h include/uv-unix.h
CLEANFILES =
lib_LTLIBRARIES = libuv.la
libuv_la_CFLAGS = @CFLAGS@
libuv_la_LDFLAGS = -no-undefined -version-info 11:0:0
libuv_la_SOURCES = src/fs-poll.c \
src/inet.c \
src/uv-common.c \
src/uv-common.h \
src/version.c \
src/unix/async.c \
src/unix/core.c \
src/unix/dl.c \
src/unix/fs.c \
src/unix/getaddrinfo.c \
src/unix/internal.h \
src/unix/loop-watcher.c \
src/unix/loop.c \
src/unix/pipe.c \
src/unix/poll.c \
src/unix/process.c \
src/unix/signal.c \
src/unix/stream.c \
src/unix/tcp.c \
src/unix/thread.c \
src/unix/threadpool.c \
src/unix/timer.c \
src/unix/tty.c \
src/unix/udp.c
TESTS = test/run-tests
check_PROGRAMS = test/run-tests
test_run_tests_SOURCES = test/blackhole-server.c \
test/dns-server.c \
test/echo-server.c \
test/run-tests.c \
test/runner-unix.c \
test/runner-unix.h \
test/runner.c \
test/runner.h \
test/task.h \
test/test-active.c \
test/test-async.c \
test/test-barrier.c \
test/test-callback-order.c \
test/test-callback-stack.c \
test/test-condvar.c \
test/test-connection-fail.c \
test/test-cwd-and-chdir.c \
test/test-delayed-accept.c \
test/test-dlerror.c \
test/test-embed.c \
test/test-error.c \
test/test-fail-always.c \
test/test-fs-event.c \
test/test-fs-poll.c \
test/test-fs.c \
test/test-get-currentexe.c \
test/test-get-loadavg.c \
test/test-get-memory.c \
test/test-getaddrinfo.c \
test/test-getsockname.c \
test/test-hrtime.c \
test/test-idle.c \
test/test-ip6-addr.c \
test/test-ipc-send-recv.c \
test/test-ipc.c \
test/test-list.h \
test/test-loop-handles.c \
test/test-loop-stop.c \
test/test-multiple-listen.c \
test/test-mutexes.c \
test/test-osx-select.c \
test/test-pass-always.c \
test/test-ping-pong.c \
test/test-pipe-bind-error.c \
test/test-pipe-connect-error.c \
test/test-platform-output.c \
test/test-poll-close.c \
test/test-poll.c \
test/test-process-title.c \
test/test-ref.c \
test/test-run-nowait.c \
test/test-run-once.c \
test/test-semaphore.c \
test/test-shutdown-close.c \
test/test-shutdown-eof.c \
test/test-signal-multiple-loops.c \
test/test-signal.c \
test/test-spawn.c \
test/test-stdio-over-pipes.c \
test/test-tcp-bind-error.c \
test/test-tcp-bind6-error.c \
test/test-tcp-close-while-connecting.c \
test/test-tcp-close.c \
test/test-tcp-connect-error-after-write.c \
test/test-tcp-connect-error.c \
test/test-tcp-connect-timeout.c \
test/test-tcp-connect6-error.c \
test/test-tcp-flags.c \
test/test-tcp-open.c \
test/test-tcp-read-stop.c \
test/test-tcp-shutdown-after-write.c \
test/test-tcp-unexpected-read.c \
test/test-tcp-write-to-half-open-connection.c \
test/test-tcp-writealot.c \
test/test-thread.c \
test/test-threadpool-cancel.c \
test/test-threadpool.c \
test/test-timer-again.c \
test/test-timer-from-check.c \
test/test-timer.c \
test/test-tty.c \
test/test-udp-dgram-too-big.c \
test/test-udp-ipv6.c \
test/test-udp-multicast-join.c \
test/test-udp-multicast-ttl.c \
test/test-udp-open.c \
test/test-udp-options.c \
test/test-udp-send-and-recv.c \
test/test-util.c \
test/test-walk-handles.c
test_run_tests_LDADD = libuv.la
if AIX
libuv_la_CFLAGS += -D_ALL_SOURCE -D_XOPEN_SOURCE=500
libuv_la_SOURCES += src/unix/aix.c
endif
if DARWIN
include_HEADERS += include/uv-darwin.h
libuv_la_CFLAGS += -D_DARWIN_USE_64_BIT_INODE=1
libuv_la_SOURCES += src/unix/darwin.c \
src/unix/darwin-proctitle.c \
src/unix/fsevents.c \
src/unix/kqueue.c \
src/unix/proctitle.c
libuv_la_LDFLAGS += -framework ApplicationServices \
-framework CoreServices \
-framework Foundation
endif
if FREEBSD
include_HEADERS += include/uv-bsd.h
libuv_la_SOURCES += src/unix/freebsd.c src/unix/kqueue.c
endif
if LINUX
include_HEADERS += include/uv-linux.h
libuv_la_SOURCES += src/unix/linux-core.c \
src/unix/linux-inotify.c \
src/unix/linux-syscalls.c \
src/unix/linux-syscalls.h \
src/unix/proctitle.c
endif
if NETBSD
include_HEADERS += include/uv-bsd.h
libuv_la_SOURCES += src/unix/kqueue.c src/unix/netbsd.c
endif
if OPENBSD
include_HEADERS += include/uv-bsd.h
libuv_la_SOURCES += src/unix/kqueue.c src/unix/openbsd.c
endif
if SUNOS
include_HEADERS += include/uv-sunos.h
libuv_la_CFLAGS += -D__EXTENSIONS__ -D_XOPEN_SOURCE=500
libuv_la_SOURCES += src/unix/sunos.c
endif
if HAVE_DTRACE
BUILT_SOURCES = include/uv-dtrace.h
CLEANFILES += include/uv-dtrace.h
endif
if DTRACE_NEEDS_OBJECTS
libuv_la_SOURCES += src/unix/uv-dtrace.d
libuv_la_DEPENDENCIES = src/unix/uv-dtrace.o
libuv_la_LIBADD = src/unix/uv-dtrace.lo
CLEANFILES += src/unix/uv-dtrace.o src/unix/uv-dtrace.lo
endif
SUFFIXES = .d
include/uv-dtrace.h: src/unix/uv-dtrace.d
$(AM_V_GEN)$(DTRACE) $(DTRACEFLAGS) -h -xnolibs -s $< -o $@
src/unix/uv-dtrace.o: src/unix/uv-dtrace.d ${libuv_la_OBJECTS}
.d.o:
$(AM_V_GEN)$(DTRACE) $(DTRACEFLAGS) -G -o $@ -s $< \
`grep '^pic_object' ${top_builddir}/*.lo | cut -f 2 -d\'`
$(AM_V_GEN)printf %s\\n \
'# $(patsubst %.o, %.lo, $@) - a libtool object file' \
'# Generated by libtool (GNU libtool) 2.4' \
'# libtool wants a .lo not a .o' \
"pic_object='uv-dtrace.o'" \
"non_pic_object='uv-dtrace.o'" \
> $(patsubst %.o, %.lo, $@)

78
deps/uv/README.md

@ -1,11 +1,9 @@
# libuv # libuv
libuv is a new platform layer for Node. Its purpose is to abstract IOCP on libuv is a platform layer for [node.js][]. Its purpose is to abstract IOCP
Windows and epoll/kqueue/event ports/etc. on Unix systems. We intend to on Windows and epoll/kqueue/event ports/etc. on Unix systems. We intend to
eventually contain all platform differences in this library. eventually contain all platform differences in this library.
http://nodejs.org/
## Features ## Features
* Non-blocking TCP sockets * Non-blocking TCP sockets
@ -30,9 +28,8 @@ http://nodejs.org/
* ANSI escape code controlled TTY `uv_tty_t` * ANSI escape code controlled TTY `uv_tty_t`
* File system events Currently supports inotify, `ReadDirectoryChangesW` * File system events using inotify, kqueue, event ports,
and kqueue. Event ports in the near future. FSEvents and `ReadDirectoryChangesW`
`uv_fs_event_t`
* IPC and socket sharing between processes `uv_write2` * IPC and socket sharing between processes `uv_write2`
@ -53,55 +50,46 @@ http://nodejs.org/
## Build Instructions ## Build Instructions
For GCC (including MinGW) there are two methods building: via normal For GCC there are two methods building: via autotools or via [GYP][].
makefiles or via GYP. GYP is a meta-build system which can generate MSVS, GYP is a meta-build system which can generate MSVS, Makefile, and XCode
Makefile, and XCode backends. It is best used for integration into other backends. It is best used for integration into other projects.
projects. The old system is using plain GNU Makefiles.
To build via Makefile simply execute:
make
MinGW users should run this instead:
make PLATFORM=mingw
Out-of-tree builds are supported:
make builddir_name=/path/to/builddir To build with autotools:
To build a shared object: $ sh autogen.sh
$ ./configure
make libuv.so # libuv.dylib on OS X $ make
$ make check
$ make install
To build with Visual Studio run the vcbuild.bat file which will To build with Visual Studio run the vcbuild.bat file which will
checkout the GYP code into build/gyp and generate the uv.sln and checkout the GYP code into build/gyp and generate the uv.sln and
related files. related files.
Windows users can also build from cmd-line using msbuild. This is Windows users can also build from the command line using msbuild.
done by running vcbuild.bat from Visual Studio command prompt. This is done by running vcbuild.bat from Visual Studio command prompt.
To have GYP generate build script for another system, make sure that To have GYP generate build script for another system, make sure that
you have Python 2.6 or 2.7 installed, then checkout GYP into the you have Python 2.6 or 2.7 installed, then checkout GYP into the
project tree manually: project tree manually:
mkdir -p build $ mkdir -p build
svn co http://gyp.googlecode.com/svn/trunk build/gyp $ git clone https://git.chromium.org/external/gyp.git build/gyp
Or: Unix users run:
mkdir -p build $ ./gyp_uv -f make
git clone https://git.chromium.org/external/gyp.git build/gyp $ make -C out
Unix users run Macintosh users run:
./gyp_uv -f make $ ./gyp_uv -f xcode
make -C out $ xcodebuild -project uv.xcodeproj -configuration Release -target All
Macintosh users run To build for android:
./gyp_uv -f xcode $ source ./android-configure NDK_PATH gyp
xcodebuild -project uv.xcodeproj -configuration Release -target All $ make -C out
Note for UNIX users: compile your project with `-D_LARGEFILE_SOURCE` and Note for UNIX users: compile your project with `-D_LARGEFILE_SOURCE` and
`-D_FILE_OFFSET_BITS=64`. GYP builds take care of that automatically. `-D_FILE_OFFSET_BITS=64`. GYP builds take care of that automatically.
@ -110,16 +98,6 @@ Note for Linux users: compile your project with `-D_GNU_SOURCE` when you
include `uv.h`. GYP builds take care of that automatically. If you use include `uv.h`. GYP builds take care of that automatically. If you use
autotools, add a `AC_GNU_SOURCE` declaration to your `configure.ac`. autotools, add a `AC_GNU_SOURCE` declaration to your `configure.ac`.
To build for android, locate your android NDK path, then run:
source ./android-configure NDK_PATH
make
To build for android with gyp, add "gyp" to the configuration:
source ./android-configure NDK_PATH gyp
make -C out
## Supported Platforms ## Supported Platforms
Microsoft Windows operating systems since Windows XP SP2. It can be built Microsoft Windows operating systems since Windows XP SP2. It can be built
@ -127,10 +105,12 @@ with either Visual Studio or MinGW. Consider using
[Visual Studio Express 2010][] or later if you do not have a full Visual [Visual Studio Express 2010][] or later if you do not have a full Visual
Studio license. Studio license.
Linux 2.6 using the GCC toolchain. Linux using the GCC toolchain.
MacOS using the GCC or XCode toolchain. MacOS using the GCC or XCode toolchain.
Solaris 121 and later using GCC toolchain. Solaris 121 and later using GCC toolchain.
[node.js]: http://nodejs.org/
[GYP]: http://code.google.com/p/gyp/
[Visual Studio Express 2010]: http://www.microsoft.com/visualstudio/eng/products/visual-studio-2010-express [Visual Studio Express 2010]: http://www.microsoft.com/visualstudio/eng/products/visual-studio-2010-express

25
deps/uv/autogen.sh

@ -0,0 +1,25 @@
#!/bin/sh
# Copyright (c) 2013, Ben Noordhuis <info@bnoordhuis.nl>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
if [ "$LIBTOOLIZE" == "" ] && [ "`uname`" == "Darwin" ]; then
LIBTOOLIZE=glibtoolize
fi
set -ex
${LIBTOOLIZE:-libtoolize}
${ACLOCAL:-aclocal -I m4}
${AUTOCONF:-autoconf}
${AUTOMAKE:-automake} --add-missing

169
deps/uv/build.mk

@ -1,169 +0,0 @@
# 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.
ifdef PLATFORM
override PLATFORM := $(shell echo $(PLATFORM) | tr "[A-Z]" "[a-z]")
else
PLATFORM = $(shell sh -c 'uname -s | tr "[A-Z]" "[a-z]"')
endif
CPPFLAGS += -I$(SRCDIR)/include -I$(SRCDIR)/include/uv-private
ifeq (darwin,$(PLATFORM))
SOEXT = dylib
else
SOEXT = so
endif
ifneq (,$(findstring mingw,$(PLATFORM)))
include $(SRCDIR)/config-mingw.mk
else
include $(SRCDIR)/config-unix.mk
endif
BENCHMARKS= \
test/benchmark-async-pummel.o \
test/benchmark-async.o \
test/benchmark-fs-stat.o \
test/benchmark-getaddrinfo.o \
test/benchmark-loop-count.o \
test/benchmark-million-async.o \
test/benchmark-million-timers.o \
test/benchmark-multi-accept.o \
test/benchmark-ping-pongs.o \
test/benchmark-pound.o \
test/benchmark-pump.o \
test/benchmark-sizes.o \
test/benchmark-spawn.o \
test/benchmark-tcp-write-batch.o \
test/benchmark-thread.o \
test/benchmark-udp-pummel.o \
test/blackhole-server.o \
test/dns-server.o \
test/echo-server.o \
TESTS= \
test/blackhole-server.o \
test/dns-server.o \
test/echo-server.o \
test/test-active.o \
test/test-async.o \
test/test-barrier.o \
test/test-callback-order.o \
test/test-callback-stack.o \
test/test-condvar.o \
test/test-connection-fail.o \
test/test-cwd-and-chdir.o \
test/test-delayed-accept.o \
test/test-dlerror.o \
test/test-embed.o \
test/test-error.o \
test/test-fail-always.o \
test/test-fs.o \
test/test-fs-event.o \
test/test-fs-poll.o \
test/test-getaddrinfo.o \
test/test-get-currentexe.o \
test/test-get-loadavg.o \
test/test-get-memory.o \
test/test-getsockname.o \
test/test-hrtime.o \
test/test-idle.o \
test/test-ipc.o \
test/test-ipc-send-recv.o \
test/test-loop-handles.o \
test/test-loop-stop.o \
test/test-multiple-listen.o \
test/test-mutexes.o \
test/test-osx-select.o \
test/test-pass-always.o \
test/test-ping-pong.o \
test/test-pipe-bind-error.o \
test/test-pipe-connect-error.o \
test/test-platform-output.o \
test/test-poll.o \
test/test-poll-close.o \
test/test-process-title.o \
test/test-ref.o \
test/test-run-nowait.o \
test/test-run-once.o \
test/test-semaphore.o \
test/test-shutdown-close.o \
test/test-shutdown-eof.o \
test/test-signal.o \
test/test-signal-multiple-loops.o \
test/test-spawn.o \
test/test-stdio-over-pipes.o \
test/test-tcp-bind6-error.o \
test/test-tcp-bind-error.o \
test/test-tcp-close.o \
test/test-tcp-close-while-connecting.o \
test/test-tcp-connect6-error.o \
test/test-tcp-connect-error-after-write.o \
test/test-tcp-connect-error.o \
test/test-tcp-connect-timeout.o \
test/test-tcp-flags.o \
test/test-tcp-open.o \
test/test-tcp-read-stop.o \
test/test-tcp-shutdown-after-write.o \
test/test-tcp-unexpected-read.o \
test/test-tcp-writealot.o \
test/test-tcp-write-to-half-open-connection.o \
test/test-thread.o \
test/test-threadpool.o \
test/test-threadpool-cancel.o \
test/test-timer-again.o \
test/test-timer.o \
test/test-tty.o \
test/test-udp-dgram-too-big.o \
test/test-udp-ipv6.o \
test/test-udp-multicast-join.o \
test/test-udp-multicast-ttl.o \
test/test-udp-open.o \
test/test-udp-options.o \
test/test-udp-send-and-recv.o \
test/test-util.o \
test/test-walk-handles.o \
all: libuv.a
run-tests$(E): test/run-tests.o test/runner.o $(RUNNER_SRC) $(TESTS) libuv.a
$(CC) $(CPPFLAGS) $(RUNNER_CFLAGS) -o $@ $^ $(RUNNER_LIBS) $(RUNNER_LDFLAGS)
run-benchmarks$(E): test/run-benchmarks.o test/runner.o $(RUNNER_SRC) $(BENCHMARKS) libuv.a
$(CC) $(CPPFLAGS) $(RUNNER_CFLAGS) -o $@ $^ $(RUNNER_LIBS) $(RUNNER_LDFLAGS)
test/echo.o: test/echo.c test/echo.h
.PHONY: clean clean-platform distclean test bench
test: run-tests$(E)
$(CURDIR)/$<
bench: run-benchmarks$(E)
$(CURDIR)/$<
clean distclean: clean-platform
$(RM) libuv.a libuv.$(SOEXT) \
test/run-tests.o test/run-benchmarks.o \
test/runner.o run-tests$(E) test/run-benchmarks$(E) \
$(BENCHMARKS) $(TESTS) $(RUNNER_LIBS)

21
deps/uv/checksparse.sh

@ -22,13 +22,12 @@ SPARSE_FLAGS=${SPARSE_FLAGS:-"
-Wno-do-while -Wno-do-while
-Wno-transparent-union -Wno-transparent-union
-Iinclude -Iinclude
-Iinclude/uv-private
-Isrc -Isrc
"} "}
SOURCES=" SOURCES="
include/uv-private/tree.h include/tree.h
include/uv-private/uv-unix.h include/uv-unix.h
include/uv.h include/uv.h
src/fs-poll.c src/fs-poll.c
src/inet.c src/inet.c
@ -36,7 +35,6 @@ src/queue.h
src/unix/async.c src/unix/async.c
src/unix/core.c src/unix/core.c
src/unix/dl.c src/unix/dl.c
src/unix/error.c
src/unix/fs.c src/unix/fs.c
src/unix/getaddrinfo.c src/unix/getaddrinfo.c
src/unix/internal.h src/unix/internal.h
@ -107,6 +105,7 @@ test/test-getaddrinfo.c
test/test-getsockname.c test/test-getsockname.c
test/test-hrtime.c test/test-hrtime.c
test/test-idle.c test/test-idle.c
test/test-ip6-addr.c
test/test-ipc-send-recv.c test/test-ipc-send-recv.c
test/test-ipc.c test/test-ipc.c
test/test-loop-handles.c test/test-loop-handles.c
@ -172,7 +171,7 @@ AIX)
Darwin) Darwin)
SPARSE_FLAGS="$SPARSE_FLAGS -D__APPLE__=1" SPARSE_FLAGS="$SPARSE_FLAGS -D__APPLE__=1"
SOURCES="$SOURCES SOURCES="$SOURCES
include/uv-private/uv-bsd.h include/uv-bsd.h
src/unix/darwin.c src/unix/darwin.c
src/unix/kqueue.c src/unix/kqueue.c
src/unix/fsevents.c" src/unix/fsevents.c"
@ -180,21 +179,21 @@ Darwin)
DragonFly) DragonFly)
SPARSE_FLAGS="$SPARSE_FLAGS -D__DragonFly__=1" SPARSE_FLAGS="$SPARSE_FLAGS -D__DragonFly__=1"
SOURCES="$SOURCES SOURCES="$SOURCES
include/uv-private/uv-bsd.h include/uv-bsd.h
src/unix/kqueue.c src/unix/kqueue.c
src/unix/freebsd.c" src/unix/freebsd.c"
;; ;;
FreeBSD) FreeBSD)
SPARSE_FLAGS="$SPARSE_FLAGS -D__FreeBSD__=1" SPARSE_FLAGS="$SPARSE_FLAGS -D__FreeBSD__=1"
SOURCES="$SOURCES SOURCES="$SOURCES
include/uv-private/uv-bsd.h include/uv-bsd.h
src/unix/kqueue.c src/unix/kqueue.c
src/unix/freebsd.c" src/unix/freebsd.c"
;; ;;
Linux) Linux)
SPARSE_FLAGS="$SPARSE_FLAGS -D__linux__=1" SPARSE_FLAGS="$SPARSE_FLAGS -D__linux__=1"
SOURCES="$SOURCES SOURCES="$SOURCES
include/uv-private/uv-linux.h include/uv-linux.h
src/unix/linux-inotify.c src/unix/linux-inotify.c
src/unix/linux-core.c src/unix/linux-core.c
src/unix/linux-syscalls.c src/unix/linux-syscalls.c
@ -203,21 +202,21 @@ Linux)
NetBSD) NetBSD)
SPARSE_FLAGS="$SPARSE_FLAGS -D__NetBSD__=1" SPARSE_FLAGS="$SPARSE_FLAGS -D__NetBSD__=1"
SOURCES="$SOURCES SOURCES="$SOURCES
include/uv-private/uv-bsd.h include/uv-bsd.h
src/unix/kqueue.c src/unix/kqueue.c
src/unix/netbsd.c" src/unix/netbsd.c"
;; ;;
OpenBSD) OpenBSD)
SPARSE_FLAGS="$SPARSE_FLAGS -D__OpenBSD__=1" SPARSE_FLAGS="$SPARSE_FLAGS -D__OpenBSD__=1"
SOURCES="$SOURCES SOURCES="$SOURCES
include/uv-private/uv-bsd.h include/uv-bsd.h
src/unix/kqueue.c src/unix/kqueue.c
src/unix/openbsd.c" src/unix/openbsd.c"
;; ;;
SunOS) SunOS)
SPARSE_FLAGS="$SPARSE_FLAGS -D__sun=1" SPARSE_FLAGS="$SPARSE_FLAGS -D__sun=1"
SOURCES="$SOURCES SOURCES="$SOURCES
include/uv-private/uv-sunos.h include/uv-sunos.h
src/unix/sunos.c" src/unix/sunos.c"
;; ;;
esac esac

1
deps/uv/common.gypi

@ -36,6 +36,7 @@
}, },
'xcode_settings': { 'xcode_settings': {
'GCC_OPTIMIZATION_LEVEL': '0', 'GCC_OPTIMIZATION_LEVEL': '0',
'OTHER_CFLAGS': [ '-Wno-strict-aliasing' ],
}, },
'conditions': [ 'conditions': [
['OS != "win"', { ['OS != "win"', {

48
deps/uv/config-mingw.mk

@ -1,48 +0,0 @@
# 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.
# Use make -f Makefile.gcc PREFIX=i686-w64-mingw32-
# for cross compilation
CC = $(PREFIX)gcc
AR = $(PREFIX)ar
E=.exe
CFLAGS=$(CPPFLAGS) -g --std=gnu89 -D_WIN32_WINNT=0x0600
LDFLAGS=-lm
WIN_SRCS=$(wildcard $(SRCDIR)/src/win/*.c)
WIN_OBJS=$(WIN_SRCS:.c=.o)
RUNNER_CFLAGS=$(CFLAGS) -D_GNU_SOURCE # Need _GNU_SOURCE for strdup?
RUNNER_LDFLAGS=$(LDFLAGS)
RUNNER_LIBS=-lws2_32 -lpsapi -liphlpapi
RUNNER_SRC=test/runner-win.c
libuv.a: $(WIN_OBJS) src/fs-poll.o src/inet.o src/uv-common.o src/version.o
$(AR) rcs $@ $^
src/%.o: src/%.c include/uv.h include/uv-private/uv-win.h
$(CC) $(CFLAGS) -c $< -o $@
src/win/%.o: src/win/%.c include/uv.h include/uv-private/uv-win.h src/win/internal.h
$(CC) $(CFLAGS) -o $@ -c $<
clean-platform:
-rm -f src/win/*.o

207
deps/uv/config-unix.mk

@ -1,207 +0,0 @@
# 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.
E=
CFLAGS += -g -Wall -Wextra -Wno-unused-parameter
CPPFLAGS += -I$(SRCDIR)/src
LDFLAGS=-lm
CPPFLAGS += -D_LARGEFILE_SOURCE
CPPFLAGS += -D_FILE_OFFSET_BITS=64
RUNNER_SRC=test/runner-unix.c
RUNNER_CFLAGS=$(CFLAGS) -I$(SRCDIR)/test
RUNNER_LDFLAGS=-L"$(CURDIR)" -luv
DTRACE_OBJS=
DTRACE_HEADER=
OBJS += src/unix/async.o
OBJS += src/unix/core.o
OBJS += src/unix/dl.o
OBJS += src/unix/error.o
OBJS += src/unix/fs.o
OBJS += src/unix/getaddrinfo.o
OBJS += src/unix/loop.o
OBJS += src/unix/loop-watcher.o
OBJS += src/unix/pipe.o
OBJS += src/unix/poll.o
OBJS += src/unix/process.o
OBJS += src/unix/signal.o
OBJS += src/unix/stream.o
OBJS += src/unix/tcp.o
OBJS += src/unix/thread.o
OBJS += src/unix/threadpool.o
OBJS += src/unix/timer.o
OBJS += src/unix/tty.o
OBJS += src/unix/udp.o
OBJS += src/fs-poll.o
OBJS += src/uv-common.o
OBJS += src/inet.o
OBJS += src/version.o
ifeq (sunos,$(PLATFORM))
HAVE_DTRACE ?= 1
CPPFLAGS += -D__EXTENSIONS__ -D_XOPEN_SOURCE=500
LDFLAGS+=-lkstat -lnsl -lsendfile -lsocket
# Library dependencies are not transitive.
OBJS += src/unix/sunos.o
ifeq (1, $(HAVE_DTRACE))
OBJS += src/unix/dtrace.o
DTRACE_OBJS += src/unix/core.o
endif
endif
ifeq (aix,$(PLATFORM))
CPPFLAGS += -D_ALL_SOURCE -D_XOPEN_SOURCE=500
LDFLAGS+= -lperfstat
OBJS += src/unix/aix.o
endif
ifeq (darwin,$(PLATFORM))
HAVE_DTRACE ?= 1
# dtrace(1) probes contain dollar signs on OS X. Mute the warnings they
# generate but only when CC=clang, -Wno-dollar-in-identifier-extension
# is a clang extension.
ifeq (__clang__,$(shell sh -c "$(CC) -dM -E - </dev/null | grep -ow __clang__"))
CFLAGS += -Wno-dollar-in-identifier-extension
endif
CPPFLAGS += -D_DARWIN_USE_64_BIT_INODE=1
LDFLAGS += -framework Foundation \
-framework CoreServices \
-framework ApplicationServices
SOEXT = dylib
OBJS += src/unix/darwin.o
OBJS += src/unix/kqueue.o
OBJS += src/unix/fsevents.o
OBJS += src/unix/proctitle.o
OBJS += src/unix/darwin-proctitle.o
endif
ifeq (linux,$(PLATFORM))
CFLAGS += -D_GNU_SOURCE
LDFLAGS+=-ldl -lrt
RUNNER_CFLAGS += -D_GNU_SOURCE
OBJS += src/unix/linux-core.o \
src/unix/linux-inotify.o \
src/unix/linux-syscalls.o \
src/unix/proctitle.o
endif
ifeq (android,$(PLATFORM))
CFLAGS += -D_GNU_SOURCE
LDFLAGS+=-ldl -lrt
RUNNER_CFLAGS += -D_GNU_SOURCE
OBJS += src/unix/linux-core.o \
src/unix/linux-inotify.o \
src/unix/linux-syscalls.o \
src/unix/proctitle.o
else
CFLAGS += -std=c89
endif
ifeq (freebsd,$(PLATFORM))
ifeq ($(shell dtrace -l 1>&2 2>/dev/null; echo $$?),0)
HAVE_DTRACE ?= 1
endif
LDFLAGS+=-lkvm
OBJS += src/unix/freebsd.o
OBJS += src/unix/kqueue.o
endif
ifeq (dragonfly,$(PLATFORM))
LDFLAGS+=-lkvm
OBJS += src/unix/freebsd.o
OBJS += src/unix/kqueue.o
endif
ifeq (netbsd,$(PLATFORM))
LDFLAGS+=-lkvm
OBJS += src/unix/netbsd.o
OBJS += src/unix/kqueue.o
endif
ifeq (openbsd,$(PLATFORM))
LDFLAGS+=-lkvm
OBJS += src/unix/openbsd.o
OBJS += src/unix/kqueue.o
endif
ifeq (sunos,$(PLATFORM))
RUNNER_LDFLAGS += -pthreads
else
ifneq (android, $(PLATFORM))
RUNNER_LDFLAGS += -pthread
endif
endif
ifeq ($(HAVE_DTRACE), 1)
DTRACE_HEADER = src/unix/uv-dtrace.h
CPPFLAGS += -Isrc/unix
CFLAGS += -DHAVE_DTRACE
endif
ifneq (darwin,$(PLATFORM))
# Must correspond with UV_VERSION_MAJOR and UV_VERSION_MINOR in src/version.c
SO_LDFLAGS = -Wl,-soname,libuv.so.0.11
endif
RUNNER_LDFLAGS += $(LDFLAGS)
libuv.a: $(OBJS)
$(AR) rcs $@ $^
libuv.$(SOEXT): override CFLAGS += -fPIC
libuv.$(SOEXT): $(OBJS:%.o=%.pic.o)
$(CC) -shared -o $@ $^ $(LDFLAGS) $(SO_LDFLAGS)
include/uv-private/uv-unix.h: \
include/uv-private/uv-bsd.h \
include/uv-private/uv-darwin.h \
include/uv-private/uv-linux.h \
include/uv-private/uv-sunos.h
src/unix/internal.h: src/unix/linux-syscalls.h src/uv-common.h
src/uv-common.h: src/queue.h
src/.buildstamp src/unix/.buildstamp test/.buildstamp:
mkdir -p $(@D)
touch $@
src/unix/%.o src/unix/%.pic.o: src/unix/%.c include/uv.h include/uv-private/uv-unix.h src/unix/internal.h src/unix/.buildstamp $(DTRACE_HEADER)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
src/%.o src/%.pic.o: src/%.c include/uv.h include/uv-private/uv-unix.h src/.buildstamp
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
test/%.o: test/%.c include/uv.h test/.buildstamp
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
clean-platform:
$(RM) test/run-{tests,benchmarks}.dSYM $(OBJS) $(OBJS:%.o=%.pic.o) src/unix/uv-dtrace.h
src/unix/uv-dtrace.h: src/unix/uv-dtrace.d
dtrace -h -xnolibs -s $< -o $@
src/unix/dtrace.o: src/unix/uv-dtrace.d $(DTRACE_OBJS)
dtrace -G -s $^ -o $@
src/unix/dtrace.pic.o: src/unix/uv-dtrace.d $(DTRACE_OBJS:%.o=%.pic.o)
dtrace -G -s $^ -o $@

47
deps/uv/configure.ac

@ -0,0 +1,47 @@
# Copyright (c) 2013, Ben Noordhuis <info@bnoordhuis.nl>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
AC_PREREQ(2.57)
AC_INIT([libuv], [0.11.5], [https://github.com/joyent/libuv/issues])
AM_INIT_AUTOMAKE([foreign -Wall -Werror])
AC_CONFIG_MACRO_DIR([m4])
AC_CANONICAL_HOST
AC_ENABLE_SHARED
AC_ENABLE_STATIC
AC_PROG_CC
# AM_PROG_AR is not available in automake v0.11 but it's essential in v0.12.
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
LT_INIT
# TODO(bnoordhuis) Check for -pthread vs. -pthreads
AC_CHECK_LIB([dl], [dlopen])
AC_CHECK_LIB([kstat], [kstat_lookup])
AC_CHECK_LIB([kvm], [kvm_open])
AC_CHECK_LIB([nsl], [gethostbyname])
AC_CHECK_LIB([perfstat], [perfstat_cpu])
AC_CHECK_LIB([pthread], [pthread_mutex_init])
AC_CHECK_LIB([rt], [clock_gettime])
AC_CHECK_LIB([sendfile], [sendfile])
AC_CHECK_LIB([socket], [socket])
AC_SYS_LARGEFILE
AM_CONDITIONAL([AIX], [AS_CASE([$host_os], [aix*], [true], [false])])
AM_CONDITIONAL([DARWIN], [AS_CASE([$host_os], [darwin*], [true], [false])])
AM_CONDITIONAL([FREEBSD], [AS_CASE([$host_os], [freebsd*], [true], [false])])
AM_CONDITIONAL([LINUX], [AS_CASE([$host_os], [linux*], [true], [false])])
AM_CONDITIONAL([NETBSD], [AS_CASE([$host_os], [netbsd*], [true], [false])])
AM_CONDITIONAL([OPENBSD], [AS_CASE([$host_os], [openbsd*], [true], [false])])
AM_CONDITIONAL([SUNOS], [AS_CASE([$host_os], [solaris*], [true], [false])])
PANDORA_ENABLE_DTRACE
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

0
deps/uv/include/uv-private/pthread-fixes.h → deps/uv/include/pthread-fixes.h

0
deps/uv/include/uv-private/stdint-msvc2008.h → deps/uv/include/stdint-msvc2008.h

0
deps/uv/include/uv-private/tree.h → deps/uv/include/tree.h

0
deps/uv/include/uv-private/uv-bsd.h → deps/uv/include/uv-bsd.h

2
deps/uv/include/uv-private/uv-darwin.h → deps/uv/include/uv-darwin.h

@ -58,4 +58,6 @@
#define UV_HAVE_KQUEUE 1 #define UV_HAVE_KQUEUE 1
#define UV_PLATFORM_HAS_IP6_LINK_LOCAL_ADDRESS
#endif /* UV_DARWIN_H */ #endif /* UV_DARWIN_H */

365
deps/uv/include/uv-errno.h

@ -0,0 +1,365 @@
/* 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.
*/
#ifndef UV_ERRNO_H_
#define UV_ERRNO_H_
#include <errno.h>
#define UV__EOF (-4095)
#define UV__UNKNOWN (-4094)
#define UV__EAI_ADDRFAMILY (-3000)
#define UV__EAI_AGAIN (-3001)
#define UV__EAI_BADFLAGS (-3002)
#define UV__EAI_CANCELED (-3003)
#define UV__EAI_FAIL (-3004)
#define UV__EAI_FAMILY (-3005)
#define UV__EAI_MEMORY (-3006)
#define UV__EAI_NODATA (-3007)
#define UV__EAI_NONAME (-3008)
#define UV__EAI_OVERFLOW (-3009)
#define UV__EAI_SERVICE (-3010)
#define UV__EAI_SOCKTYPE (-3011)
#define UV__EAI_SYSTEM (-3012) /* TODO(bnoordhuis) Return system error. */
/* Only map to the system errno on non-Windows platforms. It's apparently
* a fairly common practice for Windows programmers to redefine errno codes.
*/
#if defined(EACCES) && !defined(_WIN32)
# define UV__EACCES (-EACCES)
#else
# define UV__EACCES (-4093)
#endif
#if defined(EADDRINFO) && !defined(_WIN32)
# define UV__EADDRINFO EADDRINFO
#else
# define UV__EADDRINFO (-4092)
#endif
#if defined(EADDRINUSE) && !defined(_WIN32)
# define UV__EADDRINUSE (-EADDRINUSE)
#else
# define UV__EADDRINUSE (-4092)
#endif
#if defined(EADDRNOTAVAIL) && !defined(_WIN32)
# define UV__EADDRNOTAVAIL (-EADDRNOTAVAIL)
#else
# define UV__EADDRNOTAVAIL (-4091)
#endif
#if defined(EAFNOSUPPORT) && !defined(_WIN32)
# define UV__EAFNOSUPPORT (-EAFNOSUPPORT)
#else
# define UV__EAFNOSUPPORT (-4090)
#endif
#if defined(EAGAIN) && !defined(_WIN32)
# define UV__EAGAIN (-EAGAIN)
#else
# define UV__EAGAIN (-4089)
#endif
#if defined(EALREADY) && !defined(_WIN32)
# define UV__EALREADY (-EALREADY)
#else
# define UV__EALREADY (-4085)
#endif
#if defined(EBADF) && !defined(_WIN32)
# define UV__EBADF (-EBADF)
#else
# define UV__EBADF (-4084)
#endif
#if defined(EBUSY) && !defined(_WIN32)
# define UV__EBUSY (-EBUSY)
#else
# define UV__EBUSY (-4083)
#endif
#if defined(ECANCELED) && !defined(_WIN32)
# define UV__ECANCELED (-ECANCELED)
#else
# define UV__ECANCELED (-4082)
#endif
#if defined(ECHARSET) && !defined(_WIN32)
# define UV__ECHARSET (-ECHARSET)
#else
# define UV__ECHARSET (-4081)
#endif
#if defined(ECONNABORTED) && !defined(_WIN32)
# define UV__ECONNABORTED (-ECONNABORTED)
#else
# define UV__ECONNABORTED (-4080)
#endif
#if defined(ECONNREFUSED) && !defined(_WIN32)
# define UV__ECONNREFUSED (-ECONNREFUSED)
#else
# define UV__ECONNREFUSED (-4079)
#endif
#if defined(ECONNRESET) && !defined(_WIN32)
# define UV__ECONNRESET (-ECONNRESET)
#else
# define UV__ECONNRESET (-4078)
#endif
#if defined(EDESTADDRREQ) && !defined(_WIN32)
# define UV__EDESTADDRREQ (-EDESTADDRREQ)
#else
# define UV__EDESTADDRREQ (-4077)
#endif
#if defined(EEXIST) && !defined(_WIN32)
# define UV__EEXIST (-EEXIST)
#else
# define UV__EEXIST (-4076)
#endif
#if defined(EFAULT) && !defined(_WIN32)
# define UV__EFAULT (-EFAULT)
#else
# define UV__EFAULT (-4075)
#endif
#if defined(EHOSTUNREACH) && !defined(_WIN32)
# define UV__EHOSTUNREACH (-EHOSTUNREACH)
#else
# define UV__EHOSTUNREACH (-4074)
#endif
#if defined(EINTR) && !defined(_WIN32)
# define UV__EINTR (-EINTR)
#else
# define UV__EINTR (-4073)
#endif
#if defined(EINVAL) && !defined(_WIN32)
# define UV__EINVAL (-EINVAL)
#else
# define UV__EINVAL (-4072)
#endif
#if defined(EIO) && !defined(_WIN32)
# define UV__EIO (-EIO)
#else
# define UV__EIO (-4071)
#endif
#if defined(EISCONN) && !defined(_WIN32)
# define UV__EISCONN (-EISCONN)
#else
# define UV__EISCONN (-4070)
#endif
#if defined(EISDIR) && !defined(_WIN32)
# define UV__EISDIR (-EISDIR)
#else
# define UV__EISDIR (-4069)
#endif
#if defined(ELOOP) && !defined(_WIN32)
# define UV__ELOOP (-ELOOP)
#else
# define UV__ELOOP (-4068)
#endif
#if defined(EMFILE) && !defined(_WIN32)
# define UV__EMFILE (-EMFILE)
#else
# define UV__EMFILE (-4067)
#endif
#if defined(EMSGSIZE) && !defined(_WIN32)
# define UV__EMSGSIZE (-EMSGSIZE)
#else
# define UV__EMSGSIZE (-4066)
#endif
#if defined(ENAMETOOLONG) && !defined(_WIN32)
# define UV__ENAMETOOLONG (-ENAMETOOLONG)
#else
# define UV__ENAMETOOLONG (-4065)
#endif
#if defined(ENETDOWN) && !defined(_WIN32)
# define UV__ENETDOWN (-ENETDOWN)
#else
# define UV__ENETDOWN (-4064)
#endif
#if defined(ENETUNREACH) && !defined(_WIN32)
# define UV__ENETUNREACH (-ENETUNREACH)
#else
# define UV__ENETUNREACH (-4063)
#endif
#if defined(ENFILE) && !defined(_WIN32)
# define UV__ENFILE (-ENFILE)
#else
# define UV__ENFILE (-4062)
#endif
#if defined(ENOBUFS) && !defined(_WIN32)
# define UV__ENOBUFS (-ENOBUFS)
#else
# define UV__ENOBUFS (-4061)
#endif
#if defined(ENODEV) && !defined(_WIN32)
# define UV__ENODEV (-ENODEV)
#else
# define UV__ENODEV (-4060)
#endif
#if defined(ENOENT) && !defined(_WIN32)
# define UV__ENOENT (-ENOENT)
#else
# define UV__ENOENT (-4059)
#endif
#if defined(ENOMEM) && !defined(_WIN32)
# define UV__ENOMEM (-ENOMEM)
#else
# define UV__ENOMEM (-4058)
#endif
#if defined(ENONET) && !defined(_WIN32)
# define UV__ENONET (-ENONET)
#else
# define UV__ENONET (-4057)
#endif
#if defined(ENOSPC) && !defined(_WIN32)
# define UV__ENOSPC (-ENOSPC)
#else
# define UV__ENOSPC (-4056)
#endif
#if defined(ENOSYS) && !defined(_WIN32)
# define UV__ENOSYS (-ENOSYS)
#else
# define UV__ENOSYS (-4055)
#endif
#if defined(ENOTCONN) && !defined(_WIN32)
# define UV__ENOTCONN (-ENOTCONN)
#else
# define UV__ENOTCONN (-4054)
#endif
#if defined(ENOTDIR) && !defined(_WIN32)
# define UV__ENOTDIR (-ENOTDIR)
#else
# define UV__ENOTDIR (-4053)
#endif
#if defined(ENOTEMPTY) && !defined(_WIN32)
# define UV__ENOTEMPTY (-ENOTEMPTY)
#else
# define UV__ENOTEMPTY (-4052)
#endif
#if defined(ENOTSOCK) && !defined(_WIN32)
# define UV__ENOTSOCK (-ENOTSOCK)
#else
# define UV__ENOTSOCK (-4051)
#endif
#if defined(ENOTSUP) && !defined(_WIN32)
# define UV__ENOTSUP (-ENOTSUP)
#else
# define UV__ENOTSUP (-4050)
#endif
#if defined(EPERM) && !defined(_WIN32)
# define UV__EPERM (-EPERM)
#else
# define UV__EPERM (-4049)
#endif
#if defined(EPIPE) && !defined(_WIN32)
# define UV__EPIPE (-EPIPE)
#else
# define UV__EPIPE (-4048)
#endif
#if defined(EPROTO) && !defined(_WIN32)
# define UV__EPROTO (-EPROTO)
#else
# define UV__EPROTO (-4047)
#endif
#if defined(EPROTONOSUPPORT) && !defined(_WIN32)
# define UV__EPROTONOSUPPORT (-EPROTONOSUPPORT)
#else
# define UV__EPROTONOSUPPORT (-4046)
#endif
#if defined(EPROTOTYPE) && !defined(_WIN32)
# define UV__EPROTOTYPE (-EPROTOTYPE)
#else
# define UV__EPROTOTYPE (-4045)
#endif
#if defined(EROFS) && !defined(_WIN32)
# define UV__EROFS (-EROFS)
#else
# define UV__EROFS (-4044)
#endif
#if defined(ESHUTDOWN) && !defined(_WIN32)
# define UV__ESHUTDOWN (-ESHUTDOWN)
#else
# define UV__ESHUTDOWN (-4043)
#endif
#if defined(ESPIPE) && !defined(_WIN32)
# define UV__ESPIPE (-ESPIPE)
#else
# define UV__ESPIPE (-4042)
#endif
#if defined(ESRCH) && !defined(_WIN32)
# define UV__ESRCH (-ESRCH)
#else
# define UV__ESRCH (-4041)
#endif
#if defined(ETIMEDOUT) && !defined(_WIN32)
# define UV__ETIMEDOUT (-ETIMEDOUT)
#else
# define UV__ETIMEDOUT (-4040)
#endif
#if defined(EXDEV) && !defined(_WIN32)
# define UV__EXDEV (-EXDEV)
#else
# define UV__EXDEV (-4038)
#endif
#endif /* UV_ERRNO_H_ */

2
deps/uv/include/uv-private/uv-linux.h → deps/uv/include/uv-linux.h

@ -31,4 +31,6 @@
void* watchers[2]; \ void* watchers[2]; \
int wd; \ int wd; \
#define UV_PLATFORM_HAS_IP6_LINK_LOCAL_ADDRESS
#endif /* UV_LINUX_H */ #endif /* UV_LINUX_H */

0
deps/uv/include/uv-private/uv-sunos.h → deps/uv/include/uv-sunos.h

0
deps/uv/include/uv-private/uv-unix.h → deps/uv/include/uv-unix.h

6
deps/uv/include/uv-private/uv-win.h → deps/uv/include/uv-win.h

@ -39,7 +39,7 @@ typedef intptr_t ssize_t;
#include <sys/stat.h> #include <sys/stat.h>
#if defined(_MSC_VER) && _MSC_VER < 1600 #if defined(_MSC_VER) && _MSC_VER < 1600
# include "uv-private/stdint-msvc2008.h" # include "stdint-msvc2008.h"
#else #else
# include <stdint.h> # include <stdint.h>
#endif #endif
@ -529,7 +529,7 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s);
UV_REQ_FIELDS \ UV_REQ_FIELDS \
} exit_req; \ } exit_req; \
BYTE* child_stdio_buffer; \ BYTE* child_stdio_buffer; \
uv_err_t spawn_error; \ int spawn_error; \
int exit_signal; \ int exit_signal; \
HANDLE wait_handle; \ HANDLE wait_handle; \
HANDLE process_handle; \ HANDLE process_handle; \
@ -582,3 +582,5 @@ int uv_utf16_to_utf8(const WCHAR* utf16Buffer, size_t utf16Size,
char* utf8Buffer, size_t utf8Size); char* utf8Buffer, size_t utf8Size);
int uv_utf8_to_utf16(const char* utf8Buffer, WCHAR* utf16Buffer, int uv_utf8_to_utf16(const char* utf8Buffer, WCHAR* utf16Buffer,
size_t utf16Size); size_t utf16Size);
#define UV_PLATFORM_HAS_IP6_LINK_LOCAL_ADDRESS

275
deps/uv/include/uv.h

@ -45,8 +45,10 @@ extern "C" {
# define UV_EXTERN /* nothing */ # define UV_EXTERN /* nothing */
#endif #endif
#include "uv-errno.h"
#if defined(_MSC_VER) && _MSC_VER < 1600 #if defined(_MSC_VER) && _MSC_VER < 1600
# include "uv-private/stdint-msvc2008.h" # include "stdint-msvc2008.h"
#else #else
# include <stdint.h> # include <stdint.h>
#endif #endif
@ -59,80 +61,79 @@ extern "C" {
#if defined(__unix__) || defined(__POSIX__) || \ #if defined(__unix__) || defined(__POSIX__) || \
defined(__APPLE__) || defined(_AIX) defined(__APPLE__) || defined(_AIX)
# include "uv-private/uv-unix.h" # include "uv-unix.h"
#else #else
# include "uv-private/uv-win.h" # include "uv-win.h"
#endif #endif
/* Expand this list if necessary. */ /* Expand this list if necessary. */
#define UV_ERRNO_MAP(XX) \ #define UV_ERRNO_MAP(XX) \
XX( -1, UNKNOWN, "unknown error") \ XX(EACCES, "permission denied") \
XX( 0, OK, "success") \ XX(EADDRINUSE, "address already in use") \
XX( 1, EOF, "end of file") \ XX(EADDRNOTAVAIL, "address not available") \
XX( 2, EADDRINFO, "getaddrinfo error") \ XX(EAFNOSUPPORT, "address family not supported") \
XX( 3, EACCES, "permission denied") \ XX(EAGAIN, "resource temporarily unavailable") \
XX( 4, EAGAIN, "resource temporarily unavailable") \ XX(EAI_ADDRFAMILY, "address family not supported") \
XX( 5, EADDRINUSE, "address already in use") \ XX(EAI_AGAIN, "temporary failure") \
XX( 6, EADDRNOTAVAIL, "address not available") \ XX(EAI_BADFLAGS, "bad ai_flags value") \
XX( 7, EAFNOSUPPORT, "address family not supported") \ XX(EAI_CANCELED, "request canceled") \
XX( 8, EALREADY, "connection already in progress") \ XX(EAI_FAIL, "permanent failure") \
XX( 9, EBADF, "bad file descriptor") \ XX(EAI_FAMILY, "ai_family not supported") \
XX( 10, EBUSY, "resource busy or locked") \ XX(EAI_MEMORY, "out of memory") \
XX( 11, ECONNABORTED, "software caused connection abort") \ XX(EAI_NODATA, "no address") \
XX( 12, ECONNREFUSED, "connection refused") \ XX(EAI_NONAME, "unknown node or service") \
XX( 13, ECONNRESET, "connection reset by peer") \ XX(EAI_SERVICE, "service not available for socket type") \
XX( 14, EDESTADDRREQ, "destination address required") \ XX(EAI_SOCKTYPE, "socket type not supported") \
XX( 15, EFAULT, "bad address in system call argument") \ XX(EAI_SYSTEM, "system error") \
XX( 16, EHOSTUNREACH, "host is unreachable") \ XX(EALREADY, "connection already in progress") \
XX( 17, EINTR, "interrupted system call") \ XX(EBADF, "bad file descriptor") \
XX( 18, EINVAL, "invalid argument") \ XX(EBUSY, "resource busy or locked") \
XX( 19, EISCONN, "socket is already connected") \ XX(ECANCELED, "operation canceled") \
XX( 20, EMFILE, "too many open files") \ XX(ECHARSET, "invalid Unicode character") \
XX( 21, EMSGSIZE, "message too long") \ XX(ECONNABORTED, "software caused connection abort") \
XX( 22, ENETDOWN, "network is down") \ XX(ECONNREFUSED, "connection refused") \
XX( 23, ENETUNREACH, "network is unreachable") \ XX(ECONNRESET, "connection reset by peer") \
XX( 24, ENFILE, "file table overflow") \ XX(EDESTADDRREQ, "destination address required") \
XX( 25, ENOBUFS, "no buffer space available") \ XX(EEXIST, "file already exists") \
XX( 26, ENOMEM, "not enough memory") \ XX(EFAULT, "bad address in system call argument") \
XX( 27, ENOTDIR, "not a directory") \ XX(EHOSTUNREACH, "host is unreachable") \
XX( 28, EISDIR, "illegal operation on a directory") \ XX(EINTR, "interrupted system call") \
XX( 29, ENONET, "machine is not on the network") \ XX(EINVAL, "invalid argument") \
XX( 31, ENOTCONN, "socket is not connected") \ XX(EIO, "i/o error") \
XX( 32, ENOTSOCK, "socket operation on non-socket") \ XX(EISCONN, "socket is already connected") \
XX( 33, ENOTSUP, "operation not supported on socket") \ XX(EISDIR, "illegal operation on a directory") \
XX( 34, ENOENT, "no such file or directory") \ XX(ELOOP, "too many symbolic links encountered") \
XX( 35, ENOSYS, "function not implemented") \ XX(EMFILE, "too many open files") \
XX( 36, EPIPE, "broken pipe") \ XX(EMSGSIZE, "message too long") \
XX( 37, EPROTO, "protocol error") \ XX(ENAMETOOLONG, "name too long") \
XX( 38, EPROTONOSUPPORT, "protocol not supported") \ XX(ENETDOWN, "network is down") \
XX( 39, EPROTOTYPE, "protocol wrong type for socket") \ XX(ENETUNREACH, "network is unreachable") \
XX( 40, ETIMEDOUT, "connection timed out") \ XX(ENFILE, "file table overflow") \
XX( 41, ECHARSET, "invalid Unicode character") \ XX(ENOBUFS, "no buffer space available") \
XX( 42, EAIFAMNOSUPPORT, "address family for hostname not supported") \ XX(ENODEV, "no such device") \
XX( 44, EAISERVICE, "servname not supported for ai_socktype") \ XX(ENOENT, "no such file or directory") \
XX( 45, EAISOCKTYPE, "ai_socktype not supported") \ XX(ENOMEM, "not enough memory") \
XX( 46, ESHUTDOWN, "cannot send after transport endpoint shutdown") \ XX(ENONET, "machine is not on the network") \
XX( 47, EEXIST, "file already exists") \ XX(ENOSPC, "no space left on device") \
XX( 48, ESRCH, "no such process") \ XX(ENOSYS, "function not implemented") \
XX( 49, ENAMETOOLONG, "name too long") \ XX(ENOTCONN, "socket is not connected") \
XX( 50, EPERM, "operation not permitted") \ XX(ENOTDIR, "not a directory") \
XX( 51, ELOOP, "too many symbolic links encountered") \ XX(ENOTEMPTY, "directory not empty") \
XX( 52, EXDEV, "cross-device link not permitted") \ XX(ENOTSOCK, "socket operation on non-socket") \
XX( 53, ENOTEMPTY, "directory not empty") \ XX(ENOTSUP, "operation not supported on socket") \
XX( 54, ENOSPC, "no space left on device") \ XX(EPERM, "operation not permitted") \
XX( 55, EIO, "i/o error") \ XX(EPIPE, "broken pipe") \
XX( 56, EROFS, "read-only file system") \ XX(EPROTO, "protocol error") \
XX( 57, ENODEV, "no such device") \ XX(EPROTONOSUPPORT, "protocol not supported") \
XX( 58, ESPIPE, "invalid seek") \ XX(EPROTOTYPE, "protocol wrong type for socket") \
XX( 59, ECANCELED, "operation canceled") \ XX(EROFS, "read-only file system") \
XX(ESHUTDOWN, "cannot send after transport endpoint shutdown") \
XX(ESPIPE, "invalid seek") \
#define UV_ERRNO_GEN(val, name, s) UV_##name = val, XX(ESRCH, "no such process") \
typedef enum { XX(ETIMEDOUT, "connection timed out") \
UV_ERRNO_MAP(UV_ERRNO_GEN) XX(EXDEV, "cross-device link not permitted") \
UV_MAX_ERRORS XX(UNKNOWN, "unknown error") \
} uv_err_code; XX(EOF, "end of file") \
#undef UV_ERRNO_GEN
#define UV_HANDLE_TYPE_MAP(XX) \ #define UV_HANDLE_TYPE_MAP(XX) \
XX(ASYNC, async) \ XX(ASYNC, async) \
@ -162,6 +163,13 @@ typedef enum {
XX(WORK, work) \ XX(WORK, work) \
XX(GETADDRINFO, getaddrinfo) \ XX(GETADDRINFO, getaddrinfo) \
typedef enum {
#define XX(code, _) UV_ ## code = UV__ ## code,
UV_ERRNO_MAP(XX)
#undef XX
UV_ERRNO_MAX = UV__EOF - 1
} uv_errno_t;
typedef enum { typedef enum {
UV_UNKNOWN_HANDLE = 0, UV_UNKNOWN_HANDLE = 0,
#define XX(uc, lc) UV_##uc, #define XX(uc, lc) UV_##uc,
@ -183,7 +191,6 @@ typedef enum {
/* Handle types. */ /* Handle types. */
typedef struct uv_loop_s uv_loop_t; typedef struct uv_loop_s uv_loop_t;
typedef struct uv_err_s uv_err_t;
typedef struct uv_handle_s uv_handle_t; typedef struct uv_handle_s uv_handle_t;
typedef struct uv_stream_s uv_stream_t; typedef struct uv_stream_s uv_stream_t;
typedef struct uv_tcp_s uv_tcp_t; typedef struct uv_tcp_s uv_tcp_t;
@ -339,11 +346,8 @@ UV_EXTERN int uv_backend_timeout(const uv_loop_t*);
typedef uv_buf_t (*uv_alloc_cb)(uv_handle_t* handle, size_t suggested_size); typedef uv_buf_t (*uv_alloc_cb)(uv_handle_t* handle, size_t suggested_size);
/* /*
* `nread` is > 0 if there is data available, 0 if libuv is done reading for now * `nread` is > 0 if there is data available, 0 if libuv is done reading for
* or -1 on error. * now, or < 0 on error.
*
* Error details can be obtained by calling uv_last_error(). UV_EOF indicates
* that the stream has been closed.
* *
* The callee is responsible for closing the stream when an error happens. * The callee is responsible for closing the stream when an error happens.
* Trying to read from the stream again is undefined. * Trying to read from the stream again is undefined.
@ -400,9 +404,12 @@ typedef struct {
uint64_t st_size; uint64_t st_size;
uint64_t st_blksize; uint64_t st_blksize;
uint64_t st_blocks; uint64_t st_blocks;
uint64_t st_flags;
uint64_t st_gen;
uv_timespec_t st_atim; uv_timespec_t st_atim;
uv_timespec_t st_mtim; uv_timespec_t st_mtim;
uv_timespec_t st_ctim; uv_timespec_t st_ctim;
uv_timespec_t st_birthtim;
} uv_stat_t; } uv_stat_t;
@ -429,22 +436,11 @@ typedef enum {
} uv_membership; } uv_membership;
struct uv_err_s {
/* read-only */
uv_err_code code;
/* private */
int sys_errno_;
};
/* /*
* Most functions return boolean: 0 for success and -1 for failure. * Most functions return 0 on success or an error code < 0 on failure.
* On error the user should then call uv_last_error() to determine
* the error code.
*/ */
UV_EXTERN uv_err_t uv_last_error(uv_loop_t*); UV_EXTERN const char* uv_strerror(int err);
UV_EXTERN const char* uv_strerror(uv_err_t err); UV_EXTERN const char* uv_err_name(int err);
UV_EXTERN const char* uv_err_name(uv_err_t err);
#define UV_REQ_FIELDS \ #define UV_REQ_FIELDS \
@ -534,8 +530,7 @@ UV_EXTERN void uv_walk(uv_loop_t* loop, uv_walk_cb walk_cb, void* arg);
* It gives you a chance to free up any resources associated with the handle. * It gives you a chance to free up any resources associated with the handle.
* *
* In-progress requests, like uv_connect_t or uv_write_t, are cancelled and * In-progress requests, like uv_connect_t or uv_write_t, are cancelled and
* have their callbacks called asynchronously with status=-1 and the error code * have their callbacks called asynchronously with status=UV_ECANCELED.
* set to UV_ECANCELED.
*/ */
UV_EXTERN void uv_close(uv_handle_t* handle, uv_close_cb close_cb); UV_EXTERN void uv_close(uv_handle_t* handle, uv_close_cb close_cb);
@ -604,9 +599,11 @@ UV_EXTERN int uv_accept(uv_stream_t* server, uv_stream_t* client);
/* /*
* Read data from an incoming stream. The callback will be made several * 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. * times until there is no more data to read or uv_read_stop is called.
* When we've reached EOF nread will be set to -1 and the error is set * When we've reached EOF nread will be set to UV_EOF.
* to UV_EOF. When nread == -1 the buf parameter might not point to a *
* valid buffer; in that case buf.len and buf.base are both set to 0. * When nread < 0, the buf parameter might not point to a valid buffer;
* in that case buf.len and buf.base are both set to 0.
*
* Note that nread might also be 0, which does *not* indicate an error or * Note that nread might also be 0, which does *not* indicate an error or
* eof; it happens when libuv requested a buffer through the alloc callback * eof; it happens when libuv requested a buffer through the alloc callback
* but then decided that it didn't need that buffer. * but then decided that it didn't need that buffer.
@ -804,7 +801,7 @@ typedef void (*uv_udp_send_cb)(uv_udp_send_t* req, int status);
* nread Number of bytes that have been received. * nread Number of bytes that have been received.
* 0 if there is no more data to read. You may * 0 if there is no more data to read. You may
* discard or repurpose the read buffer. * discard or repurpose the read buffer.
* -1 if a transmission error was detected. * < 0 if a transmission error was detected.
* buf uv_buf_t with the received data. * buf uv_buf_t with the received data.
* addr struct sockaddr_in or struct sockaddr_in6. * addr struct sockaddr_in or struct sockaddr_in6.
* Valid for the duration of the callback only. * Valid for the duration of the callback only.
@ -854,7 +851,7 @@ UV_EXTERN int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock);
* flags Unused. * flags Unused.
* *
* Returns: * Returns:
* 0 on success, -1 on error. * 0 on success, or an error code < 0 on failure.
*/ */
UV_EXTERN int uv_udp_bind(uv_udp_t* handle, struct sockaddr_in addr, UV_EXTERN int uv_udp_bind(uv_udp_t* handle, struct sockaddr_in addr,
unsigned flags); unsigned flags);
@ -868,10 +865,11 @@ UV_EXTERN int uv_udp_bind(uv_udp_t* handle, struct sockaddr_in addr,
* flags Should be 0 or UV_UDP_IPV6ONLY. * flags Should be 0 or UV_UDP_IPV6ONLY.
* *
* Returns: * Returns:
* 0 on success, -1 on error. * 0 on success, or an error code < 0 on failure.
*/ */
UV_EXTERN int uv_udp_bind6(uv_udp_t* handle, struct sockaddr_in6 addr, UV_EXTERN int uv_udp_bind6(uv_udp_t* handle, struct sockaddr_in6 addr,
unsigned flags); unsigned flags);
UV_EXTERN int uv_udp_getsockname(uv_udp_t* handle, struct sockaddr* name, UV_EXTERN int uv_udp_getsockname(uv_udp_t* handle, struct sockaddr* name,
int* namelen); int* namelen);
@ -886,7 +884,7 @@ UV_EXTERN int uv_udp_getsockname(uv_udp_t* handle, struct sockaddr* name,
* membership Should be UV_JOIN_GROUP or UV_LEAVE_GROUP * membership Should be UV_JOIN_GROUP or UV_LEAVE_GROUP
* *
* Returns: * Returns:
* 0 on success, -1 on error. * 0 on success, or an error code < 0 on failure.
*/ */
UV_EXTERN int uv_udp_set_membership(uv_udp_t* handle, UV_EXTERN int uv_udp_set_membership(uv_udp_t* handle,
const char* multicast_addr, const char* interface_addr, const char* multicast_addr, const char* interface_addr,
@ -902,7 +900,7 @@ UV_EXTERN int uv_udp_set_membership(uv_udp_t* handle,
* on 1 for on, 0 for off * on 1 for on, 0 for off
* *
* Returns: * Returns:
* 0 on success, -1 on error. * 0 on success, or an error code < 0 on failure.
*/ */
UV_EXTERN int uv_udp_set_multicast_loop(uv_udp_t* handle, int on); UV_EXTERN int uv_udp_set_multicast_loop(uv_udp_t* handle, int on);
@ -915,7 +913,7 @@ UV_EXTERN int uv_udp_set_multicast_loop(uv_udp_t* handle, int on);
* ttl 1 through 255 * ttl 1 through 255
* *
* Returns: * Returns:
* 0 on success, -1 on error. * 0 on success, or an error code < 0 on failure.
*/ */
UV_EXTERN int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl); UV_EXTERN int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl);
@ -928,7 +926,7 @@ UV_EXTERN int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl);
* on 1 for on, 0 for off * on 1 for on, 0 for off
* *
* Returns: * Returns:
* 0 on success, -1 on error. * 0 on success, or an error code < 0 on failure.
*/ */
UV_EXTERN int uv_udp_set_broadcast(uv_udp_t* handle, int on); UV_EXTERN int uv_udp_set_broadcast(uv_udp_t* handle, int on);
@ -941,7 +939,7 @@ UV_EXTERN int uv_udp_set_broadcast(uv_udp_t* handle, int on);
* ttl 1 through 255 * ttl 1 through 255
* *
* Returns: * Returns:
* 0 on success, -1 on error. * 0 on success, or an error code < 0 on failure.
*/ */
UV_EXTERN int uv_udp_set_ttl(uv_udp_t* handle, int ttl); UV_EXTERN int uv_udp_set_ttl(uv_udp_t* handle, int ttl);
@ -959,7 +957,7 @@ UV_EXTERN int uv_udp_set_ttl(uv_udp_t* handle, int ttl);
* send_cb Callback to invoke when the data has been sent out. * send_cb Callback to invoke when the data has been sent out.
* *
* Returns: * Returns:
* 0 on success, -1 on error. * 0 on success, or an error code < 0 on failure.
*/ */
UV_EXTERN int uv_udp_send(uv_udp_send_t* req, uv_udp_t* handle, UV_EXTERN int uv_udp_send(uv_udp_send_t* req, uv_udp_t* handle,
uv_buf_t bufs[], int bufcnt, struct sockaddr_in addr, uv_buf_t bufs[], int bufcnt, struct sockaddr_in addr,
@ -978,7 +976,7 @@ UV_EXTERN int uv_udp_send(uv_udp_send_t* req, uv_udp_t* handle,
* send_cb Callback to invoke when the data has been sent out. * send_cb Callback to invoke when the data has been sent out.
* *
* Returns: * Returns:
* 0 on success, -1 on error. * 0 on success, or an error code < 0 on failure.
*/ */
UV_EXTERN int uv_udp_send6(uv_udp_send_t* req, uv_udp_t* handle, UV_EXTERN int uv_udp_send6(uv_udp_send_t* req, uv_udp_t* handle,
uv_buf_t bufs[], int bufcnt, struct sockaddr_in6 addr, uv_buf_t bufs[], int bufcnt, struct sockaddr_in6 addr,
@ -995,7 +993,7 @@ UV_EXTERN int uv_udp_send6(uv_udp_send_t* req, uv_udp_t* handle,
* recv_cb Callback to invoke with received data. * recv_cb Callback to invoke with received data.
* *
* Returns: * Returns:
* 0 on success, -1 on error. * 0 on success, or an error code < 0 on failure.
*/ */
UV_EXTERN int uv_udp_recv_start(uv_udp_t* handle, uv_alloc_cb alloc_cb, UV_EXTERN int uv_udp_recv_start(uv_udp_t* handle, uv_alloc_cb alloc_cb,
uv_udp_recv_cb recv_cb); uv_udp_recv_cb recv_cb);
@ -1007,7 +1005,7 @@ UV_EXTERN int uv_udp_recv_start(uv_udp_t* handle, uv_alloc_cb alloc_cb,
* handle UDP handle. Should have been initialized with `uv_udp_init`. * handle UDP handle. Should have been initialized with `uv_udp_init`.
* *
* Returns: * Returns:
* 0 on success, -1 on error. * 0 on success, or an error code < 0 on failure.
*/ */
UV_EXTERN int uv_udp_recv_stop(uv_udp_t* handle); UV_EXTERN int uv_udp_recv_stop(uv_udp_t* handle);
@ -1151,10 +1149,10 @@ UV_EXTERN int uv_poll_init_socket(uv_loop_t* loop, uv_poll_t* handle,
* will be called with `status` set to 0, and the detected events set en the * will be called with `status` set to 0, and the detected events set en the
* `events` field. * `events` field.
* *
* If an error happens while polling status may be set to -1 and the error * If an error happens while polling status, `status` < 0 and corresponds
* code can be retrieved with uv_last_error. The user should not close the * with one of the UV_E* error codes. The user should not close the socket
* socket while uv_poll is active. If the user does that anyway, the callback * while uv_poll is active. If the user does that anyway, the callback *may*
* *may* be called reporting an error status, but this is not guaranteed. * be called reporting an error status, but this is not guaranteed.
* *
* Calling uv_poll_start on an uv_poll watcher that is already active is fine. * Calling uv_poll_start on an uv_poll watcher that is already active is fine.
* Doing so will update the events mask that is being watched for. * Doing so will update the events mask that is being watched for.
@ -1275,8 +1273,8 @@ UV_EXTERN int uv_timer_stop(uv_timer_t* handle);
/* /*
* Stop the timer, and if it is repeating restart it using the repeat value * Stop the timer, and if it is repeating restart it using the repeat value
* as the timeout. If the timer has never been started before it returns -1 and * as the timeout. If the timer has never been started before it returns
* sets the error to UV_EINVAL. * UV_EINVAL.
*/ */
UV_EXTERN int uv_timer_again(uv_timer_t* handle); UV_EXTERN int uv_timer_again(uv_timer_t* handle);
@ -1312,15 +1310,13 @@ struct uv_getaddrinfo_s {
* hints is a pointer to a struct addrinfo with additional address type * hints is a pointer to a struct addrinfo with additional address type
* constraints, or NULL. Consult `man -s 3 getaddrinfo` for details. * constraints, or NULL. Consult `man -s 3 getaddrinfo` for details.
* *
* Returns 0 on success, -1 on error. Call uv_last_error() to get the error. * Returns 0 on success or an error code < 0 on failure.
* *
* If successful, your callback gets called sometime in the future with the * If successful, your callback gets called sometime in the future with the
* lookup result, which is either: * lookup result, which is either:
* *
* a) status == 0, the res argument points to a valid struct addrinfo, or * a) err == 0, the res argument points to a valid struct addrinfo, or
* b) status == -1, the res argument is NULL. * b) err < 0, the res argument is NULL. See the UV_EAI_* constants.
*
* On NXDOMAIN, the status code is -1 and uv_last_error() returns UV_ENOENT.
* *
* Call uv_freeaddrinfo() to free the addrinfo structure. * Call uv_freeaddrinfo() to free the addrinfo structure.
*/ */
@ -1336,6 +1332,7 @@ UV_EXTERN int uv_getaddrinfo(uv_loop_t* loop,
*/ */
UV_EXTERN void uv_freeaddrinfo(struct addrinfo* ai); UV_EXTERN void uv_freeaddrinfo(struct addrinfo* ai);
/* uv_spawn() options */ /* uv_spawn() options */
typedef enum { typedef enum {
UV_IGNORE = 0x00, UV_IGNORE = 0x00,
@ -1466,7 +1463,7 @@ UV_EXTERN int uv_process_kill(uv_process_t*, int signum);
/* Kills the process with the specified signal. */ /* Kills the process with the specified signal. */
UV_EXTERN uv_err_t uv_kill(int pid, int signum); UV_EXTERN int uv_kill(int pid, int signum);
/* /*
@ -1487,7 +1484,7 @@ UV_EXTERN int uv_queue_work(uv_loop_t* loop, uv_work_t* req,
/* Cancel a pending request. Fails if the request is executing or has finished /* Cancel a pending request. Fails if the request is executing or has finished
* executing. * executing.
* *
* Returns 0 on success, -1 on error. The loop error code is not touched. * Returns 0 on success, or an error code < 0 on failure.
* *
* Only cancellation of uv_fs_t, uv_getaddrinfo_t and uv_work_t requests is * Only cancellation of uv_fs_t, uv_getaddrinfo_t and uv_work_t requests is
* currently supported. * currently supported.
@ -1498,13 +1495,13 @@ UV_EXTERN int uv_queue_work(uv_loop_t* loop, uv_work_t* req,
* *
* Here is how cancellation is reported to your callback: * Here is how cancellation is reported to your callback:
* *
* - A uv_fs_t request has its req->errorno field set to UV_ECANCELED. * - A uv_fs_t request has its req->result field set to UV_ECANCELED.
* *
* - A uv_work_t or uv_getaddrinfo_t request has its callback invoked with * - A uv_work_t or uv_getaddrinfo_t request has its callback invoked with
* status == -1 and uv_last_error(loop).code == UV_ECANCELED. * status == UV_ECANCELED.
* *
* This function is currently only implemented on UNIX platforms. On Windows, * This function is currently only implemented on UNIX platforms. On Windows,
* it always returns -1. * it always returns UV_ENOSYS.
*/ */
UV_EXTERN int uv_cancel(uv_req_t* req); UV_EXTERN int uv_cancel(uv_req_t* req);
@ -1535,23 +1532,23 @@ struct uv_interface_address_s {
}; };
UV_EXTERN char** uv_setup_args(int argc, char** argv); UV_EXTERN char** uv_setup_args(int argc, char** argv);
UV_EXTERN uv_err_t uv_get_process_title(char* buffer, size_t size); UV_EXTERN int uv_get_process_title(char* buffer, size_t size);
UV_EXTERN uv_err_t uv_set_process_title(const char* title); UV_EXTERN int uv_set_process_title(const char* title);
UV_EXTERN uv_err_t uv_resident_set_memory(size_t* rss); UV_EXTERN int uv_resident_set_memory(size_t* rss);
UV_EXTERN uv_err_t uv_uptime(double* uptime); UV_EXTERN int uv_uptime(double* uptime);
/* /*
* This allocates cpu_infos array, and sets count. The array * This allocates cpu_infos array, and sets count. The array
* is freed using uv_free_cpu_info(). * is freed using uv_free_cpu_info().
*/ */
UV_EXTERN uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count); UV_EXTERN int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count);
UV_EXTERN void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count); UV_EXTERN void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count);
/* /*
* This allocates addresses array, and sets count. The array * This allocates addresses array, and sets count. The array
* is freed using uv_free_interface_addresses(). * is freed using uv_free_interface_addresses().
*/ */
UV_EXTERN uv_err_t uv_interface_addresses(uv_interface_address_t** addresses, UV_EXTERN int uv_interface_addresses(uv_interface_address_t** addresses,
int* count); int* count);
UV_EXTERN void uv_free_interface_addresses(uv_interface_address_t* addresses, UV_EXTERN void uv_free_interface_addresses(uv_interface_address_t* addresses,
int count); int count);
@ -1609,7 +1606,6 @@ struct uv_fs_s {
ssize_t result; ssize_t result;
void* ptr; void* ptr;
const char* path; const char* path;
uv_err_code errorno;
uv_stat_t statbuf; /* Stores the result of uv_fs_stat and uv_fs_fstat. */ uv_stat_t statbuf; /* Stores the result of uv_fs_stat and uv_fs_fstat. */
UV_FS_PRIVATE_FIELDS UV_FS_PRIVATE_FIELDS
}; };
@ -1731,7 +1727,7 @@ UV_EXTERN int uv_fs_poll_init(uv_loop_t* loop, uv_fs_poll_t* handle);
/* /*
* Check the file at `path` for changes every `interval` milliseconds. * Check the file at `path` for changes every `interval` milliseconds.
* *
* Your callback i invoked with `status == -1` if `path` does not exist * Your callback is invoked with `status < 0` if `path` does not exist
* or is inaccessible. The watcher is *not* stopped but your callback is * or is inaccessible. The watcher is *not* stopped but your callback is
* not called again until something changes (e.g. when the file is created * not called again until something changes (e.g. when the file is created
* or the error reason changes). * or the error reason changes).
@ -1855,19 +1851,19 @@ UV_EXTERN int uv_ip4_name(struct sockaddr_in* src, char* dst, size_t size);
UV_EXTERN int uv_ip6_name(struct sockaddr_in6* src, char* dst, size_t size); UV_EXTERN int uv_ip6_name(struct sockaddr_in6* src, char* dst, size_t size);
/* Cross-platform IPv6-capable implementation of the 'standard' inet_ntop */ /* Cross-platform IPv6-capable implementation of the 'standard' inet_ntop */
/* and inet_pton functions. On success they return UV_OK. If an error */ /* and inet_pton functions. On success they return 0. If an error */
/* the target of the `dst` pointer is unmodified. */ /* the target of the `dst` pointer is unmodified. */
UV_EXTERN uv_err_t uv_inet_ntop(int af, const void* src, char* dst, size_t size); UV_EXTERN int uv_inet_ntop(int af, const void* src, char* dst, size_t size);
UV_EXTERN uv_err_t uv_inet_pton(int af, const char* src, void* dst); UV_EXTERN int uv_inet_pton(int af, const char* src, void* dst);
/* Gets the executable path */ /* Gets the executable path */
UV_EXTERN int uv_exepath(char* buffer, size_t* size); UV_EXTERN int uv_exepath(char* buffer, size_t* size);
/* Gets the current working directory */ /* Gets the current working directory */
UV_EXTERN uv_err_t uv_cwd(char* buffer, size_t size); UV_EXTERN int uv_cwd(char* buffer, size_t size);
/* Changes the current working directory */ /* Changes the current working directory */
UV_EXTERN uv_err_t uv_chdir(const char* dir); UV_EXTERN int uv_chdir(const char* dir);
/* Gets memory info in bytes */ /* Gets memory info in bytes */
UV_EXTERN uint64_t uv_get_free_memory(void); UV_EXTERN uint64_t uv_get_free_memory(void);
@ -1922,7 +1918,7 @@ UV_EXTERN int uv_dlsym(uv_lib_t* lib, const char* name, void** ptr);
UV_EXTERN const char* uv_dlerror(uv_lib_t* lib); UV_EXTERN const char* uv_dlerror(uv_lib_t* lib);
/* /*
* The mutex functions return 0 on success, -1 on error * The mutex functions return 0 on success or an error code < 0
* (unless the return type is void, of course). * (unless the return type is void, of course).
*/ */
UV_EXTERN int uv_mutex_init(uv_mutex_t* handle); UV_EXTERN int uv_mutex_init(uv_mutex_t* handle);
@ -1966,7 +1962,8 @@ UV_EXTERN void uv_cond_broadcast(uv_cond_t* cond);
*/ */
UV_EXTERN void uv_cond_wait(uv_cond_t* cond, uv_mutex_t* mutex); UV_EXTERN void uv_cond_wait(uv_cond_t* cond, uv_mutex_t* mutex);
/* Waits on a condition variable with a timeout in nano seconds. /* Waits on a condition variable with a timeout in nano seconds.
* Returns 0 for success or -1 on timeout, * aborts when other errors happen. * Returns 0 for success or UV_ETIMEDOUT on timeout, It aborts when other
* errors happen.
* *
* Note: * Note:
* 1. callers should be prepared to deal with spurious wakeups. * 1. callers should be prepared to deal with spurious wakeups.
@ -2006,8 +2003,6 @@ union uv_any_req {
struct uv_loop_s { struct uv_loop_s {
/* User data - use this for whatever. */ /* User data - use this for whatever. */
void* data; void* data;
/* The last error */
uv_err_t last_err;
/* Loop reference counting */ /* Loop reference counting */
unsigned int active_handles; unsigned int active_handles;
void* handle_queue[2]; void* handle_queue[2];

18
deps/uv/src/fs-poll.c

@ -69,7 +69,7 @@ int uv_fs_poll_start(uv_fs_poll_t* handle,
ctx = calloc(1, sizeof(*ctx) + len); ctx = calloc(1, sizeof(*ctx) + len);
if (ctx == NULL) if (ctx == NULL)
return uv__set_artificial_error(loop, UV_ENOMEM); return UV_ENOMEM;
ctx->loop = loop; ctx->loop = loop;
ctx->poll_cb = cb; ctx->poll_cb = cb;
@ -150,10 +150,12 @@ static void poll_cb(uv_fs_t* req) {
} }
if (req->result != 0) { if (req->result != 0) {
if (ctx->busy_polling != -req->errorno) { if (ctx->busy_polling != req->result) {
uv__set_artificial_error(ctx->loop, req->errorno); ctx->poll_cb(ctx->parent_handle,
ctx->poll_cb(ctx->parent_handle, -1, &ctx->statbuf, &zero_statbuf); req->result,
ctx->busy_polling = -req->errorno; &ctx->statbuf,
&zero_statbuf);
ctx->busy_polling = req->result;
} }
goto out; goto out;
} }
@ -192,14 +194,18 @@ static void timer_close_cb(uv_handle_t* handle) {
static int statbuf_eq(const uv_stat_t* a, const uv_stat_t* b) { static int statbuf_eq(const uv_stat_t* a, const uv_stat_t* b) {
return a->st_ctim.tv_nsec == b->st_ctim.tv_nsec return a->st_ctim.tv_nsec == b->st_ctim.tv_nsec
&& a->st_mtim.tv_nsec == b->st_mtim.tv_nsec && a->st_mtim.tv_nsec == b->st_mtim.tv_nsec
&& a->st_birthtim.tv_nsec == b->st_birthtim.tv_nsec
&& a->st_ctim.tv_sec == b->st_ctim.tv_sec && a->st_ctim.tv_sec == b->st_ctim.tv_sec
&& a->st_mtim.tv_sec == b->st_mtim.tv_sec && a->st_mtim.tv_sec == b->st_mtim.tv_sec
&& a->st_birthtim.tv_sec == b->st_birthtim.tv_sec
&& a->st_size == b->st_size && a->st_size == b->st_size
&& a->st_mode == b->st_mode && a->st_mode == b->st_mode
&& a->st_uid == b->st_uid && a->st_uid == b->st_uid
&& a->st_gid == b->st_gid && a->st_gid == b->st_gid
&& a->st_ino == b->st_ino && a->st_ino == b->st_ino
&& a->st_dev == b->st_dev; && a->st_dev == b->st_dev
&& a->st_flags == b->st_flags
&& a->st_gen == b->st_gen;
} }

80
deps/uv/src/inet.c

@ -19,7 +19,7 @@
#include <string.h> #include <string.h>
#if defined(_MSC_VER) && _MSC_VER < 1600 #if defined(_MSC_VER) && _MSC_VER < 1600
# include "uv-private/stdint-msvc2008.h" # include "stdint-msvc2008.h"
#else #else
# include <stdint.h> # include <stdint.h>
#endif #endif
@ -28,30 +28,26 @@
#include "uv-common.h" #include "uv-common.h"
static const uv_err_t uv_eafnosupport_ = { UV_EAFNOSUPPORT, 0 }; static int inet_ntop4(const unsigned char *src, char *dst, size_t size);
static const uv_err_t uv_enospc_ = { UV_ENOSPC, 0 }; static int inet_ntop6(const unsigned char *src, char *dst, size_t size);
static const uv_err_t uv_einval_ = { UV_EINVAL, 0 }; static int inet_pton4(const char *src, unsigned char *dst);
static int inet_pton6(const char *src, unsigned char *dst);
static uv_err_t inet_ntop4(const unsigned char *src, char *dst, size_t size);
static uv_err_t inet_ntop6(const unsigned char *src, char *dst, size_t size);
static uv_err_t inet_pton4(const char *src, unsigned char *dst);
static uv_err_t inet_pton6(const char *src, unsigned char *dst);
int uv_inet_ntop(int af, const void* src, char* dst, size_t size) {
uv_err_t uv_inet_ntop(int af, const void* src, char* dst, size_t size) {
switch (af) { switch (af) {
case AF_INET: case AF_INET:
return (inet_ntop4(src, dst, size)); return (inet_ntop4(src, dst, size));
case AF_INET6: case AF_INET6:
return (inet_ntop6(src, dst, size)); return (inet_ntop6(src, dst, size));
default: default:
return uv_eafnosupport_; return UV_EAFNOSUPPORT;
} }
/* NOTREACHED */ /* NOTREACHED */
} }
static uv_err_t inet_ntop4(const unsigned char *src, char *dst, size_t size) { static int inet_ntop4(const unsigned char *src, char *dst, size_t size) {
static const char fmt[] = "%u.%u.%u.%u"; static const char fmt[] = "%u.%u.%u.%u";
char tmp[sizeof "255.255.255.255"]; char tmp[sizeof "255.255.255.255"];
int l; int l;
@ -62,15 +58,15 @@ static uv_err_t inet_ntop4(const unsigned char *src, char *dst, size_t size) {
l = _snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], src[3]); l = _snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], src[3]);
#endif #endif
if (l <= 0 || (size_t) l >= size) { if (l <= 0 || (size_t) l >= size) {
return uv_enospc_; return UV_ENOSPC;
} }
strncpy(dst, tmp, size); strncpy(dst, tmp, size);
dst[size - 1] = '\0'; dst[size - 1] = '\0';
return uv_ok_; return 0;
} }
static uv_err_t inet_ntop6(const unsigned char *src, char *dst, size_t size) { static int inet_ntop6(const unsigned char *src, char *dst, size_t size) {
/* /*
* Note that int32_t and int16_t need only be "at least" large enough * Note that int32_t and int16_t need only be "at least" large enough
* to contain a value of the specified size. On some systems, like * to contain a value of the specified size. On some systems, like
@ -135,8 +131,8 @@ static uv_err_t inet_ntop6(const unsigned char *src, char *dst, size_t size) {
if (i == 6 && best.base == 0 && (best.len == 6 || if (i == 6 && best.base == 0 && (best.len == 6 ||
(best.len == 7 && words[7] != 0x0001) || (best.len == 7 && words[7] != 0x0001) ||
(best.len == 5 && words[5] == 0xffff))) { (best.len == 5 && words[5] == 0xffff))) {
uv_err_t err = inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp)); int err = inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp));
if (err.code != UV_OK) if (err)
return err; return err;
tp += strlen(tp); tp += strlen(tp);
break; break;
@ -152,27 +148,27 @@ static uv_err_t inet_ntop6(const unsigned char *src, char *dst, size_t size) {
* Check for overflow, copy, and we're done. * Check for overflow, copy, and we're done.
*/ */
if ((size_t)(tp - tmp) > size) { if ((size_t)(tp - tmp) > size) {
return uv_enospc_; return UV_ENOSPC;
} }
strcpy(dst, tmp); strcpy(dst, tmp);
return uv_ok_; return 0;
} }
uv_err_t uv_inet_pton(int af, const char* src, void* dst) { int uv_inet_pton(int af, const char* src, void* dst) {
switch (af) { switch (af) {
case AF_INET: case AF_INET:
return (inet_pton4(src, dst)); return (inet_pton4(src, dst));
case AF_INET6: case AF_INET6:
return (inet_pton6(src, dst)); return (inet_pton6(src, dst));
default: default:
return uv_eafnosupport_; return UV_EAFNOSUPPORT;
} }
/* NOTREACHED */ /* NOTREACHED */
} }
static uv_err_t inet_pton4(const char *src, unsigned char *dst) { static int inet_pton4(const char *src, unsigned char *dst) {
static const char digits[] = "0123456789"; static const char digits[] = "0123456789";
int saw_digit, octets, ch; int saw_digit, octets, ch;
unsigned char tmp[sizeof(struct in_addr)], *tp; unsigned char tmp[sizeof(struct in_addr)], *tp;
@ -187,31 +183,31 @@ static uv_err_t inet_pton4(const char *src, unsigned char *dst) {
unsigned int nw = *tp * 10 + (pch - digits); unsigned int nw = *tp * 10 + (pch - digits);
if (saw_digit && *tp == 0) if (saw_digit && *tp == 0)
return uv_einval_; return UV_EINVAL;
if (nw > 255) if (nw > 255)
return uv_einval_; return UV_EINVAL;
*tp = nw; *tp = nw;
if (!saw_digit) { if (!saw_digit) {
if (++octets > 4) if (++octets > 4)
return uv_einval_; return UV_EINVAL;
saw_digit = 1; saw_digit = 1;
} }
} else if (ch == '.' && saw_digit) { } else if (ch == '.' && saw_digit) {
if (octets == 4) if (octets == 4)
return uv_einval_; return UV_EINVAL;
*++tp = 0; *++tp = 0;
saw_digit = 0; saw_digit = 0;
} else } else
return uv_einval_; return UV_EINVAL;
} }
if (octets < 4) if (octets < 4)
return uv_einval_; return UV_EINVAL;
memcpy(dst, tmp, sizeof(struct in_addr)); memcpy(dst, tmp, sizeof(struct in_addr));
return uv_ok_; return 0;
} }
static uv_err_t inet_pton6(const char *src, unsigned char *dst) { static int inet_pton6(const char *src, unsigned char *dst) {
static const char xdigits_l[] = "0123456789abcdef", static const char xdigits_l[] = "0123456789abcdef",
xdigits_u[] = "0123456789ABCDEF"; xdigits_u[] = "0123456789ABCDEF";
unsigned char tmp[sizeof(struct in6_addr)], *tp, *endp, *colonp; unsigned char tmp[sizeof(struct in6_addr)], *tp, *endp, *colonp;
@ -225,7 +221,7 @@ static uv_err_t inet_pton6(const char *src, unsigned char *dst) {
/* Leading :: requires some special handling. */ /* Leading :: requires some special handling. */
if (*src == ':') if (*src == ':')
if (*++src != ':') if (*++src != ':')
return uv_einval_; return UV_EINVAL;
curtok = src; curtok = src;
seen_xdigits = 0; seen_xdigits = 0;
val = 0; val = 0;
@ -238,21 +234,21 @@ static uv_err_t inet_pton6(const char *src, unsigned char *dst) {
val <<= 4; val <<= 4;
val |= (pch - xdigits); val |= (pch - xdigits);
if (++seen_xdigits > 4) if (++seen_xdigits > 4)
return uv_einval_; return UV_EINVAL;
continue; continue;
} }
if (ch == ':') { if (ch == ':') {
curtok = src; curtok = src;
if (!seen_xdigits) { if (!seen_xdigits) {
if (colonp) if (colonp)
return uv_einval_; return UV_EINVAL;
colonp = tp; colonp = tp;
continue; continue;
} else if (*src == '\0') { } else if (*src == '\0') {
return uv_einval_; return UV_EINVAL;
} }
if (tp + sizeof(uint16_t) > endp) if (tp + sizeof(uint16_t) > endp)
return uv_einval_; return UV_EINVAL;
*tp++ = (unsigned char) (val >> 8) & 0xff; *tp++ = (unsigned char) (val >> 8) & 0xff;
*tp++ = (unsigned char) val & 0xff; *tp++ = (unsigned char) val & 0xff;
seen_xdigits = 0; seen_xdigits = 0;
@ -260,18 +256,18 @@ static uv_err_t inet_pton6(const char *src, unsigned char *dst) {
continue; continue;
} }
if (ch == '.' && ((tp + sizeof(struct in_addr)) <= endp)) { if (ch == '.' && ((tp + sizeof(struct in_addr)) <= endp)) {
uv_err_t err = inet_pton4(curtok, tp); int err = inet_pton4(curtok, tp);
if (err.code == 0) { if (err == 0) {
tp += sizeof(struct in_addr); tp += sizeof(struct in_addr);
seen_xdigits = 0; seen_xdigits = 0;
break; /*%< '\\0' was seen by inet_pton4(). */ break; /*%< '\\0' was seen by inet_pton4(). */
} }
} }
return uv_einval_; return UV_EINVAL;
} }
if (seen_xdigits) { if (seen_xdigits) {
if (tp + sizeof(uint16_t) > endp) if (tp + sizeof(uint16_t) > endp)
return uv_einval_; return UV_EINVAL;
*tp++ = (unsigned char) (val >> 8) & 0xff; *tp++ = (unsigned char) (val >> 8) & 0xff;
*tp++ = (unsigned char) val & 0xff; *tp++ = (unsigned char) val & 0xff;
} }
@ -284,7 +280,7 @@ static uv_err_t inet_pton6(const char *src, unsigned char *dst) {
int i; int i;
if (tp == endp) if (tp == endp)
return uv_einval_; return UV_EINVAL;
for (i = 1; i <= n; i++) { for (i = 1; i <= n; i++) {
endp[- i] = colonp[n - i]; endp[- i] = colonp[n - i];
colonp[n - i] = 0; colonp[n - i] = 0;
@ -292,7 +288,7 @@ static uv_err_t inet_pton6(const char *src, unsigned char *dst) {
tp = endp; tp = endp;
} }
if (tp != endp) if (tp != endp)
return uv_einval_; return UV_EINVAL;
memcpy(dst, tmp, sizeof tmp); memcpy(dst, tmp, sizeof tmp);
return uv_ok_; return 0;
} }

60
deps/uv/src/unix/aix.c

@ -134,8 +134,7 @@ int uv_fs_event_init(uv_loop_t* loop,
uv_fs_event_cb cb, uv_fs_event_cb cb,
int flags) { int flags) {
loop->counters.fs_event_init++; loop->counters.fs_event_init++;
uv__set_sys_error(loop, ENOSYS); return -ENOSYS;
return -1;
} }
@ -149,45 +148,44 @@ char** uv_setup_args(int argc, char** argv) {
} }
uv_err_t uv_set_process_title(const char* title) { int uv_set_process_title(const char* title) {
return uv_ok_; return 0;
} }
uv_err_t uv_get_process_title(char* buffer, size_t size) { int uv_get_process_title(char* buffer, size_t size) {
if (size > 0) { if (size > 0) {
buffer[0] = '\0'; buffer[0] = '\0';
} }
return uv_ok_; return 0;
} }
uv_err_t uv_resident_set_memory(size_t* rss) { int uv_resident_set_memory(size_t* rss) {
char pp[64]; char pp[64];
psinfo_t psinfo; psinfo_t psinfo;
uv_err_t err; int err;
int fd; int fd;
(void) snprintf(pp, sizeof(pp), "/proc/%lu/psinfo", (unsigned long) getpid()); (void) snprintf(pp, sizeof(pp), "/proc/%lu/psinfo", (unsigned long) getpid());
fd = open(pp, O_RDONLY); fd = open(pp, O_RDONLY);
if (fd == -1) if (fd == -1)
return uv__new_sys_error(errno); return -errno;
err = uv_ok_; /* FIXME(bnoordhuis) Handle EINTR. */
err = -EINVAL;
if (read(fd, &psinfo, sizeof(psinfo)) == sizeof(psinfo)) if (read(fd, &psinfo, sizeof(psinfo)) == sizeof(psinfo)) {
*rss = (size_t)psinfo.pr_rssize * 1024; *rss = (size_t)psinfo.pr_rssize * 1024;
else err = 0;
err = uv__new_sys_error(EINVAL); }
close(fd); close(fd);
return err; return err;
} }
uv_err_t uv_uptime(double* uptime) { int uv_uptime(double* uptime) {
struct utmp *utmp_buf; struct utmp *utmp_buf;
size_t entries = 0; size_t entries = 0;
time_t boot_time; time_t boot_time;
@ -206,14 +204,14 @@ uv_err_t uv_uptime(double* uptime) {
endutent(); endutent();
if (boot_time == 0) if (boot_time == 0)
return uv__new_artificial_error(UV_ENOSYS); return -ENOSYS;
*uptime = time(NULL) - boot_time; *uptime = time(NULL) - boot_time;
return uv_ok_; return 0;
} }
uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
uv_cpu_info_t* cpu_info; uv_cpu_info_t* cpu_info;
perfstat_cpu_total_t ps_total; perfstat_cpu_total_t ps_total;
perfstat_cpu_t* ps_cpus; perfstat_cpu_t* ps_cpus;
@ -222,30 +220,30 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
result = perfstat_cpu_total(NULL, &ps_total, sizeof(ps_total), 1); result = perfstat_cpu_total(NULL, &ps_total, sizeof(ps_total), 1);
if (result == -1) { if (result == -1) {
return uv__new_artificial_error(UV_ENOSYS); return -ENOSYS;
} }
ncpus = result = perfstat_cpu(NULL, NULL, sizeof(perfstat_cpu_t), 0); ncpus = result = perfstat_cpu(NULL, NULL, sizeof(perfstat_cpu_t), 0);
if (result == -1) { if (result == -1) {
return uv__new_artificial_error(UV_ENOSYS); return -ENOSYS;
} }
ps_cpus = (perfstat_cpu_t*) malloc(ncpus * sizeof(perfstat_cpu_t)); ps_cpus = (perfstat_cpu_t*) malloc(ncpus * sizeof(perfstat_cpu_t));
if (!ps_cpus) { if (!ps_cpus) {
return uv__new_artificial_error(UV_ENOMEM); return -ENOMEM;
} }
strcpy(cpu_id.name, FIRST_CPU); strcpy(cpu_id.name, FIRST_CPU);
result = perfstat_cpu(&cpu_id, ps_cpus, sizeof(perfstat_cpu_t), ncpus); result = perfstat_cpu(&cpu_id, ps_cpus, sizeof(perfstat_cpu_t), ncpus);
if (result == -1) { if (result == -1) {
free(ps_cpus); free(ps_cpus);
return uv__new_artificial_error(UV_ENOSYS); return -ENOSYS;
} }
*cpu_infos = (uv_cpu_info_t*) malloc(ncpus * sizeof(uv_cpu_info_t)); *cpu_infos = (uv_cpu_info_t*) malloc(ncpus * sizeof(uv_cpu_info_t));
if (!*cpu_infos) { if (!*cpu_infos) {
free(ps_cpus); free(ps_cpus);
return uv__new_artificial_error(UV_ENOMEM); return -ENOMEM;
} }
*count = ncpus; *count = ncpus;
@ -264,7 +262,7 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
} }
free(ps_cpus); free(ps_cpus);
return uv_ok_; return 0;
} }
@ -279,7 +277,7 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
} }
uv_err_t uv_interface_addresses(uv_interface_address_t** addresses, int uv_interface_addresses(uv_interface_address_t** addresses,
int* count) { int* count) {
uv_interface_address_t* address; uv_interface_address_t* address;
int sockfd, size = 1; int sockfd, size = 1;
@ -289,19 +287,19 @@ uv_err_t uv_interface_addresses(uv_interface_address_t** addresses,
*count = 0; *count = 0;
if (0 > (sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP))) { if (0 > (sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP))) {
return uv__new_artificial_error(UV_ENOSYS); return -ENOSYS;
} }
if (ioctl(sockfd, SIOCGSIZIFCONF, &size) == -1) { if (ioctl(sockfd, SIOCGSIZIFCONF, &size) == -1) {
close(sockfd); close(sockfd);
return uv__new_artificial_error(UV_ENOSYS); return -ENOSYS;
} }
ifc.ifc_req = (struct ifreq*)malloc(size); ifc.ifc_req = (struct ifreq*)malloc(size);
ifc.ifc_len = size; ifc.ifc_len = size;
if (ioctl(sockfd, SIOCGIFCONF, &ifc) == -1) { if (ioctl(sockfd, SIOCGIFCONF, &ifc) == -1) {
close(sockfd); close(sockfd);
return uv__new_artificial_error(UV_ENOSYS); return -ENOSYS;
} }
#define ADDR_SIZE(p) MAX((p).sa_len, sizeof(p)) #define ADDR_SIZE(p) MAX((p).sa_len, sizeof(p))
@ -334,7 +332,7 @@ uv_err_t uv_interface_addresses(uv_interface_address_t** addresses,
malloc(*count * sizeof(uv_interface_address_t)); malloc(*count * sizeof(uv_interface_address_t));
if (!(*addresses)) { if (!(*addresses)) {
close(sockfd); close(sockfd);
return uv__new_artificial_error(UV_ENOMEM); return -ENOMEM;
} }
address = *addresses; address = *addresses;
@ -377,7 +375,7 @@ uv_err_t uv_interface_addresses(uv_interface_address_t** addresses,
#undef ADDR_SIZE #undef ADDR_SIZE
close(sockfd); close(sockfd);
return uv_ok_; return 0;
} }

24
deps/uv/src/unix/async.c

@ -39,8 +39,11 @@ static int uv__async_eventfd(void);
int uv_async_init(uv_loop_t* loop, uv_async_t* handle, uv_async_cb async_cb) { int uv_async_init(uv_loop_t* loop, uv_async_t* handle, uv_async_cb async_cb) {
if (uv__async_start(loop, &loop->async_watcher, uv__async_event)) int err;
return uv__set_sys_error(loop, errno);
err = uv__async_start(loop, &loop->async_watcher, uv__async_event);
if (err)
return err;
uv__handle_init(loop, (uv_handle_t*)handle, UV_ASYNC); uv__handle_init(loop, (uv_handle_t*)handle, UV_ASYNC);
handle->async_cb = async_cb; handle->async_cb = async_cb;
@ -199,20 +202,21 @@ void uv__async_init(struct uv__async* wa) {
int uv__async_start(uv_loop_t* loop, struct uv__async* wa, uv__async_cb cb) { int uv__async_start(uv_loop_t* loop, struct uv__async* wa, uv__async_cb cb) {
int pipefd[2]; int pipefd[2];
int fd; int err;
if (wa->io_watcher.fd != -1) if (wa->io_watcher.fd != -1)
return 0; return 0;
fd = uv__async_eventfd(); err = uv__async_eventfd();
if (fd >= 0) { if (err >= 0) {
pipefd[0] = fd; pipefd[0] = err;
pipefd[1] = -1; pipefd[1] = -1;
} }
else if (fd != -ENOSYS) else if (err == -ENOSYS)
return -1; err = uv__make_pipe(pipefd, UV__F_NONBLOCK);
else if (uv__make_pipe(pipefd, UV__F_NONBLOCK))
return -1; if (err < 0)
return err;
uv__io_init(&wa->io_watcher, uv__async_io, pipefd[0]); uv__io_init(&wa->io_watcher, uv__async_io, pipefd[0]);
uv__io_start(loop, &wa->io_watcher, UV__POLLIN); uv__io_start(loop, &wa->io_watcher, UV__POLLIN);

105
deps/uv/src/unix/core.c

@ -361,25 +361,28 @@ int uv_is_active(const uv_handle_t* handle) {
/* Open a socket in non-blocking close-on-exec mode, atomically if possible. */ /* Open a socket in non-blocking close-on-exec mode, atomically if possible. */
int uv__socket(int domain, int type, int protocol) { int uv__socket(int domain, int type, int protocol) {
int sockfd; int sockfd;
int err;
#if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC) #if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC)
sockfd = socket(domain, type | SOCK_NONBLOCK | SOCK_CLOEXEC, protocol); sockfd = socket(domain, type | SOCK_NONBLOCK | SOCK_CLOEXEC, protocol);
if (sockfd != -1) if (sockfd != -1)
goto out; return sockfd;
if (errno != EINVAL) if (errno != EINVAL)
goto out; return -errno;
#endif #endif
sockfd = socket(domain, type, protocol); sockfd = socket(domain, type, protocol);
if (sockfd == -1) if (sockfd == -1)
goto out; return -errno;
if (uv__nonblock(sockfd, 1) || uv__cloexec(sockfd, 1)) { err = uv__nonblock(sockfd, 1);
if (err == 0)
err = uv__cloexec(sockfd, 1);
if (err) {
close(sockfd); close(sockfd);
sockfd = -1; return err;
} }
#if defined(SO_NOSIGPIPE) #if defined(SO_NOSIGPIPE)
@ -389,13 +392,13 @@ int uv__socket(int domain, int type, int protocol) {
} }
#endif #endif
out:
return sockfd; return sockfd;
} }
int uv__accept(int sockfd) { int uv__accept(int sockfd) {
int peerfd; int peerfd;
int err;
assert(sockfd >= 0); assert(sockfd >= 0);
@ -410,38 +413,37 @@ int uv__accept(int sockfd) {
NULL, NULL,
NULL, NULL,
UV__SOCK_NONBLOCK|UV__SOCK_CLOEXEC); UV__SOCK_NONBLOCK|UV__SOCK_CLOEXEC);
if (peerfd != -1) if (peerfd != -1)
break; return peerfd;
if (errno == EINTR) if (errno == EINTR)
continue; continue;
if (errno != ENOSYS) if (errno != ENOSYS)
break; return -errno;
no_accept4 = 1; no_accept4 = 1;
skip: skip:
#endif #endif
peerfd = accept(sockfd, NULL, NULL); peerfd = accept(sockfd, NULL, NULL);
if (peerfd == -1) { if (peerfd == -1) {
if (errno == EINTR) if (errno == EINTR)
continue; continue;
else return -errno;
break;
} }
if (uv__cloexec(peerfd, 1) || uv__nonblock(peerfd, 1)) { err = uv__cloexec(peerfd, 1);
if (err == 0)
err = uv__nonblock(peerfd, 1);
if (err) {
close(peerfd); close(peerfd);
peerfd = -1; return err;
} }
break; return peerfd;
} }
return peerfd;
} }
@ -454,7 +456,10 @@ int uv__nonblock(int fd, int set) {
r = ioctl(fd, FIONBIO, &set); r = ioctl(fd, FIONBIO, &set);
while (r == -1 && errno == EINTR); while (r == -1 && errno == EINTR);
return r; if (r)
return -errno;
return 0;
} }
@ -465,7 +470,10 @@ int uv__cloexec(int fd, int set) {
r = ioctl(fd, set ? FIOCLEX : FIONCLEX); r = ioctl(fd, set ? FIOCLEX : FIONCLEX);
while (r == -1 && errno == EINTR); while (r == -1 && errno == EINTR);
return r; if (r)
return -errno;
return 0;
} }
#else /* !(defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)) */ #else /* !(defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)) */
@ -479,7 +487,7 @@ int uv__nonblock(int fd, int set) {
while (r == -1 && errno == EINTR); while (r == -1 && errno == EINTR);
if (r == -1) if (r == -1)
return -1; return -errno;
/* Bail out now if already set/clear. */ /* Bail out now if already set/clear. */
if (!!(r & O_NONBLOCK) == !!set) if (!!(r & O_NONBLOCK) == !!set)
@ -494,7 +502,10 @@ int uv__nonblock(int fd, int set) {
r = fcntl(fd, F_SETFL, flags); r = fcntl(fd, F_SETFL, flags);
while (r == -1 && errno == EINTR); while (r == -1 && errno == EINTR);
return r; if (r)
return -errno;
return 0;
} }
@ -507,7 +518,7 @@ int uv__cloexec(int fd, int set) {
while (r == -1 && errno == EINTR); while (r == -1 && errno == EINTR);
if (r == -1) if (r == -1)
return -1; return -errno;
/* Bail out now if already set/clear. */ /* Bail out now if already set/clear. */
if (!!(r & FD_CLOEXEC) == !!set) if (!!(r & FD_CLOEXEC) == !!set)
@ -522,7 +533,10 @@ int uv__cloexec(int fd, int set) {
r = fcntl(fd, F_SETFD, flags); r = fcntl(fd, F_SETFD, flags);
while (r == -1 && errno == EINTR); while (r == -1 && errno == EINTR);
return r; if (r)
return -errno;
return 0;
} }
#endif /* defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) */ #endif /* defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) */
@ -532,39 +546,42 @@ int uv__cloexec(int fd, int set) {
* between the call to dup() and fcntl(FD_CLOEXEC). * between the call to dup() and fcntl(FD_CLOEXEC).
*/ */
int uv__dup(int fd) { int uv__dup(int fd) {
int err;
fd = dup(fd); fd = dup(fd);
if (fd == -1) if (fd == -1)
return -1; return -errno;
if (uv__cloexec(fd, 1)) { err = uv__cloexec(fd, 1);
SAVE_ERRNO(close(fd)); if (err) {
return -1; close(fd);
return err;
} }
return fd; return fd;
} }
uv_err_t uv_cwd(char* buffer, size_t size) { int uv_cwd(char* buffer, size_t size) {
if (!buffer || !size) { if (buffer == NULL)
return uv__new_artificial_error(UV_EINVAL); return -EINVAL;
}
if (getcwd(buffer, size)) { if (size == 0)
return uv_ok_; return -EINVAL;
} else {
return uv__new_sys_error(errno); if (getcwd(buffer, size) == NULL)
} return -errno;
return 0;
} }
uv_err_t uv_chdir(const char* dir) { int uv_chdir(const char* dir) {
if (chdir(dir) == 0) { if (chdir(dir))
return uv_ok_; return -errno;
} else {
return uv__new_sys_error(errno); return 0;
}
} }

14
deps/uv/src/unix/darwin-proctitle.c

@ -28,7 +28,7 @@
int uv__set_process_title(const char* title) { int uv__set_process_title(const char* title) {
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
return -1; return -ENOSYS;
#else #else
typedef CFTypeRef (*LSGetCurrentApplicationASNType)(void); typedef CFTypeRef (*LSGetCurrentApplicationASNType)(void);
typedef OSStatus (*LSSetApplicationInformationItemType)(int, typedef OSStatus (*LSSetApplicationInformationItemType)(int,
@ -49,27 +49,27 @@ int uv__set_process_title(const char* title) {
CFBundleGetBundleWithIdentifier(CFSTR("com.apple.LaunchServices")); CFBundleGetBundleWithIdentifier(CFSTR("com.apple.LaunchServices"));
if (launch_services_bundle == NULL) if (launch_services_bundle == NULL)
return -1; return -ENOENT;
ls_get_current_application_asn = (LSGetCurrentApplicationASNType) ls_get_current_application_asn = (LSGetCurrentApplicationASNType)
CFBundleGetFunctionPointerForName(launch_services_bundle, CFBundleGetFunctionPointerForName(launch_services_bundle,
CFSTR("_LSGetCurrentApplicationASN")); CFSTR("_LSGetCurrentApplicationASN"));
if (ls_get_current_application_asn == NULL) if (ls_get_current_application_asn == NULL)
return -1; return -ENOENT;
ls_set_application_information_item = (LSSetApplicationInformationItemType) ls_set_application_information_item = (LSSetApplicationInformationItemType)
CFBundleGetFunctionPointerForName(launch_services_bundle, CFBundleGetFunctionPointerForName(launch_services_bundle,
CFSTR("_LSSetApplicationInformationItem")); CFSTR("_LSSetApplicationInformationItem"));
if (ls_set_application_information_item == NULL) if (ls_set_application_information_item == NULL)
return -1; return -ENOENT;
display_name_key = CFBundleGetDataPointerForName(launch_services_bundle, display_name_key = CFBundleGetDataPointerForName(launch_services_bundle,
CFSTR("_kLSDisplayNameKey")); CFSTR("_kLSDisplayNameKey"));
if (display_name_key == NULL || *display_name_key == NULL) if (display_name_key == NULL || *display_name_key == NULL)
return -1; return -ENOENT;
/* Force the process manager to initialize. */ /* Force the process manager to initialize. */
GetCurrentProcess(&psn); GetCurrentProcess(&psn);
@ -81,7 +81,9 @@ int uv__set_process_title(const char* title) {
*display_name_key, *display_name_key,
display_name, display_name,
NULL); NULL);
if (err != noErr)
return -ENOENT;
return (err == noErr) ? 0 : -1; return 0;
#endif /* !TARGET_OS_IPHONE */ #endif /* !TARGET_OS_IPHONE */
} }

81
deps/uv/src/unix/darwin.c

@ -54,7 +54,7 @@ int uv__platform_loop_init(uv_loop_t* loop, int default_loop) {
int r; int r;
if (uv__kqueue_init(loop)) if (uv__kqueue_init(loop))
return -1; return -errno;
loop->cf_loop = NULL; loop->cf_loop = NULL;
if ((r = uv_mutex_init(&loop->cf_mutex))) if ((r = uv_mutex_init(&loop->cf_mutex)))
@ -194,9 +194,8 @@ int uv_exepath(char* buffer, size_t* size) {
char* path; char* path;
char* fullpath; char* fullpath;
if (!buffer || !size) { if (buffer == NULL || size == NULL)
return -1; return -EINVAL;
}
usize = *size; usize = *size;
result = _NSGetExecutablePath(buffer, &usize); result = _NSGetExecutablePath(buffer, &usize);
@ -204,10 +203,9 @@ int uv_exepath(char* buffer, size_t* size) {
path = (char*)malloc(2 * PATH_MAX); path = (char*)malloc(2 * PATH_MAX);
fullpath = realpath(buffer, path); fullpath = realpath(buffer, path);
if (fullpath == NULL) { if (fullpath == NULL) {
free(path); SAVE_ERRNO(free(path));
return -1; return -errno;
} }
strncpy(buffer, fullpath, *size); strncpy(buffer, fullpath, *size);
@ -223,7 +221,7 @@ uint64_t uv_get_free_memory(void) {
if (host_statistics(mach_host_self(), HOST_VM_INFO, if (host_statistics(mach_host_self(), HOST_VM_INFO,
(host_info_t)&info, &count) != KERN_SUCCESS) { (host_info_t)&info, &count) != KERN_SUCCESS) {
return -1; return -EINVAL; /* FIXME(bnoordhuis) Translate error. */
} }
return (uint64_t) info.free_count * sysconf(_SC_PAGESIZE); return (uint64_t) info.free_count * sysconf(_SC_PAGESIZE);
@ -235,9 +233,8 @@ uint64_t uv_get_total_memory(void) {
int which[] = {CTL_HW, HW_MEMSIZE}; int which[] = {CTL_HW, HW_MEMSIZE};
size_t size = sizeof(info); size_t size = sizeof(info);
if (sysctl(which, 2, &info, &size, NULL, 0) < 0) { if (sysctl(which, 2, &info, &size, NULL, 0))
return -1; return -errno;
}
return (uint64_t) info; return (uint64_t) info;
} }
@ -256,7 +253,7 @@ void uv_loadavg(double avg[3]) {
} }
uv_err_t uv_resident_set_memory(size_t* rss) { int uv_resident_set_memory(size_t* rss) {
mach_msg_type_number_t count; mach_msg_type_number_t count;
task_basic_info_data_t info; task_basic_info_data_t info;
kern_return_t err; kern_return_t err;
@ -273,27 +270,26 @@ uv_err_t uv_resident_set_memory(size_t* rss) {
assert(err == KERN_SUCCESS); assert(err == KERN_SUCCESS);
*rss = info.resident_size; *rss = info.resident_size;
return uv_ok_; return 0;
} }
uv_err_t uv_uptime(double* uptime) { int uv_uptime(double* uptime) {
time_t now; time_t now;
struct timeval info; struct timeval info;
size_t size = sizeof(info); size_t size = sizeof(info);
static int which[] = {CTL_KERN, KERN_BOOTTIME}; static int which[] = {CTL_KERN, KERN_BOOTTIME};
if (sysctl(which, 2, &info, &size, NULL, 0) < 0) { if (sysctl(which, 2, &info, &size, NULL, 0))
return uv__new_sys_error(errno); return -errno;
}
now = time(NULL);
*uptime = (double)(now - info.tv_sec); now = time(NULL);
*uptime = now - info.tv_sec;
return uv_ok_; return 0;
} }
uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
unsigned int ticks = (unsigned int)sysconf(_SC_CLK_TCK), unsigned int ticks = (unsigned int)sysconf(_SC_CLK_TCK),
multiplier = ((uint64_t)1000L / ticks); multiplier = ((uint64_t)1000L / ticks);
char model[512]; char model[512];
@ -306,25 +302,24 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
uv_cpu_info_t* cpu_info; uv_cpu_info_t* cpu_info;
size = sizeof(model); size = sizeof(model);
if (sysctlbyname("machdep.cpu.brand_string", &model, &size, NULL, 0) < 0 && if (sysctlbyname("machdep.cpu.brand_string", &model, &size, NULL, 0) &&
sysctlbyname("hw.model", &model, &size, NULL, 0) < 0) { sysctlbyname("hw.model", &model, &size, NULL, 0)) {
return uv__new_sys_error(errno); return -errno;
} }
size = sizeof(cpuspeed); size = sizeof(cpuspeed);
if (sysctlbyname("hw.cpufrequency", &cpuspeed, &size, NULL, 0) < 0) { if (sysctlbyname("hw.cpufrequency", &cpuspeed, &size, NULL, 0))
return uv__new_sys_error(errno); return -errno;
}
if (host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &numcpus, if (host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &numcpus,
(processor_info_array_t*)&info, (processor_info_array_t*)&info,
&msg_type) != KERN_SUCCESS) { &msg_type) != KERN_SUCCESS) {
return uv__new_sys_error(errno); return -EINVAL; /* FIXME(bnoordhuis) Translate error. */
} }
*cpu_infos = (uv_cpu_info_t*)malloc(numcpus * sizeof(uv_cpu_info_t)); *cpu_infos = malloc(numcpus * sizeof(**cpu_infos));
if (!(*cpu_infos)) { if (!(*cpu_infos))
return uv__new_artificial_error(UV_ENOMEM); return -ENOMEM; /* FIXME(bnoordhuis) Deallocate info? */
}
*count = numcpus; *count = numcpus;
@ -342,7 +337,7 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
} }
vm_deallocate(mach_task_self(), (vm_address_t)info, msg_type); vm_deallocate(mach_task_self(), (vm_address_t)info, msg_type);
return uv_ok_; return 0;
} }
@ -357,15 +352,12 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
} }
uv_err_t uv_interface_addresses(uv_interface_address_t** addresses, int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
int* count) {
struct ifaddrs *addrs, *ent; struct ifaddrs *addrs, *ent;
char ip[INET6_ADDRSTRLEN];
uv_interface_address_t* address; uv_interface_address_t* address;
if (getifaddrs(&addrs) != 0) { if (getifaddrs(&addrs))
return uv__new_sys_error(errno); return -errno;
}
*count = 0; *count = 0;
@ -380,16 +372,13 @@ uv_err_t uv_interface_addresses(uv_interface_address_t** addresses,
(*count)++; (*count)++;
} }
*addresses = (uv_interface_address_t*) *addresses = malloc(*count * sizeof(**addresses));
malloc(*count * sizeof(uv_interface_address_t)); if (!(*addresses))
if (!(*addresses)) { return -ENOMEM;
return uv__new_artificial_error(UV_ENOMEM);
}
address = *addresses; address = *addresses;
for (ent = addrs; ent != NULL; ent = ent->ifa_next) { for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
bzero(&ip, sizeof (ip));
if (!(ent->ifa_flags & IFF_UP && ent->ifa_flags & IFF_RUNNING)) { if (!(ent->ifa_flags & IFF_UP && ent->ifa_flags & IFF_RUNNING)) {
continue; continue;
} }
@ -427,7 +416,7 @@ uv_err_t uv_interface_addresses(uv_interface_address_t** addresses,
freeifaddrs(addrs); freeifaddrs(addrs);
return uv_ok_; return 0;
} }

88
deps/uv/src/unix/error.c

@ -1,88 +0,0 @@
/* 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.
*/
/*
* TODO Share this code with Windows.
* See https://github.com/joyent/libuv/issues/76
*/
#include "uv.h"
#include "internal.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
uv_err_code uv_translate_sys_error(int sys_errno) {
switch (sys_errno) {
case 0: return UV_OK;
case EIO: return UV_EIO;
case EPERM: return UV_EPERM;
case ENOSYS: return UV_ENOSYS;
case ENOTSOCK: return UV_ENOTSOCK;
case ENOENT: return UV_ENOENT;
case EACCES: return UV_EACCES;
case EAFNOSUPPORT: return UV_EAFNOSUPPORT;
case EBADF: return UV_EBADF;
case EPIPE: return UV_EPIPE;
case ESPIPE: return UV_ESPIPE;
case EAGAIN: return UV_EAGAIN;
#if EWOULDBLOCK != EAGAIN
case EWOULDBLOCK: return UV_EAGAIN;
#endif
case ECONNRESET: return UV_ECONNRESET;
case EFAULT: return UV_EFAULT;
case EMFILE: return UV_EMFILE;
case EMSGSIZE: return UV_EMSGSIZE;
case ENAMETOOLONG: return UV_ENAMETOOLONG;
case EINVAL: return UV_EINVAL;
case ENETDOWN: return UV_ENETDOWN;
case ENETUNREACH: return UV_ENETUNREACH;
case ECONNABORTED: return UV_ECONNABORTED;
case ELOOP: return UV_ELOOP;
case ECONNREFUSED: return UV_ECONNREFUSED;
case EADDRINUSE: return UV_EADDRINUSE;
case EADDRNOTAVAIL: return UV_EADDRNOTAVAIL;
case ENOTDIR: return UV_ENOTDIR;
case EISDIR: return UV_EISDIR;
case ENODEV: return UV_ENODEV;
case ENOTCONN: return UV_ENOTCONN;
case EEXIST: return UV_EEXIST;
case EHOSTUNREACH: return UV_EHOSTUNREACH;
case EAI_NONAME: return UV_ENOENT;
case ESRCH: return UV_ESRCH;
case ETIMEDOUT: return UV_ETIMEDOUT;
case EXDEV: return UV_EXDEV;
case EBUSY: return UV_EBUSY;
#if ENOTEMPTY != EEXIST
case ENOTEMPTY: return UV_ENOTEMPTY;
#endif
case ENOSPC: return UV_ENOSPC;
case EROFS: return UV_EROFS;
case ENOMEM: return UV_ENOMEM;
case EDQUOT: return UV_ENOSPC;
default: return UV_UNKNOWN;
}
UNREACHABLE();
}

95
deps/uv/src/unix/freebsd.c

@ -74,9 +74,8 @@ int uv_exepath(char* buffer, size_t* size) {
int mib[4]; int mib[4];
size_t cb; size_t cb;
if (!buffer || !size) { if (buffer == NULL || size == NULL)
return -1; return -EINVAL;
}
#ifdef __DragonFly__ #ifdef __DragonFly__
mib[0] = CTL_KERN; mib[0] = CTL_KERN;
@ -91,10 +90,8 @@ int uv_exepath(char* buffer, size_t* size) {
#endif #endif
cb = *size; cb = *size;
if (sysctl(mib, 4, buffer, &cb, NULL, 0) < 0) { if (sysctl(mib, 4, buffer, &cb, NULL, 0))
*size = 0; return -errno;
return -1;
}
*size = strlen(buffer); *size = strlen(buffer);
return 0; return 0;
@ -105,10 +102,9 @@ uint64_t uv_get_free_memory(void) {
int freecount; int freecount;
size_t size = sizeof(freecount); size_t size = sizeof(freecount);
if(sysctlbyname("vm.stats.vm.v_free_count", if (sysctlbyname("vm.stats.vm.v_free_count", &freecount, &size, NULL, 0))
&freecount, &size, NULL, 0) == -1){ return -errno;
return -1;
}
return (uint64_t) freecount * sysconf(_SC_PAGESIZE); return (uint64_t) freecount * sysconf(_SC_PAGESIZE);
} }
@ -120,9 +116,8 @@ uint64_t uv_get_total_memory(void) {
size_t size = sizeof(info); size_t size = sizeof(info);
if (sysctl(which, 2, &info, &size, NULL, 0) < 0) { if (sysctl(which, 2, &info, &size, NULL, 0))
return -1; return -errno;
}
return (uint64_t) info; return (uint64_t) info;
} }
@ -147,7 +142,7 @@ char** uv_setup_args(int argc, char** argv) {
} }
uv_err_t uv_set_process_title(const char* title) { int uv_set_process_title(const char* title) {
int oid[4]; int oid[4];
if (process_title) free(process_title); if (process_title) free(process_title);
@ -165,11 +160,11 @@ uv_err_t uv_set_process_title(const char* title) {
process_title, process_title,
strlen(process_title) + 1); strlen(process_title) + 1);
return uv_ok_; return 0;
} }
uv_err_t uv_get_process_title(char* buffer, size_t size) { int uv_get_process_title(char* buffer, size_t size) {
if (process_title) { if (process_title) {
strncpy(buffer, process_title, size); strncpy(buffer, process_title, size);
} else { } else {
@ -178,11 +173,11 @@ uv_err_t uv_get_process_title(char* buffer, size_t size) {
} }
} }
return uv_ok_; return 0;
} }
uv_err_t uv_resident_set_memory(size_t* rss) { int uv_resident_set_memory(size_t* rss) {
kvm_t *kd = NULL; kvm_t *kd = NULL;
struct kinfo_proc *kinfo = NULL; struct kinfo_proc *kinfo = NULL;
pid_t pid; pid_t pid;
@ -205,32 +200,31 @@ uv_err_t uv_resident_set_memory(size_t* rss) {
kvm_close(kd); kvm_close(kd);
return uv_ok_; return 0;
error: error:
if (kd) kvm_close(kd); if (kd) kvm_close(kd);
return uv__new_sys_error(errno); return -EPERM;
} }
uv_err_t uv_uptime(double* uptime) { int uv_uptime(double* uptime) {
time_t now; time_t now;
struct timeval info; struct timeval info;
size_t size = sizeof(info); size_t size = sizeof(info);
static int which[] = {CTL_KERN, KERN_BOOTTIME}; static int which[] = {CTL_KERN, KERN_BOOTTIME};
if (sysctl(which, 2, &info, &size, NULL, 0) < 0) { if (sysctl(which, 2, &info, &size, NULL, 0))
return uv__new_sys_error(errno); return -errno;
}
now = time(NULL); now = time(NULL);
*uptime = (double)(now - info.tv_sec); *uptime = (double)(now - info.tv_sec);
return uv_ok_; return 0;
} }
uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
unsigned int ticks = (unsigned int)sysconf(_SC_CLK_TCK), unsigned int ticks = (unsigned int)sysconf(_SC_CLK_TCK),
multiplier = ((uint64_t)1000L / ticks), cpuspeed, maxcpus, multiplier = ((uint64_t)1000L / ticks), cpuspeed, maxcpus,
cur = 0; cur = 0;
@ -256,32 +250,30 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
#endif #endif
size = sizeof(model); size = sizeof(model);
if (sysctlbyname("hw.model", &model, &size, NULL, 0) < 0) { if (sysctlbyname("hw.model", &model, &size, NULL, 0))
return uv__new_sys_error(errno); return -errno;
}
size = sizeof(numcpus); size = sizeof(numcpus);
if (sysctlbyname("hw.ncpu", &numcpus, &size, NULL, 0) < 0) { if (sysctlbyname("hw.ncpu", &numcpus, &size, NULL, 0))
return uv__new_sys_error(errno); return -errno;
}
*cpu_infos = (uv_cpu_info_t*)malloc(numcpus * sizeof(uv_cpu_info_t)); *cpu_infos = malloc(numcpus * sizeof(**cpu_infos));
if (!(*cpu_infos)) { if (!(*cpu_infos))
return uv__new_artificial_error(UV_ENOMEM); return -ENOMEM;
}
*count = numcpus; *count = numcpus;
size = sizeof(cpuspeed); size = sizeof(cpuspeed);
if (sysctlbyname("hw.clockrate", &cpuspeed, &size, NULL, 0) < 0) { if (sysctlbyname("hw.clockrate", &cpuspeed, &size, NULL, 0)) {
free(*cpu_infos); SAVE_ERRNO(free(*cpu_infos));
return uv__new_sys_error(errno); return -errno;
} }
/* kern.cp_times on FreeBSD i386 gives an array up to maxcpus instead of ncpu */ /* kern.cp_times on FreeBSD i386 gives an array up to maxcpus instead of ncpu */
size = sizeof(maxcpus); size = sizeof(maxcpus);
if (sysctlbyname(maxcpus_key, &maxcpus, &size, NULL, 0) < 0) { if (sysctlbyname(maxcpus_key, &maxcpus, &size, NULL, 0)) {
free(*cpu_infos); SAVE_ERRNO(free(*cpu_infos));
return uv__new_sys_error(errno); return -errno;
} }
size = maxcpus * CPUSTATES * sizeof(long); size = maxcpus * CPUSTATES * sizeof(long);
@ -289,13 +281,13 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
cp_times = malloc(size); cp_times = malloc(size);
if (cp_times == NULL) { if (cp_times == NULL) {
free(*cpu_infos); free(*cpu_infos);
return uv__new_sys_error(ENOMEM); return -ENOMEM;
} }
if (sysctlbyname(cptimes_key, cp_times, &size, NULL, 0) < 0) { if (sysctlbyname(cptimes_key, cp_times, &size, NULL, 0)) {
free(cp_times); SAVE_ERRNO(free(cp_times));
free(*cpu_infos); SAVE_ERRNO(free(*cpu_infos));
return uv__new_sys_error(errno); return -errno;
} }
for (i = 0; i < numcpus; i++) { for (i = 0; i < numcpus; i++) {
@ -314,7 +306,7 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
} }
free(cp_times); free(cp_times);
return uv_ok_; return 0;
} }
@ -329,12 +321,11 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
} }
uv_err_t uv_interface_addresses(uv_interface_address_t** addresses, int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
int* count) {
/* TODO: implement */ /* TODO: implement */
*addresses = NULL; *addresses = NULL;
*count = 0; *count = 0;
return uv_ok_; return 0;
} }

61
deps/uv/src/unix/fs.c

@ -19,6 +19,13 @@
* IN THE SOFTWARE. * IN THE SOFTWARE.
*/ */
/* Caveat emptor: this file deviates from the libuv convention of returning
* negated errno codes. Most uv_fs_*() functions map directly to the system
* call of the same name. For more complex wrappers, it's easier to just
* return -1 with errno set. The dispatcher in uv__fs_work() takes care of
* getting the errno to the right place (req->result or as the return value.)
*/
#include "uv.h" #include "uv.h"
#include "internal.h" #include "internal.h"
@ -48,7 +55,6 @@
do { \ do { \
uv__req_init((loop), (req), UV_FS); \ uv__req_init((loop), (req), UV_FS); \
(req)->fs_type = UV_FS_ ## type; \ (req)->fs_type = UV_FS_ ## type; \
(req)->errorno = 0; \
(req)->result = 0; \ (req)->result = 0; \
(req)->ptr = NULL; \ (req)->ptr = NULL; \
(req)->loop = loop; \ (req)->loop = loop; \
@ -60,8 +66,9 @@
#define PATH \ #define PATH \
do { \ do { \
if (NULL == ((req)->path = strdup((path)))) \ (req)->path = strdup(path); \
return uv__set_sys_error((loop), ENOMEM); \ if ((req)->path == NULL) \
return -ENOMEM; \
} \ } \
while (0) while (0)
@ -69,13 +76,11 @@
do { \ do { \
size_t path_len; \ size_t path_len; \
size_t new_path_len; \ size_t new_path_len; \
\
path_len = strlen((path)) + 1; \ path_len = strlen((path)) + 1; \
new_path_len = strlen((new_path)) + 1; \ new_path_len = strlen((new_path)) + 1; \
\ (req)->path = malloc(path_len + new_path_len); \
if (NULL == ((req)->path = malloc(path_len + new_path_len))) \ if ((req)->path == NULL) \
return uv__set_sys_error((loop), ENOMEM); \ return -ENOMEM; \
\
(req)->new_path = (req)->path + path_len; \ (req)->new_path = (req)->path + path_len; \
memcpy((void*) (req)->path, (path), path_len); \ memcpy((void*) (req)->path, (path), path_len); \
memcpy((void*) (req)->new_path, (new_path), new_path_len); \ memcpy((void*) (req)->new_path, (new_path), new_path_len); \
@ -519,6 +524,10 @@ static void uv__to_stat(struct stat* src, uv_stat_t* dst) {
dst->st_mtim.tv_nsec = src->st_mtimespec.tv_nsec; dst->st_mtim.tv_nsec = src->st_mtimespec.tv_nsec;
dst->st_ctim.tv_sec = src->st_ctimespec.tv_sec; dst->st_ctim.tv_sec = src->st_ctimespec.tv_sec;
dst->st_ctim.tv_nsec = src->st_ctimespec.tv_nsec; dst->st_ctim.tv_nsec = src->st_ctimespec.tv_nsec;
dst->st_birthtim.tv_sec = src->st_birthtimespec.tv_sec;
dst->st_birthtim.tv_nsec = src->st_birthtimespec.tv_nsec;
dst->st_flags = src->st_flags;
dst->st_gen = src->st_gen;
#elif defined(_BSD_SOURCE) || defined(_SVID_SOURCE) || defined(_XOPEN_SOURCE) #elif defined(_BSD_SOURCE) || defined(_SVID_SOURCE) || defined(_XOPEN_SOURCE)
dst->st_atim.tv_sec = src->st_atim.tv_sec; dst->st_atim.tv_sec = src->st_atim.tv_sec;
dst->st_atim.tv_nsec = src->st_atim.tv_nsec; dst->st_atim.tv_nsec = src->st_atim.tv_nsec;
@ -526,6 +535,20 @@ static void uv__to_stat(struct stat* src, uv_stat_t* dst) {
dst->st_mtim.tv_nsec = src->st_mtim.tv_nsec; dst->st_mtim.tv_nsec = src->st_mtim.tv_nsec;
dst->st_ctim.tv_sec = src->st_ctim.tv_sec; dst->st_ctim.tv_sec = src->st_ctim.tv_sec;
dst->st_ctim.tv_nsec = src->st_ctim.tv_nsec; dst->st_ctim.tv_nsec = src->st_ctim.tv_nsec;
# if defined(__DragonFly__) || \
defined(__FreeBSD__) || \
defined(__OpenBSD__) || \
defined(__NetBSD__)
dst->st_birthtim.tv_sec = src->st_birthtim.tv_sec;
dst->st_birthtim.tv_nsec = src->st_birthtim.tv_nsec;
dst->st_flags = src->st_flags;
dst->st_gen = src->st_gen;
# else
dst->st_birthtim.tv_sec = src->st_ctim.tv_sec;
dst->st_birthtim.tv_nsec = src->st_ctim.tv_nsec;
dst->st_flags = 0;
dst->st_gen = 0;
# endif
#else #else
dst->st_atim.tv_sec = src->st_atime; dst->st_atim.tv_sec = src->st_atime;
dst->st_atim.tv_nsec = 0; dst->st_atim.tv_nsec = 0;
@ -533,6 +556,10 @@ static void uv__to_stat(struct stat* src, uv_stat_t* dst) {
dst->st_mtim.tv_nsec = 0; dst->st_mtim.tv_nsec = 0;
dst->st_ctim.tv_sec = src->st_ctime; dst->st_ctim.tv_sec = src->st_ctime;
dst->st_ctim.tv_nsec = 0; dst->st_ctim.tv_nsec = 0;
dst->st_birthtim.tv_sec = src->st_ctime;
dst->st_birthtim.tv_nsec = 0;
dst->st_flags = 0;
dst->st_gen = 0;
#endif #endif
} }
@ -613,8 +640,10 @@ static void uv__fs_work(struct uv__work* w) {
} }
while (r == -1 && errno == EINTR && retry_on_eintr); while (r == -1 && errno == EINTR && retry_on_eintr);
req->errorno = errno; if (r == -1)
req->result = r; req->result = -errno;
else
req->result = r;
if (r == 0 && (req->fs_type == UV_FS_STAT || if (r == 0 && (req->fs_type == UV_FS_STAT ||
req->fs_type == UV_FS_FSTAT || req->fs_type == UV_FS_FSTAT ||
@ -630,15 +659,9 @@ static void uv__fs_done(struct uv__work* w, int status) {
req = container_of(w, uv_fs_t, work_req); req = container_of(w, uv_fs_t, work_req);
uv__req_unregister(req->loop, req); uv__req_unregister(req->loop, req);
if (req->errorno != 0) { if (status == -ECANCELED) {
req->errorno = uv_translate_sys_error(req->errorno); assert(req->result == 0);
uv__set_artificial_error(req->loop, req->errorno); req->result = -ECANCELED;
}
if (status == -UV_ECANCELED) {
assert(req->errorno == 0);
req->errorno = UV_ECANCELED;
uv__set_artificial_error(req->loop, UV_ECANCELED);
} }
if (req->cb != NULL) if (req->cb != NULL)

4
deps/uv/src/unix/fsevents.c

@ -248,7 +248,7 @@ int uv__fsevents_init(uv_fs_event_t* handle) {
*/ */
handle->cf_cb = malloc(sizeof(*handle->cf_cb)); handle->cf_cb = malloc(sizeof(*handle->cf_cb));
if (handle->cf_cb == NULL) if (handle->cf_cb == NULL)
return uv__set_sys_error(handle->loop, ENOMEM); return -ENOMEM;
handle->cf_cb->data = handle; handle->cf_cb->data = handle;
uv_async_init(handle->loop, handle->cf_cb, uv__fsevents_cb); uv_async_init(handle->loop, handle->cf_cb, uv__fsevents_cb);
@ -267,7 +267,7 @@ int uv__fsevents_init(uv_fs_event_t* handle) {
int uv__fsevents_close(uv_fs_event_t* handle) { int uv__fsevents_close(uv_fs_event_t* handle) {
if (handle->cf_eventstream == NULL) if (handle->cf_eventstream == NULL)
return -1; return -EINVAL;
/* Ensure that event stream was scheduled */ /* Ensure that event stream was scheduled */
uv_sem_wait(&handle->cf_sem); uv_sem_wait(&handle->cf_sem);

51
deps/uv/src/unix/getaddrinfo.c

@ -28,19 +28,18 @@
static void uv__getaddrinfo_work(struct uv__work* w) { static void uv__getaddrinfo_work(struct uv__work* w) {
uv_getaddrinfo_t* req = container_of(w, uv_getaddrinfo_t, work_req); uv_getaddrinfo_t* req;
int err;
req->retcode = getaddrinfo(req->hostname, req = container_of(w, uv_getaddrinfo_t, work_req);
req->service, err = getaddrinfo(req->hostname, req->service, req->hints, &req->res);
req->hints, req->retcode = uv__getaddrinfo_translate_error(err);
&req->res);
} }
static void uv__getaddrinfo_done(struct uv__work* w, int status) { static void uv__getaddrinfo_done(struct uv__work* w, int status) {
uv_getaddrinfo_t* req; uv_getaddrinfo_t* req;
struct addrinfo *res; struct addrinfo *res;
size_t hostlen;
req = container_of(w, uv_getaddrinfo_t, work_req); req = container_of(w, uv_getaddrinfo_t, work_req);
uv__req_unregister(req->loop, req); uv__req_unregister(req->loop, req);
@ -48,13 +47,6 @@ static void uv__getaddrinfo_done(struct uv__work* w, int status) {
res = req->res; res = req->res;
req->res = NULL; req->res = NULL;
(void) &hostlen; /* Silence unused variable warning. */
hostlen = 0;
#if defined(__sun)
if (req->hostname != NULL)
hostlen = strlen(req->hostname);
#endif
/* See initialization in uv_getaddrinfo(). */ /* See initialization in uv_getaddrinfo(). */
if (req->hints) if (req->hints)
free(req->hints); free(req->hints);
@ -69,35 +61,12 @@ static void uv__getaddrinfo_done(struct uv__work* w, int status) {
req->service = NULL; req->service = NULL;
req->hostname = NULL; req->hostname = NULL;
if (status == -UV_ECANCELED) { if (status == -ECANCELED) {
assert(req->retcode == 0); assert(req->retcode == 0);
req->retcode = UV_ECANCELED; req->retcode = UV_EAI_CANCELED;
uv__set_artificial_error(req->loop, UV_ECANCELED);
req->cb(req, -1, NULL);
return;
}
if (req->retcode == 0) {
req->cb(req, 0, res);
return;
}
if (req->retcode == EAI_NONAME)
uv__set_sys_error(req->loop, ENOENT);
#if defined(EAI_NODATA) /* Newer FreeBSDs don't have EAI_NODATA. */
else if (req->retcode == EAI_NODATA)
uv__set_sys_error(req->loop, ENOENT);
#endif
#if defined(__sun)
else if (req->retcode == EAI_MEMORY && hostlen >= MAXHOSTNAMELEN)
uv__set_sys_error(req->loop, ENOENT);
#endif
else {
req->loop->last_err.code = UV_EADDRINFO;
req->loop->last_err.sys_errno_ = req->retcode;
} }
req->cb(req, -1, res); req->cb(req, req->retcode, res);
} }
@ -114,7 +83,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
char* buf; char* buf;
if (req == NULL || cb == NULL || (hostname == NULL && service == NULL)) if (req == NULL || cb == NULL || (hostname == NULL && service == NULL))
return uv__set_artificial_error(loop, UV_EINVAL); return -EINVAL;
hostname_len = hostname ? strlen(hostname) + 1 : 0; hostname_len = hostname ? strlen(hostname) + 1 : 0;
service_len = service ? strlen(service) + 1 : 0; service_len = service ? strlen(service) + 1 : 0;
@ -122,7 +91,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
buf = malloc(hostname_len + service_len + hints_len); buf = malloc(hostname_len + service_len + hints_len);
if (buf == NULL) if (buf == NULL)
return uv__set_artificial_error(loop, UV_ENOMEM); return -ENOMEM;
uv__req_init(loop, req, UV_GETADDRINFO); uv__req_init(loop, req, UV_GETADDRINFO);
req->loop = loop; req->loop = loop;

3
deps/uv/src/unix/internal.h

@ -142,9 +142,6 @@ void uv__run_idle(uv_loop_t* loop);
void uv__run_check(uv_loop_t* loop); void uv__run_check(uv_loop_t* loop);
void uv__run_prepare(uv_loop_t* loop); void uv__run_prepare(uv_loop_t* loop);
/* error */
uv_err_code uv_translate_sys_error(int sys_errno);
/* stream */ /* stream */
void uv__stream_init(uv_loop_t* loop, uv_stream_t* stream, void uv__stream_init(uv_loop_t* loop, uv_stream_t* stream,
uv_handle_type type); uv_handle_type type);

10
deps/uv/src/unix/kqueue.c

@ -39,9 +39,8 @@ static void uv__fs_event(uv_loop_t* loop, uv__io_t* w, unsigned int fflags);
int uv__kqueue_init(uv_loop_t* loop) { int uv__kqueue_init(uv_loop_t* loop) {
loop->backend_fd = kqueue(); loop->backend_fd = kqueue();
if (loop->backend_fd == -1) if (loop->backend_fd == -1)
return -1; return -errno;
uv__cloexec(loop->backend_fd, 1); uv__cloexec(loop->backend_fd, 1);
@ -308,10 +307,9 @@ int uv_fs_event_init(uv_loop_t* loop,
int fd; int fd;
/* TODO open asynchronously - but how do we report back errors? */ /* TODO open asynchronously - but how do we report back errors? */
if ((fd = open(filename, O_RDONLY)) == -1) { fd = open(filename, O_RDONLY);
uv__set_sys_error(loop, errno); if (fd == -1)
return -1; return -errno;
}
uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT); uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT);
uv__handle_start(handle); /* FIXME shouldn't start automatically */ uv__handle_start(handle); /* FIXME shouldn't start automatically */

76
deps/uv/src/unix/linux-core.c

@ -86,7 +86,7 @@ int uv__platform_loop_init(uv_loop_t* loop, int default_loop) {
loop->inotify_watchers = NULL; loop->inotify_watchers = NULL;
if (fd == -1) if (fd == -1)
return -1; return -errno;
return 0; return 0;
} }
@ -263,12 +263,13 @@ void uv_loadavg(double avg[3]) {
int uv_exepath(char* buffer, size_t* size) { int uv_exepath(char* buffer, size_t* size) {
ssize_t n; ssize_t n;
if (!buffer || !size) { if (buffer == NULL || size == NULL)
return -1; return -EINVAL;
}
n = readlink("/proc/self/exe", buffer, *size - 1); n = readlink("/proc/self/exe", buffer, *size - 1);
if (n <= 0) return -1; if (n == -1)
return -errno;
buffer[n] = '\0'; buffer[n] = '\0';
*size = n; *size = n;
@ -286,7 +287,7 @@ uint64_t uv_get_total_memory(void) {
} }
uv_err_t uv_resident_set_memory(size_t* rss) { int uv_resident_set_memory(size_t* rss) {
char buf[1024]; char buf[1024];
const char* s; const char* s;
ssize_t n; ssize_t n;
@ -299,7 +300,7 @@ uv_err_t uv_resident_set_memory(size_t* rss) {
while (fd == -1 && errno == EINTR); while (fd == -1 && errno == EINTR);
if (fd == -1) if (fd == -1)
return uv__new_sys_error(errno); return -errno;
do do
n = read(fd, buf, sizeof(buf) - 1); n = read(fd, buf, sizeof(buf) - 1);
@ -307,7 +308,7 @@ uv_err_t uv_resident_set_memory(size_t* rss) {
SAVE_ERRNO(close(fd)); SAVE_ERRNO(close(fd));
if (n == -1) if (n == -1)
return uv__new_sys_error(errno); return -errno;
buf[n] = '\0'; buf[n] = '\0';
s = strchr(buf, ' '); s = strchr(buf, ' ');
@ -336,14 +337,14 @@ uv_err_t uv_resident_set_memory(size_t* rss) {
goto err; goto err;
*rss = val * getpagesize(); *rss = val * getpagesize();
return uv_ok_; return 0;
err: err:
return uv__new_artificial_error(UV_EINVAL); return -EINVAL;
} }
uv_err_t uv_uptime(double* uptime) { int uv_uptime(double* uptime) {
static volatile int no_clock_boottime; static volatile int no_clock_boottime;
struct timespec now; struct timespec now;
int r; int r;
@ -361,17 +362,18 @@ uv_err_t uv_uptime(double* uptime) {
} }
if (r) if (r)
return uv__new_sys_error(errno); return -errno;
*uptime = now.tv_sec; *uptime = now.tv_sec;
*uptime += (double)now.tv_nsec / 1000000000.0; *uptime += (double)now.tv_nsec / 1000000000.0;
return uv_ok_; return 0;
} }
uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
unsigned int numcpus; unsigned int numcpus;
uv_cpu_info_t* ci; uv_cpu_info_t* ci;
int err;
*cpu_infos = NULL; *cpu_infos = NULL;
*count = 0; *count = 0;
@ -382,16 +384,15 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
ci = calloc(numcpus, sizeof(*ci)); ci = calloc(numcpus, sizeof(*ci));
if (ci == NULL) if (ci == NULL)
return uv__new_sys_error(ENOMEM); return -ENOMEM;
if (read_models(numcpus, ci)) { err = read_models(numcpus, ci);
SAVE_ERRNO(uv_free_cpu_info(ci, numcpus)); if (err == 0)
return uv__new_sys_error(errno); err = read_times(numcpus, ci);
}
if (read_times(numcpus, ci)) { if (err) {
SAVE_ERRNO(uv_free_cpu_info(ci, numcpus)); uv_free_cpu_info(ci, numcpus);
return uv__new_sys_error(errno); return err;
} }
/* read_models() on x86 also reads the CPU speed from /proc/cpuinfo. /* read_models() on x86 also reads the CPU speed from /proc/cpuinfo.
@ -403,7 +404,7 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
*cpu_infos = ci; *cpu_infos = ci;
*count = numcpus; *count = numcpus;
return uv_ok_; return 0;
} }
@ -447,7 +448,7 @@ static int read_models(unsigned int numcpus, uv_cpu_info_t* ci) {
defined(__x86_64__) defined(__x86_64__)
fp = fopen("/proc/cpuinfo", "r"); fp = fopen("/proc/cpuinfo", "r");
if (fp == NULL) if (fp == NULL)
return -1; return -errno;
while (fgets(buf, sizeof(buf), fp)) { while (fgets(buf, sizeof(buf), fp)) {
if (model_idx < numcpus) { if (model_idx < numcpus) {
@ -456,7 +457,7 @@ static int read_models(unsigned int numcpus, uv_cpu_info_t* ci) {
model = strndup(model, strlen(model) - 1); /* Strip newline. */ model = strndup(model, strlen(model) - 1); /* Strip newline. */
if (model == NULL) { if (model == NULL) {
fclose(fp); fclose(fp);
return -1; return -ENOMEM;
} }
ci[model_idx++].model = model; ci[model_idx++].model = model;
continue; continue;
@ -475,7 +476,7 @@ static int read_models(unsigned int numcpus, uv_cpu_info_t* ci) {
model = strndup(model, strlen(model) - 1); /* Strip newline. */ model = strndup(model, strlen(model) - 1); /* Strip newline. */
if (model == NULL) { if (model == NULL) {
fclose(fp); fclose(fp);
return -1; return -ENOMEM;
} }
ci[model_idx++].model = model; ci[model_idx++].model = model;
continue; continue;
@ -505,7 +506,7 @@ static int read_models(unsigned int numcpus, uv_cpu_info_t* ci) {
while (model_idx < numcpus) { while (model_idx < numcpus) {
model = strndup(inferred_model, strlen(inferred_model)); model = strndup(inferred_model, strlen(inferred_model));
if (model == NULL) if (model == NULL)
return -1; return -ENOMEM;
ci[model_idx++].model = model; ci[model_idx++].model = model;
} }
@ -533,7 +534,7 @@ static int read_times(unsigned int numcpus, uv_cpu_info_t* ci) {
fp = fopen("/proc/stat", "r"); fp = fopen("/proc/stat", "r");
if (fp == NULL) if (fp == NULL)
return -1; return -errno;
if (!fgets(buf, sizeof(buf), fp)) if (!fgets(buf, sizeof(buf), fp))
abort(); abort();
@ -617,18 +618,17 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
} }
uv_err_t uv_interface_addresses(uv_interface_address_t** addresses, int uv_interface_addresses(uv_interface_address_t** addresses,
int* count) { int* count) {
#ifndef HAVE_IFADDRS_H #ifndef HAVE_IFADDRS_H
return uv__new_artificial_error(UV_ENOSYS); return -ENOSYS;
#else #else
struct ifaddrs *addrs, *ent; struct ifaddrs *addrs, *ent;
char ip[INET6_ADDRSTRLEN]; char ip[INET6_ADDRSTRLEN];
uv_interface_address_t* address; uv_interface_address_t* address;
if (getifaddrs(&addrs) != 0) { if (getifaddrs(&addrs))
return uv__new_sys_error(errno); return -errno;
}
*count = 0; *count = 0;
@ -643,11 +643,9 @@ uv_err_t uv_interface_addresses(uv_interface_address_t** addresses,
(*count)++; (*count)++;
} }
*addresses = (uv_interface_address_t*) *addresses = malloc(*count * sizeof(**addresses));
malloc(*count * sizeof(uv_interface_address_t)); if (!(*addresses))
if (!(*addresses)) { return -ENOMEM;
return uv__new_artificial_error(UV_ENOMEM);
}
address = *addresses; address = *addresses;
@ -690,7 +688,7 @@ uv_err_t uv_interface_addresses(uv_interface_address_t** addresses,
freeifaddrs(addrs); freeifaddrs(addrs);
return uv_ok_; return 0;
#endif #endif
} }

39
deps/uv/src/unix/linux-inotify.c

@ -62,20 +62,27 @@ static void uv__inotify_read(uv_loop_t* loop,
static int new_inotify_fd(void) { static int new_inotify_fd(void) {
int err;
int fd; int fd;
fd = uv__inotify_init1(UV__IN_NONBLOCK | UV__IN_CLOEXEC); fd = uv__inotify_init1(UV__IN_NONBLOCK | UV__IN_CLOEXEC);
if (fd != -1) if (fd != -1)
return fd; return fd;
if (errno != ENOSYS) if (errno != ENOSYS)
return -1; return -errno;
fd = uv__inotify_init();
if (fd == -1)
return -errno;
if ((fd = uv__inotify_init()) == -1) err = uv__cloexec(fd, 1);
return -1; if (err == 0)
err = uv__nonblock(fd, 1);
if (uv__cloexec(fd, 1) || uv__nonblock(fd, 1)) { if (err) {
SAVE_ERRNO(close(fd)); close(fd);
return -1; return err;
} }
return fd; return fd;
@ -83,15 +90,16 @@ static int new_inotify_fd(void) {
static int init_inotify(uv_loop_t* loop) { static int init_inotify(uv_loop_t* loop) {
int err;
if (loop->inotify_fd != -1) if (loop->inotify_fd != -1)
return 0; return 0;
loop->inotify_fd = new_inotify_fd(); err = new_inotify_fd();
if (loop->inotify_fd == -1) { if (err < 0)
uv__set_sys_error(loop, errno); return err;
return -1;
}
loop->inotify_fd = err;
uv__io_init(&loop->inotify_read_watcher, uv__inotify_read, loop->inotify_fd); uv__io_init(&loop->inotify_read_watcher, uv__inotify_read, loop->inotify_fd);
uv__io_start(loop, &loop->inotify_read_watcher, UV__POLLIN); uv__io_start(loop, &loop->inotify_read_watcher, UV__POLLIN);
@ -167,9 +175,12 @@ int uv_fs_event_init(uv_loop_t* loop,
int flags) { int flags) {
struct watcher_list* w; struct watcher_list* w;
int events; int events;
int err;
int wd; int wd;
if (init_inotify(loop)) return -1; err = init_inotify(loop);
if (err)
return err;
events = UV__IN_ATTRIB events = UV__IN_ATTRIB
| UV__IN_CREATE | UV__IN_CREATE
@ -182,7 +193,7 @@ int uv_fs_event_init(uv_loop_t* loop,
wd = uv__inotify_add_watch(loop->inotify_fd, path, events); wd = uv__inotify_add_watch(loop->inotify_fd, path, events);
if (wd == -1) if (wd == -1)
return uv__set_sys_error(loop, errno); return -errno;
w = find_watcher(loop, wd); w = find_watcher(loop, wd);
if (w) if (w)
@ -190,7 +201,7 @@ int uv_fs_event_init(uv_loop_t* loop,
w = malloc(sizeof(*w) + strlen(path) + 1); w = malloc(sizeof(*w) + strlen(path) + 1);
if (w == NULL) if (w == NULL)
return uv__set_sys_error(loop, ENOMEM); return -ENOMEM;
w->wd = wd; w->wd = wd;
w->path = strcpy((char*)(w + 1), path); w->path = strcpy((char*)(w + 1), path);

3
deps/uv/src/unix/loop-watcher.c

@ -31,8 +31,7 @@
\ \
int uv_##name##_start(uv_##name##_t* handle, uv_##name##_cb cb) { \ int uv_##name##_start(uv_##name##_t* handle, uv_##name##_cb cb) { \
if (uv__is_active(handle)) return 0; \ if (uv__is_active(handle)) return 0; \
if (cb == NULL) \ if (cb == NULL) return -EINVAL; \
return uv__set_artificial_error(handle->loop, UV_EINVAL); \
QUEUE_INSERT_HEAD(&handle->loop->name##_handles, &handle->queue); \ QUEUE_INSERT_HEAD(&handle->loop->name##_handles, &handle->queue); \
handle->name##_cb = cb; \ handle->name##_cb = cb; \
uv__handle_start(handle); \ uv__handle_start(handle); \

6
deps/uv/src/unix/loop.c

@ -29,6 +29,7 @@
int uv__loop_init(uv_loop_t* loop, int default_loop) { int uv__loop_init(uv_loop_t* loop, int default_loop) {
unsigned int i; unsigned int i;
int err;
uv__signal_global_once_init(); uv__signal_global_once_init();
@ -59,8 +60,9 @@ int uv__loop_init(uv_loop_t* loop, int default_loop) {
loop->timer_counter = 0; loop->timer_counter = 0;
loop->stop_flag = 0; loop->stop_flag = 0;
if (uv__platform_loop_init(loop, default_loop)) err = uv__platform_loop_init(loop, default_loop);
return -1; if (err)
return err;
uv_signal_init(loop, &loop->child_watcher); uv_signal_init(loop, &loop->child_watcher);
uv__handle_unref(&loop->child_watcher); uv__handle_unref(&loop->child_watcher);

90
deps/uv/src/unix/netbsd.c

@ -81,9 +81,8 @@ int uv_exepath(char* buffer, size_t* size) {
size_t cb; size_t cb;
pid_t mypid; pid_t mypid;
if (!buffer || !size) { if (buffer == NULL || size == NULL)
return -1; return -EINVAL;
}
mypid = getpid(); mypid = getpid();
mib[0] = CTL_KERN; mib[0] = CTL_KERN;
@ -92,10 +91,8 @@ int uv_exepath(char* buffer, size_t* size) {
mib[3] = KERN_PROC_ARGV; mib[3] = KERN_PROC_ARGV;
cb = *size; cb = *size;
if (sysctl(mib, 4, buffer, &cb, NULL, 0) == -1) { if (sysctl(mib, 4, buffer, &cb, NULL, 0))
*size = 0; return -errno;
return -1;
}
*size = strlen(buffer); *size = strlen(buffer);
return 0; return 0;
@ -107,9 +104,8 @@ uint64_t uv_get_free_memory(void) {
size_t size = sizeof(info); size_t size = sizeof(info);
int which[] = {CTL_VM, VM_UVMEXP}; int which[] = {CTL_VM, VM_UVMEXP};
if (sysctl(which, 2, &info, &size, NULL, 0) == -1) { if (sysctl(which, 2, &info, &size, NULL, 0))
return -1; return -errno;
}
return (uint64_t) info.free * sysconf(_SC_PAGESIZE); return (uint64_t) info.free * sysconf(_SC_PAGESIZE);
} }
@ -125,9 +121,8 @@ uint64_t uv_get_total_memory(void) {
#endif #endif
size_t size = sizeof(info); size_t size = sizeof(info);
if (sysctl(which, 2, &info, &size, NULL, 0) == -1) { if (sysctl(which, 2, &info, &size, NULL, 0))
return -1; return -errno;
}
return (uint64_t) info; return (uint64_t) info;
} }
@ -139,17 +134,17 @@ char** uv_setup_args(int argc, char** argv) {
} }
uv_err_t uv_set_process_title(const char* title) { int uv_set_process_title(const char* title) {
if (process_title) free(process_title); if (process_title) free(process_title);
process_title = strdup(title); process_title = strdup(title);
setproctitle("%s", title); setproctitle("%s", title);
return uv_ok_; return 0;
} }
uv_err_t uv_get_process_title(char* buffer, size_t size) { int uv_get_process_title(char* buffer, size_t size) {
if (process_title) { if (process_title) {
strncpy(buffer, process_title, size); strncpy(buffer, process_title, size);
} else { } else {
@ -158,11 +153,11 @@ uv_err_t uv_get_process_title(char* buffer, size_t size) {
} }
} }
return uv_ok_; return 0;
} }
uv_err_t uv_resident_set_memory(size_t* rss) { int uv_resident_set_memory(size_t* rss) {
kvm_t *kd = NULL; kvm_t *kd = NULL;
struct kinfo_proc2 *kinfo = NULL; struct kinfo_proc2 *kinfo = NULL;
pid_t pid; pid_t pid;
@ -184,32 +179,31 @@ uv_err_t uv_resident_set_memory(size_t* rss) {
kvm_close(kd); kvm_close(kd);
return uv_ok_; return 0;
error: error:
if (kd) kvm_close(kd); if (kd) kvm_close(kd);
return uv__new_sys_error(errno); return -EPERM;
} }
uv_err_t uv_uptime(double* uptime) { int uv_uptime(double* uptime) {
time_t now; time_t now;
struct timeval info; struct timeval info;
size_t size = sizeof(info); size_t size = sizeof(info);
static int which[] = {CTL_KERN, KERN_BOOTTIME}; static int which[] = {CTL_KERN, KERN_BOOTTIME};
if (sysctl(which, 2, &info, &size, NULL, 0) == -1) { if (sysctl(which, 2, &info, &size, NULL, 0))
return uv__new_sys_error(errno); return -errno;
}
now = time(NULL); now = time(NULL);
*uptime = (double)(now - info.tv_sec); *uptime = (double)(now - info.tv_sec);
return uv_ok_; return 0;
} }
uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
unsigned int ticks = (unsigned int)sysconf(_SC_CLK_TCK); unsigned int ticks = (unsigned int)sysconf(_SC_CLK_TCK);
unsigned int multiplier = ((uint64_t)1000L / ticks); unsigned int multiplier = ((uint64_t)1000L / ticks);
unsigned int cur = 0; unsigned int cur = 0;
@ -222,37 +216,34 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
int i; int i;
size = sizeof(model); size = sizeof(model);
if (sysctlbyname("machdep.cpu_brand", &model, &size, NULL, 0) == -1 && if (sysctlbyname("machdep.cpu_brand", &model, &size, NULL, 0) &&
sysctlbyname("hw.model", &model, &size, NULL, 0) == -1) { sysctlbyname("hw.model", &model, &size, NULL, 0)) {
return uv__new_sys_error(errno); return -errno;
} }
size = sizeof(numcpus); size = sizeof(numcpus);
if (sysctlbyname("hw.ncpu", &numcpus, &size, NULL, 0) == -1) { if (sysctlbyname("hw.ncpu", &numcpus, &size, NULL, 0))
return uv__new_sys_error(errno); return -errno;
}
*count = numcpus; *count = numcpus;
/* Only i386 and amd64 have machdep.tsc_freq */ /* Only i386 and amd64 have machdep.tsc_freq */
size = sizeof(cpuspeed); size = sizeof(cpuspeed);
if (sysctlbyname("machdep.tsc_freq", &cpuspeed, &size, NULL, 0) == -1) { if (sysctlbyname("machdep.tsc_freq", &cpuspeed, &size, NULL, 0))
cpuspeed = 0; cpuspeed = 0;
}
size = numcpus * CPUSTATES * sizeof(*cp_times); size = numcpus * CPUSTATES * sizeof(*cp_times);
cp_times = malloc(size); cp_times = malloc(size);
if (cp_times == NULL) { if (cp_times == NULL)
return uv__new_artificial_error(UV_ENOMEM); return -ENOMEM;
}
if (sysctlbyname("kern.cp_time", cp_times, &size, NULL, 0) == -1) { if (sysctlbyname("kern.cp_time", cp_times, &size, NULL, 0))
return uv__new_sys_error(errno); return -errno;
}
*cpu_infos = malloc(numcpus * sizeof(**cpu_infos)); *cpu_infos = malloc(numcpus * sizeof(**cpu_infos));
if (!(*cpu_infos)) { if (!(*cpu_infos)) {
free(cp_times); free(cp_times);
free(*cpu_infos); free(*cpu_infos);
return uv__new_artificial_error(UV_ENOMEM); return -ENOMEM;
} }
for (i = 0; i < numcpus; i++) { for (i = 0; i < numcpus; i++) {
@ -267,9 +258,10 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
cur += CPUSTATES; cur += CPUSTATES;
} }
free(cp_times); free(cp_times);
return uv_ok_; return 0;
} }
void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) { void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
int i; int i;
@ -281,14 +273,13 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
} }
uv_err_t uv_interface_addresses(uv_interface_address_t** addresses, int* count) { int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
struct ifaddrs *addrs; struct ifaddrs *addrs;
struct ifaddrs *ent; struct ifaddrs *ent;
uv_interface_address_t* address; uv_interface_address_t* address;
if (getifaddrs(&addrs) != 0) { if (getifaddrs(&addrs))
return uv__new_sys_error(errno); return -errno;
}
*count = 0; *count = 0;
@ -304,9 +295,8 @@ uv_err_t uv_interface_addresses(uv_interface_address_t** addresses, int* count)
*addresses = malloc(*count * sizeof(**addresses)); *addresses = malloc(*count * sizeof(**addresses));
if (!(*addresses)) { if (!(*addresses))
return uv__new_artificial_error(UV_ENOMEM); return -ENOMEM;
}
address = *addresses; address = *addresses;
@ -344,7 +334,7 @@ uv_err_t uv_interface_addresses(uv_interface_address_t** addresses, int* count)
freeifaddrs(addrs); freeifaddrs(addrs);
return uv_ok_; return 0;
} }

91
deps/uv/src/unix/openbsd.c

@ -79,16 +79,17 @@ int uv_exepath(char* buffer, size_t* size) {
size_t argsbuf_size = 100U; size_t argsbuf_size = 100U;
size_t exepath_size; size_t exepath_size;
pid_t mypid; pid_t mypid;
int status = -1; int err;
if (buffer == NULL || size == NULL)
return -EINVAL;
if (!buffer || !size) {
goto out;
}
mypid = getpid(); mypid = getpid();
for (;;) { for (;;) {
if ((argsbuf_tmp = realloc(argsbuf, argsbuf_size)) == NULL) { err = -ENOMEM;
argsbuf_tmp = realloc(argsbuf, argsbuf_size);
if (argsbuf_tmp == NULL)
goto out; goto out;
}
argsbuf = argsbuf_tmp; argsbuf = argsbuf_tmp;
mib[0] = CTL_KERN; mib[0] = CTL_KERN;
mib[1] = KERN_PROC_ARGS; mib[1] = KERN_PROC_ARGS;
@ -98,25 +99,28 @@ int uv_exepath(char* buffer, size_t* size) {
break; break;
} }
if (errno != ENOMEM) { if (errno != ENOMEM) {
err = -errno;
goto out; goto out;
} }
argsbuf_size *= 2U; argsbuf_size *= 2U;
} }
if (argsbuf[0] == NULL) { if (argsbuf[0] == NULL) {
err = -EINVAL; /* FIXME(bnoordhuis) More appropriate error. */
goto out; goto out;
} }
exepath_size = strlen(argsbuf[0]); exepath_size = strlen(argsbuf[0]);
if (exepath_size >= *size) { if (exepath_size >= *size) {
err = -EINVAL;
goto out; goto out;
} }
memcpy(buffer, argsbuf[0], exepath_size + 1U); memcpy(buffer, argsbuf[0], exepath_size + 1U);
*size = exepath_size; *size = exepath_size;
status = 0; err = 0;
out: out:
free(argsbuf); free(argsbuf);
return status; return err;
} }
@ -125,9 +129,8 @@ uint64_t uv_get_free_memory(void) {
size_t size = sizeof(info); size_t size = sizeof(info);
int which[] = {CTL_VM, VM_UVMEXP}; int which[] = {CTL_VM, VM_UVMEXP};
if (sysctl(which, 2, &info, &size, NULL, 0) < 0) { if (sysctl(which, 2, &info, &size, NULL, 0))
return -1; return -errno;
}
return (uint64_t) info.free * sysconf(_SC_PAGESIZE); return (uint64_t) info.free * sysconf(_SC_PAGESIZE);
} }
@ -138,9 +141,8 @@ uint64_t uv_get_total_memory(void) {
int which[] = {CTL_HW, HW_PHYSMEM64}; int which[] = {CTL_HW, HW_PHYSMEM64};
size_t size = sizeof(info); size_t size = sizeof(info);
if (sysctl(which, 2, &info, &size, NULL, 0) < 0) { if (sysctl(which, 2, &info, &size, NULL, 0))
return -1; return -errno;
}
return (uint64_t) info; return (uint64_t) info;
} }
@ -152,15 +154,15 @@ char** uv_setup_args(int argc, char** argv) {
} }
uv_err_t uv_set_process_title(const char* title) { int uv_set_process_title(const char* title) {
if (process_title) free(process_title); if (process_title) free(process_title);
process_title = strdup(title); process_title = strdup(title);
setproctitle(title); setproctitle(title);
return uv_ok_; return 0;
} }
uv_err_t uv_get_process_title(char* buffer, size_t size) { int uv_get_process_title(char* buffer, size_t size) {
if (process_title) { if (process_title) {
strncpy(buffer, process_title, size); strncpy(buffer, process_title, size);
} else { } else {
@ -169,11 +171,11 @@ uv_err_t uv_get_process_title(char* buffer, size_t size) {
} }
} }
return uv_ok_; return 0;
} }
uv_err_t uv_resident_set_memory(size_t* rss) { int uv_resident_set_memory(size_t* rss) {
kvm_t *kd = NULL; kvm_t *kd = NULL;
struct kinfo_proc *kinfo = NULL; struct kinfo_proc *kinfo = NULL;
pid_t pid; pid_t pid;
@ -192,32 +194,31 @@ uv_err_t uv_resident_set_memory(size_t* rss) {
kvm_close(kd); kvm_close(kd);
return uv_ok_; return 0;
error: error:
if (kd) kvm_close(kd); if (kd) kvm_close(kd);
return uv__new_sys_error(errno); return -EPERM;
} }
uv_err_t uv_uptime(double* uptime) { int uv_uptime(double* uptime) {
time_t now; time_t now;
struct timeval info; struct timeval info;
size_t size = sizeof(info); size_t size = sizeof(info);
static int which[] = {CTL_KERN, KERN_BOOTTIME}; static int which[] = {CTL_KERN, KERN_BOOTTIME};
if (sysctl(which, 2, &info, &size, NULL, 0) < 0) { if (sysctl(which, 2, &info, &size, NULL, 0))
return uv__new_sys_error(errno); return -errno;
}
now = time(NULL); now = time(NULL);
*uptime = (double)(now - info.tv_sec); *uptime = (double)(now - info.tv_sec);
return uv_ok_; return 0;
} }
uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
unsigned int ticks = (unsigned int)sysconf(_SC_CLK_TCK), unsigned int ticks = (unsigned int)sysconf(_SC_CLK_TCK),
multiplier = ((uint64_t)1000L / ticks), cpuspeed; multiplier = ((uint64_t)1000L / ticks), cpuspeed;
uint64_t info[CPUSTATES]; uint64_t info[CPUSTATES];
@ -229,27 +230,25 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
uv_cpu_info_t* cpu_info; uv_cpu_info_t* cpu_info;
size = sizeof(model); size = sizeof(model);
if (sysctl(which, 2, &model, &size, NULL, 0) < 0) { if (sysctl(which, 2, &model, &size, NULL, 0))
return uv__new_sys_error(errno); return -errno;
}
which[1] = HW_NCPU; which[1] = HW_NCPU;
size = sizeof(numcpus); size = sizeof(numcpus);
if (sysctl(which, 2, &numcpus, &size, NULL, 0) < 0) { if (sysctl(which, 2, &numcpus, &size, NULL, 0))
return uv__new_sys_error(errno); return -errno;
}
*cpu_infos = (uv_cpu_info_t*)malloc(numcpus * sizeof(uv_cpu_info_t)); *cpu_infos = malloc(numcpus * sizeof(**cpu_infos));
if (!(*cpu_infos)) { if (!(*cpu_infos))
return uv__new_artificial_error(UV_ENOMEM); return -ENOMEM;
}
*count = numcpus; *count = numcpus;
which[1] = HW_CPUSPEED; which[1] = HW_CPUSPEED;
size = sizeof(cpuspeed); size = sizeof(cpuspeed);
if (sysctl(which, 2, &cpuspeed, &size, NULL, 0) < 0) { if (sysctl(which, 2, &cpuspeed, &size, NULL, 0)) {
free(*cpu_infos); SAVE_ERRNO(free(*cpu_infos));
return uv__new_sys_error(errno); return -errno;
} }
size = sizeof(info); size = sizeof(info);
@ -258,9 +257,9 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
for (i = 0; i < numcpus; i++) { for (i = 0; i < numcpus; i++) {
which[2] = i; which[2] = i;
size = sizeof(info); size = sizeof(info);
if (sysctl(which, 3, &info, &size, NULL, 0) < 0) { if (sysctl(which, 3, &info, &size, NULL, 0)) {
free(*cpu_infos); SAVE_ERRNO(free(*cpu_infos));
return uv__new_sys_error(errno); return -errno;
} }
cpu_info = &(*cpu_infos)[i]; cpu_info = &(*cpu_infos)[i];
@ -275,7 +274,7 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
cpu_info->speed = cpuspeed; cpu_info->speed = cpuspeed;
} }
return uv_ok_; return 0;
} }
@ -290,12 +289,12 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
} }
uv_err_t uv_interface_addresses(uv_interface_address_t** addresses, int uv_interface_addresses(uv_interface_address_t** addresses,
int* count) { int* count) {
/* TODO: implement */ /* TODO: implement */
*addresses = NULL; *addresses = NULL;
*count = 0; *count = 0;
return uv_ok_; return 0;
} }

114
deps/uv/src/unix/pipe.c

@ -46,41 +46,42 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
struct sockaddr_un saddr; struct sockaddr_un saddr;
const char* pipe_fname; const char* pipe_fname;
int sockfd; int sockfd;
int status;
int bound; int bound;
int err;
pipe_fname = NULL; pipe_fname = NULL;
sockfd = -1; sockfd = -1;
status = -1;
bound = 0; bound = 0;
err = -EINVAL;
/* Already bound? */ /* Already bound? */
if (uv__stream_fd(handle) >= 0) { if (uv__stream_fd(handle) >= 0)
uv__set_artificial_error(handle->loop, UV_EINVAL); return -EINVAL;
goto out;
}
/* Make a copy of the file name, it outlives this function's scope. */ /* Make a copy of the file name, it outlives this function's scope. */
if ((pipe_fname = strdup(name)) == NULL) { pipe_fname = strdup(name);
uv__set_sys_error(handle->loop, ENOMEM); if (pipe_fname == NULL) {
err = -ENOMEM;
goto out; goto out;
} }
/* We've got a copy, don't touch the original any more. */ /* We've got a copy, don't touch the original any more. */
name = NULL; name = NULL;
if ((sockfd = uv__socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { err = uv__socket(AF_UNIX, SOCK_STREAM, 0);
uv__set_sys_error(handle->loop, errno); if (err < 0)
goto out; goto out;
} sockfd = err;
memset(&saddr, 0, sizeof saddr); memset(&saddr, 0, sizeof saddr);
uv_strlcpy(saddr.sun_path, pipe_fname, sizeof(saddr.sun_path)); uv_strlcpy(saddr.sun_path, pipe_fname, sizeof(saddr.sun_path));
saddr.sun_family = AF_UNIX; saddr.sun_family = AF_UNIX;
if (bind(sockfd, (struct sockaddr*)&saddr, sizeof saddr)) { if (bind(sockfd, (struct sockaddr*)&saddr, sizeof saddr)) {
err = -errno;
/* Convert ENOENT to EACCES for compatibility with Windows. */ /* Convert ENOENT to EACCES for compatibility with Windows. */
uv__set_sys_error(handle->loop, (errno == ENOENT) ? EACCES : errno); if (err == -ENOENT)
err = -EACCES;
goto out; goto out;
} }
bound = 1; bound = 1;
@ -88,32 +89,26 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
/* Success. */ /* Success. */
handle->pipe_fname = pipe_fname; /* Is a strdup'ed copy. */ handle->pipe_fname = pipe_fname; /* Is a strdup'ed copy. */
handle->io_watcher.fd = sockfd; handle->io_watcher.fd = sockfd;
status = 0; return 0;
out: out:
/* Clean up on error. */ if (bound) {
if (status) { /* unlink() before close() to avoid races. */
if (bound) { assert(pipe_fname != NULL);
/* unlink() before close() to avoid races. */ unlink(pipe_fname);
assert(pipe_fname != NULL);
unlink(pipe_fname);
}
close(sockfd);
free((void*)pipe_fname);
} }
close(sockfd);
return status; free((void*)pipe_fname);
return err;
} }
int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) { int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) {
if (uv__stream_fd(handle) == -1) if (uv__stream_fd(handle) == -1)
return uv__set_artificial_error(handle->loop, UV_EINVAL); return -EINVAL;
assert(uv__stream_fd(handle) >= 0);
if (listen(uv__stream_fd(handle), backlog)) if (listen(uv__stream_fd(handle), backlog))
return uv__set_sys_error(handle->loop, errno); return -errno;
handle->connection_cb = cb; handle->connection_cb = cb;
handle->io_watcher.cb = uv__pipe_accept; handle->io_watcher.cb = uv__pipe_accept;
@ -141,8 +136,11 @@ void uv__pipe_close(uv_pipe_t* handle) {
int uv_pipe_open(uv_pipe_t* handle, uv_file fd) { int uv_pipe_open(uv_pipe_t* handle, uv_file fd) {
#if defined(__APPLE__) #if defined(__APPLE__)
if (uv__stream_try_select((uv_stream_t*) handle, &fd)) int err;
return -1;
err = uv__stream_try_select((uv_stream_t*) handle, &fd);
if (err)
return err;
#endif /* defined(__APPLE__) */ #endif /* defined(__APPLE__) */
return uv__stream_open((uv_stream_t*)handle, return uv__stream_open((uv_stream_t*)handle,
@ -161,11 +159,14 @@ void uv_pipe_connect(uv_connect_t* req,
int r; int r;
new_sock = (uv__stream_fd(handle) == -1); new_sock = (uv__stream_fd(handle) == -1);
err = -1; err = -EINVAL;
if (new_sock) if (new_sock) {
if ((handle->io_watcher.fd = uv__socket(AF_UNIX, SOCK_STREAM, 0)) == -1) err = uv__socket(AF_UNIX, SOCK_STREAM, 0);
if (err < 0)
goto out; goto out;
handle->io_watcher.fd = err;
}
memset(&saddr, 0, sizeof saddr); memset(&saddr, 0, sizeof saddr);
uv_strlcpy(saddr.sun_path, name, sizeof(saddr.sun_path)); uv_strlcpy(saddr.sun_path, name, sizeof(saddr.sun_path));
@ -177,21 +178,23 @@ void uv_pipe_connect(uv_connect_t* req,
} }
while (r == -1 && errno == EINTR); while (r == -1 && errno == EINTR);
if (r == -1) if (r == -1 && errno != EINPROGRESS) {
if (errno != EINPROGRESS) err = -errno;
goto out; goto out;
}
if (new_sock)
if (uv__stream_open((uv_stream_t*)handle,
uv__stream_fd(handle),
UV_STREAM_READABLE | UV_STREAM_WRITABLE))
goto out;
uv__io_start(handle->loop, &handle->io_watcher, UV__POLLIN | UV__POLLOUT);
err = 0; err = 0;
if (new_sock) {
err = uv__stream_open((uv_stream_t*)handle,
uv__stream_fd(handle),
UV_STREAM_READABLE | UV_STREAM_WRITABLE);
}
if (err == 0)
uv__io_start(handle->loop, &handle->io_watcher, UV__POLLIN | UV__POLLOUT);
out: out:
handle->delayed_error = err ? errno : 0; /* Passed to callback. */ handle->delayed_error = err;
handle->connect_req = req; handle->connect_req = req;
uv__req_init(handle->loop, req, UV_CONNECT); uv__req_init(handle->loop, req, UV_CONNECT);
@ -200,7 +203,7 @@ out:
QUEUE_INIT(&req->queue); QUEUE_INIT(&req->queue);
/* Force callback to run on next tick in case of error. */ /* Force callback to run on next tick in case of error. */
if (err != 0) if (err)
uv__io_feed(handle->loop, &handle->io_watcher); uv__io_feed(handle->loop, &handle->io_watcher);
/* Mimic the Windows pipe implementation, always /* Mimic the Windows pipe implementation, always
@ -219,17 +222,16 @@ static void uv__pipe_accept(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
sockfd = uv__accept(uv__stream_fd(pipe)); sockfd = uv__accept(uv__stream_fd(pipe));
if (sockfd == -1) { if (sockfd == -1) {
if (errno != EAGAIN && errno != EWOULDBLOCK) { if (errno != EAGAIN && errno != EWOULDBLOCK)
uv__set_sys_error(pipe->loop, errno); pipe->connection_cb((uv_stream_t*)pipe, -errno);
pipe->connection_cb((uv_stream_t*)pipe, -1); return;
} }
} else {
pipe->accepted_fd = sockfd; pipe->accepted_fd = sockfd;
pipe->connection_cb((uv_stream_t*)pipe, 0); pipe->connection_cb((uv_stream_t*)pipe, 0);
if (pipe->accepted_fd == sockfd) { if (pipe->accepted_fd == sockfd) {
/* The user hasn't called uv_accept() yet */ /* The user hasn't called uv_accept() yet */
uv__io_stop(pipe->loop, &pipe->io_watcher, UV__POLLIN); uv__io_stop(pipe->loop, &pipe->io_watcher, UV__POLLIN);
}
} }
} }

3
deps/uv/src/unix/poll.c

@ -36,8 +36,7 @@ static void uv__poll_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
if (events & UV__POLLERR) { if (events & UV__POLLERR) {
uv__io_stop(loop, w, UV__POLLIN | UV__POLLOUT); uv__io_stop(loop, w, UV__POLLIN | UV__POLLOUT);
uv__handle_stop(handle); uv__handle_stop(handle);
uv__set_sys_error(handle->loop, EBADF); handle->poll_cb(handle, -EBADF, 0);
handle->poll_cb(handle, -1, 0);
return; return;
} }

95
deps/uv/src/unix/process.c

@ -103,10 +103,8 @@ static void uv__chld(uv_signal_t* handle, int signum) {
if (WIFSIGNALED(status)) if (WIFSIGNALED(status))
term_signal = WTERMSIG(status); term_signal = WTERMSIG(status);
if (process->errorno) { if (process->errorno)
uv__set_sys_error(process->loop, process->errorno); exit_status = process->errorno; /* execve() failed */
exit_status = -1; /* execve() failed */
}
process->exit_cb(process, exit_status, term_signal); process->exit_cb(process, exit_status, term_signal);
} }
@ -127,7 +125,7 @@ int uv__make_socketpair(int fds[2], int flags) {
* Anything else is a genuine error. * Anything else is a genuine error.
*/ */
if (errno != EINVAL) if (errno != EINVAL)
return -1; return -errno;
no_cloexec = 1; no_cloexec = 1;
@ -135,7 +133,7 @@ skip:
#endif #endif
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds)) if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds))
return -1; return -errno;
uv__cloexec(fds[0], 1); uv__cloexec(fds[0], 1);
uv__cloexec(fds[1], 1); uv__cloexec(fds[1], 1);
@ -160,7 +158,7 @@ int uv__make_pipe(int fds[2], int flags) {
return 0; return 0;
if (errno != ENOSYS) if (errno != ENOSYS)
return -1; return -errno;
no_pipe2 = 1; no_pipe2 = 1;
@ -168,7 +166,7 @@ skip:
#endif #endif
if (pipe(fds)) if (pipe(fds))
return -1; return -errno;
uv__cloexec(fds[0], 1); uv__cloexec(fds[0], 1);
uv__cloexec(fds[1], 1); uv__cloexec(fds[1], 1);
@ -198,11 +196,10 @@ static int uv__process_init_stdio(uv_stdio_container_t* container, int fds[2]) {
case UV_CREATE_PIPE: case UV_CREATE_PIPE:
assert(container->data.stream != NULL); assert(container->data.stream != NULL);
if (container->data.stream->type != UV_NAMED_PIPE) { if (container->data.stream->type != UV_NAMED_PIPE)
errno = EINVAL; return -EINVAL;
return -1; else
} return uv__make_socketpair(fds, 0);
return uv__make_socketpair(fds, 0);
case UV_INHERIT_FD: case UV_INHERIT_FD:
case UV_INHERIT_STREAM: case UV_INHERIT_STREAM:
@ -211,17 +208,15 @@ static int uv__process_init_stdio(uv_stdio_container_t* container, int fds[2]) {
else else
fd = uv__stream_fd(container->data.stream); fd = uv__stream_fd(container->data.stream);
if (fd == -1) { if (fd == -1)
errno = EINVAL; return -EINVAL;
return -1;
}
fds[1] = fd; fds[1] = fd;
return 0; return 0;
default: default:
assert(0 && "Unexpected flags"); assert(0 && "Unexpected flags");
return -1; return -EINVAL;
} }
} }
@ -299,7 +294,7 @@ static void uv__process_child_init(uv_process_options_t options,
use_fd = open("/dev/null", fd == 0 ? O_RDONLY : O_RDWR); use_fd = open("/dev/null", fd == 0 ? O_RDONLY : O_RDWR);
if (use_fd == -1) { if (use_fd == -1) {
uv__write_int(error_fd, errno); uv__write_int(error_fd, -errno);
perror("failed to open stdio"); perror("failed to open stdio");
_exit(127); _exit(127);
} }
@ -317,19 +312,19 @@ static void uv__process_child_init(uv_process_options_t options,
} }
if (options.cwd && chdir(options.cwd)) { if (options.cwd && chdir(options.cwd)) {
uv__write_int(error_fd, errno); uv__write_int(error_fd, -errno);
perror("chdir()"); perror("chdir()");
_exit(127); _exit(127);
} }
if ((options.flags & UV_PROCESS_SETGID) && setgid(options.gid)) { if ((options.flags & UV_PROCESS_SETGID) && setgid(options.gid)) {
uv__write_int(error_fd, errno); uv__write_int(error_fd, -errno);
perror("setgid()"); perror("setgid()");
_exit(127); _exit(127);
} }
if ((options.flags & UV_PROCESS_SETUID) && setuid(options.uid)) { if ((options.flags & UV_PROCESS_SETUID) && setuid(options.uid)) {
uv__write_int(error_fd, errno); uv__write_int(error_fd, -errno);
perror("setuid()"); perror("setuid()");
_exit(127); _exit(127);
} }
@ -339,7 +334,7 @@ static void uv__process_child_init(uv_process_options_t options,
} }
execvp(options.file, options.args); execvp(options.file, options.args);
uv__write_int(error_fd, errno); uv__write_int(error_fd, -errno);
perror("execvp()"); perror("execvp()");
_exit(127); _exit(127);
} }
@ -354,6 +349,7 @@ int uv_spawn(uv_loop_t* loop,
QUEUE* q; QUEUE* q;
ssize_t r; ssize_t r;
pid_t pid; pid_t pid;
int err;
int i; int i;
assert(options.file != NULL); assert(options.file != NULL);
@ -370,20 +366,21 @@ int uv_spawn(uv_loop_t* loop,
if (stdio_count < 3) if (stdio_count < 3)
stdio_count = 3; stdio_count = 3;
err = -ENOMEM;
pipes = malloc(stdio_count * sizeof(*pipes)); pipes = malloc(stdio_count * sizeof(*pipes));
if (pipes == NULL) { if (pipes == NULL)
errno = ENOMEM;
goto error; goto error;
}
for (i = 0; i < stdio_count; i++) { for (i = 0; i < stdio_count; i++) {
pipes[i][0] = -1; pipes[i][0] = -1;
pipes[i][1] = -1; pipes[i][1] = -1;
} }
for (i = 0; i < options.stdio_count; i++) for (i = 0; i < options.stdio_count; i++) {
if (uv__process_init_stdio(options.stdio + i, pipes[i])) err = uv__process_init_stdio(options.stdio + i, pipes[i]);
if (err)
goto error; goto error;
}
/* This pipe is used by the parent to wait until /* This pipe is used by the parent to wait until
* the child has called `execve()`. We need this * the child has called `execve()`. We need this
@ -405,7 +402,8 @@ int uv_spawn(uv_loop_t* loop,
* marked close-on-exec. Then, after the call to `fork()`, * marked close-on-exec. Then, after the call to `fork()`,
* the parent polls the read end until it EOFs or errors with EPIPE. * the parent polls the read end until it EOFs or errors with EPIPE.
*/ */
if (uv__make_pipe(signal_pipe, 0)) err = uv__make_pipe(signal_pipe, 0);
if (err)
goto error; goto error;
uv_signal_start(&loop->child_watcher, uv__chld, SIGCHLD); uv_signal_start(&loop->child_watcher, uv__chld, SIGCHLD);
@ -413,6 +411,7 @@ int uv_spawn(uv_loop_t* loop,
pid = fork(); pid = fork();
if (pid == -1) { if (pid == -1) {
err = -errno;
close(signal_pipe[0]); close(signal_pipe[0]);
close(signal_pipe[1]); close(signal_pipe[1]);
goto error; goto error;
@ -442,10 +441,14 @@ int uv_spawn(uv_loop_t* loop,
close(signal_pipe[0]); close(signal_pipe[0]);
for (i = 0; i < options.stdio_count; i++) { for (i = 0; i < options.stdio_count; i++) {
if (uv__process_open_stream(options.stdio + i, pipes[i], i == 0)) { err = uv__process_open_stream(options.stdio + i, pipes[i], i == 0);
while (i--) uv__process_close_stream(options.stdio + i); if (err == 0)
goto error; continue;
}
while (i--)
uv__process_close_stream(options.stdio + i);
goto error;
} }
q = uv__process_queue(loop, pid); q = uv__process_queue(loop, pid);
@ -459,38 +462,26 @@ int uv_spawn(uv_loop_t* loop,
return 0; return 0;
error: error:
uv__set_sys_error(process->loop, errno);
for (i = 0; i < stdio_count; i++) { for (i = 0; i < stdio_count; i++) {
close(pipes[i][0]); close(pipes[i][0]);
close(pipes[i][1]); close(pipes[i][1]);
} }
free(pipes); free(pipes);
return -1; return err;
} }
int uv_process_kill(uv_process_t* process, int signum) { int uv_process_kill(uv_process_t* process, int signum) {
int r = kill(process->pid, signum); return uv_kill(process->pid, signum);
if (r) {
uv__set_sys_error(process->loop, errno);
return -1;
} else {
return 0;
}
} }
uv_err_t uv_kill(int pid, int signum) { int uv_kill(int pid, int signum) {
int r = kill(pid, signum); if (kill(pid, signum))
return -errno;
if (r) { else
return uv__new_sys_error(errno); return 0;
} else {
return uv_ok_;
}
} }

10
deps/uv/src/unix/proctitle.c

@ -74,25 +74,25 @@ char** uv_setup_args(int argc, char** argv) {
} }
uv_err_t uv_set_process_title(const char* title) { int uv_set_process_title(const char* title) {
if (process_title.len == 0) if (process_title.len == 0)
return uv_ok_; return 0;
/* No need to terminate, byte after is always '\0'. */ /* No need to terminate, byte after is always '\0'. */
strncpy(process_title.str, title, process_title.len); strncpy(process_title.str, title, process_title.len);
uv__set_process_title(title); uv__set_process_title(title);
return uv_ok_; return 0;
} }
uv_err_t uv_get_process_title(char* buffer, size_t size) { int uv_get_process_title(char* buffer, size_t size) {
if (process_title.len > 0) if (process_title.len > 0)
strncpy(buffer, process_title.str, size); strncpy(buffer, process_title.str, size);
else if (size > 0) else if (size > 0)
buffer[0] = '\0'; buffer[0] = '\0';
return uv_ok_; return 0;
} }

34
deps/uv/src/unix/signal.c

@ -171,7 +171,7 @@ static void uv__signal_handler(int signum) {
} }
static uv_err_t uv__signal_register_handler(int signum) { static int uv__signal_register_handler(int signum) {
/* When this function is called, the signal lock must be held. */ /* When this function is called, the signal lock must be held. */
struct sigaction sa; struct sigaction sa;
@ -183,9 +183,9 @@ static uv_err_t uv__signal_register_handler(int signum) {
/* XXX save old action so we can restore it later on? */ /* XXX save old action so we can restore it later on? */
if (sigaction(signum, &sa, NULL)) if (sigaction(signum, &sa, NULL))
return uv__new_sys_error(errno); return -errno;
return uv_ok_; return 0;
} }
@ -206,12 +206,15 @@ static void uv__signal_unregister_handler(int signum) {
static int uv__signal_loop_once_init(uv_loop_t* loop) { static int uv__signal_loop_once_init(uv_loop_t* loop) {
int err;
/* Return if already initialized. */ /* Return if already initialized. */
if (loop->signal_pipefd[0] != -1) if (loop->signal_pipefd[0] != -1)
return 0; return 0;
if (uv__make_pipe(loop->signal_pipefd, UV__F_NONBLOCK)) err = uv__make_pipe(loop->signal_pipefd, UV__F_NONBLOCK);
return -1; if (err)
return err;
uv__io_init(&loop->signal_io_watcher, uv__io_init(&loop->signal_io_watcher,
uv__signal_event, uv__signal_event,
@ -249,8 +252,11 @@ void uv__signal_loop_cleanup(uv_loop_t* loop) {
int uv_signal_init(uv_loop_t* loop, uv_signal_t* handle) { int uv_signal_init(uv_loop_t* loop, uv_signal_t* handle) {
if (uv__signal_loop_once_init(loop)) int err;
return uv__set_sys_error(loop, errno);
err = uv__signal_loop_once_init(loop);
if (err)
return err;
uv__handle_init(loop, (uv_handle_t*) handle, UV_SIGNAL); uv__handle_init(loop, (uv_handle_t*) handle, UV_SIGNAL);
handle->signum = 0; handle->signum = 0;
@ -277,6 +283,7 @@ void uv__signal_close(uv_signal_t* handle) {
int uv_signal_start(uv_signal_t* handle, uv_signal_cb signal_cb, int signum) { int uv_signal_start(uv_signal_t* handle, uv_signal_cb signal_cb, int signum) {
sigset_t saved_sigmask; sigset_t saved_sigmask;
int err;
assert(!(handle->flags & (UV_CLOSING | UV_CLOSED))); assert(!(handle->flags & (UV_CLOSING | UV_CLOSED)));
@ -284,10 +291,8 @@ int uv_signal_start(uv_signal_t* handle, uv_signal_cb signal_cb, int signum) {
* signum is otherwise invalid then uv__signal_register will find out * signum is otherwise invalid then uv__signal_register will find out
* eventually. * eventually.
*/ */
if (signum == 0) { if (signum == 0)
uv__set_artificial_error(handle->loop, UV_EINVAL); return -EINVAL;
return -1;
}
/* Short circuit: if the signal watcher is already watching {signum} don't /* Short circuit: if the signal watcher is already watching {signum} don't
* go through the process of deregistering and registering the handler. * go through the process of deregistering and registering the handler.
@ -310,12 +315,11 @@ int uv_signal_start(uv_signal_t* handle, uv_signal_cb signal_cb, int signum) {
* any of the loops), it's time to try and register a handler for it here. * any of the loops), it's time to try and register a handler for it here.
*/ */
if (uv__signal_first_handle(signum) == NULL) { if (uv__signal_first_handle(signum) == NULL) {
uv_err_t err = uv__signal_register_handler(signum); err = uv__signal_register_handler(signum);
if (err.code != UV_OK) { if (err) {
/* Registering the signal handler failed. Must be an invalid signal. */ /* Registering the signal handler failed. Must be an invalid signal. */
handle->loop->last_err = err;
uv__signal_unlock_and_unblock(&saved_sigmask); uv__signal_unlock_and_unblock(&saved_sigmask);
return -1; return err;
} }
} }

176
deps/uv/src/unix/stream.c

@ -65,6 +65,7 @@ static size_t uv__write_req_size(uv_write_t* req);
/* Used by the accept() EMFILE party trick. */ /* Used by the accept() EMFILE party trick. */
static int uv__open_cloexec(const char* path, int flags) { static int uv__open_cloexec(const char* path, int flags) {
int err;
int fd; int fd;
#if defined(__linux__) #if defined(__linux__)
@ -73,14 +74,20 @@ static int uv__open_cloexec(const char* path, int flags) {
return fd; return fd;
if (errno != EINVAL) if (errno != EINVAL)
return -1; return -errno;
/* O_CLOEXEC not supported. */ /* O_CLOEXEC not supported. */
#endif #endif
fd = open(path, flags); fd = open(path, flags);
if (fd != -1) if (fd == -1)
uv__cloexec(fd, 1); return -errno;
err = uv__cloexec(fd, 1);
if (err) {
close(fd);
return err;
}
return fd; return fd;
} }
@ -101,6 +108,8 @@ static size_t uv__buf_count(uv_buf_t bufs[], int bufcnt) {
void uv__stream_init(uv_loop_t* loop, void uv__stream_init(uv_loop_t* loop,
uv_stream_t* stream, uv_stream_t* stream,
uv_handle_type type) { uv_handle_type type) {
int err;
uv__handle_init(loop, (uv_handle_t*)stream, type); uv__handle_init(loop, (uv_handle_t*)stream, type);
stream->read_cb = NULL; stream->read_cb = NULL;
stream->read2_cb = NULL; stream->read2_cb = NULL;
@ -115,8 +124,11 @@ void uv__stream_init(uv_loop_t* loop,
QUEUE_INIT(&stream->write_completed_queue); QUEUE_INIT(&stream->write_completed_queue);
stream->write_queue_size = 0; stream->write_queue_size = 0;
if (loop->emfile_fd == -1) if (loop->emfile_fd == -1) {
loop->emfile_fd = uv__open_cloexec("/", O_RDONLY); err = uv__open_cloexec("/", O_RDONLY);
if (err >= 0)
loop->emfile_fd = err;
}
#if defined(__APPLE__) #if defined(__APPLE__)
stream->select = NULL; stream->select = NULL;
@ -280,13 +292,14 @@ int uv__stream_try_select(uv_stream_t* stream, int* fd) {
struct timespec timeout; struct timespec timeout;
uv__stream_select_t* s; uv__stream_select_t* s;
int fds[2]; int fds[2];
int err;
int ret; int ret;
int kq; int kq;
kq = kqueue(); kq = kqueue();
if (kq == -1) { if (kq == -1) {
fprintf(stderr, "(libuv) Failed to create kqueue (%d)\n", errno); fprintf(stderr, "(libuv) Failed to create kqueue (%d)\n", errno);
return uv__set_sys_error(stream->loop, errno); return -errno;
} }
EV_SET(&filter[0], *fd, EVFILT_READ, EV_ADD | EV_ENABLE, 0, 0, 0); EV_SET(&filter[0], *fd, EVFILT_READ, EV_ADD | EV_ENABLE, 0, 0, 0);
@ -299,7 +312,7 @@ int uv__stream_try_select(uv_stream_t* stream, int* fd) {
SAVE_ERRNO(close(kq)); SAVE_ERRNO(close(kq));
if (ret == -1) if (ret == -1)
return uv__set_sys_error(stream->loop, errno); return -errno;
if (ret == 0 || (events[0].flags & EV_ERROR) == 0 || events[0].data != EINVAL) if (ret == 0 || (events[0].flags & EV_ERROR) == 0 || events[0].data != EINVAL)
return 0; return 0;
@ -307,14 +320,15 @@ int uv__stream_try_select(uv_stream_t* stream, int* fd) {
/* At this point we definitely know that this fd won't work with kqueue */ /* At this point we definitely know that this fd won't work with kqueue */
s = malloc(sizeof(*s)); s = malloc(sizeof(*s));
if (s == NULL) if (s == NULL)
return uv__set_artificial_error(stream->loop, UV_ENOMEM); return -ENOMEM;
s->events = 0; s->events = 0;
s->fd = *fd; s->fd = *fd;
if (uv_async_init(stream->loop, &s->async, uv__stream_osx_select_cb)) { err = uv_async_init(stream->loop, &s->async, uv__stream_osx_select_cb);
SAVE_ERRNO(free(s)); if (err) {
return uv__set_sys_error(stream->loop, errno); free(s);
return err;
} }
s->async.flags |= UV__HANDLE_INTERNAL; s->async.flags |= UV__HANDLE_INTERNAL;
@ -353,7 +367,7 @@ fatal2:
uv_sem_destroy(&s->close_sem); uv_sem_destroy(&s->close_sem);
fatal1: fatal1:
uv_close((uv_handle_t*) &s->async, uv__stream_osx_cb_close); uv_close((uv_handle_t*) &s->async, uv__stream_osx_cb_close);
return uv__set_sys_error(stream->loop, errno); return -errno;
} }
#endif /* defined(__APPLE__) */ #endif /* defined(__APPLE__) */
@ -364,11 +378,11 @@ int uv__stream_open(uv_stream_t* stream, int fd, int flags) {
if (stream->type == UV_TCP) { if (stream->type == UV_TCP) {
if ((stream->flags & UV_TCP_NODELAY) && uv__tcp_nodelay(fd, 1)) if ((stream->flags & UV_TCP_NODELAY) && uv__tcp_nodelay(fd, 1))
return uv__set_sys_error(stream->loop, errno); return -errno;
/* TODO Use delay the user passed in. */ /* TODO Use delay the user passed in. */
if ((stream->flags & UV_TCP_KEEPALIVE) && uv__tcp_keepalive(fd, 1, 60)) if ((stream->flags & UV_TCP_KEEPALIVE) && uv__tcp_keepalive(fd, 1, 60))
return uv__set_sys_error(stream->loop, errno); return -errno;
} }
stream->io_watcher.fd = fd; stream->io_watcher.fd = fd;
@ -386,8 +400,7 @@ void uv__stream_destroy(uv_stream_t* stream) {
if (stream->connect_req) { if (stream->connect_req) {
uv__req_unregister(stream->loop, stream->connect_req); uv__req_unregister(stream->loop, stream->connect_req);
uv__set_artificial_error(stream->loop, UV_ECANCELED); stream->connect_req->cb(stream->connect_req, -ECANCELED);
stream->connect_req->cb(stream->connect_req, -1);
stream->connect_req = NULL; stream->connect_req = NULL;
} }
@ -402,10 +415,8 @@ void uv__stream_destroy(uv_stream_t* stream) {
free(req->bufs); free(req->bufs);
req->bufs = NULL; req->bufs = NULL;
if (req->cb) { if (req->cb != NULL)
uv__set_artificial_error(req->handle->loop, UV_ECANCELED); req->cb(req, -ECANCELED);
req->cb(req, -1);
}
} }
while (!QUEUE_EMPTY(&stream->write_completed_queue)) { while (!QUEUE_EMPTY(&stream->write_completed_queue)) {
@ -422,21 +433,18 @@ void uv__stream_destroy(uv_stream_t* stream) {
req->bufs = NULL; req->bufs = NULL;
} }
if (req->cb) { if (req->cb)
uv__set_sys_error(stream->loop, req->error); req->cb(req, req->error);
req->cb(req, req->error ? -1 : 0);
}
} }
if (stream->shutdown_req) { if (stream->shutdown_req) {
/* The UV_ECANCELED error code is a lie, the shutdown(2) syscall is a /* The ECANCELED error code is a lie, the shutdown(2) syscall is a
* fait accompli at this point. Maybe we should revisit this in v0.11. * fait accompli at this point. Maybe we should revisit this in v0.11.
* A possible reason for leaving it unchanged is that it informs the * A possible reason for leaving it unchanged is that it informs the
* callee that the handle has been destroyed. * callee that the handle has been destroyed.
*/ */
uv__req_unregister(stream->loop, stream->shutdown_req); uv__req_unregister(stream->loop, stream->shutdown_req);
uv__set_artificial_error(stream->loop, UV_ECANCELED); stream->shutdown_req->cb(stream->shutdown_req, -ECANCELED);
stream->shutdown_req->cb(stream->shutdown_req, -1);
stream->shutdown_req = NULL; stream->shutdown_req = NULL;
} }
} }
@ -457,7 +465,7 @@ static int uv__emfile_trick(uv_loop_t* loop, int accept_fd) {
int fd; int fd;
if (loop->emfile_fd == -1) if (loop->emfile_fd == -1)
return -1; return -EMFILE;
close(loop->emfile_fd); close(loop->emfile_fd);
@ -473,7 +481,7 @@ static int uv__emfile_trick(uv_loop_t* loop, int accept_fd) {
continue; continue;
SAVE_ERRNO(loop->emfile_fd = uv__open_cloexec("/", O_RDONLY)); SAVE_ERRNO(loop->emfile_fd = uv__open_cloexec("/", O_RDONLY));
return errno; return -errno;
} }
} }
@ -488,7 +496,6 @@ static int uv__emfile_trick(uv_loop_t* loop, int accept_fd) {
void uv__server_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) { void uv__server_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
uv_stream_t* stream; uv_stream_t* stream;
int err; int err;
int fd;
stream = container_of(w, uv_stream_t, io_watcher); stream = container_of(w, uv_stream_t, io_watcher);
assert(events == UV__POLLIN); assert(events == UV__POLLIN);
@ -508,27 +515,26 @@ void uv__server_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
return; return;
#endif /* defined(UV_HAVE_KQUEUE) */ #endif /* defined(UV_HAVE_KQUEUE) */
fd = uv__accept(uv__stream_fd(stream)); err = uv__accept(uv__stream_fd(stream));
if (fd == -1) { if (err < 0) {
if (errno == EAGAIN || errno == EWOULDBLOCK) if (err == -EAGAIN || err == -EWOULDBLOCK)
return; /* Not an error. */ return; /* Not an error. */
if (errno == ECONNABORTED) if (err == -ECONNABORTED)
continue; /* Ignore. Nothing we can do about that. */ continue; /* Ignore. Nothing we can do about that. */
if (errno == EMFILE || errno == ENFILE) { if (err == -EMFILE || err == -ENFILE) {
SAVE_ERRNO(err = uv__emfile_trick(loop, uv__stream_fd(stream))); err = uv__emfile_trick(loop, uv__stream_fd(stream));
if (err == EAGAIN || err == EWOULDBLOCK) if (err == -EAGAIN || err == -EWOULDBLOCK)
break; break;
} }
uv__set_sys_error(loop, errno); stream->connection_cb(stream, err);
stream->connection_cb(stream, -1);
continue; continue;
} }
UV_DEC_BACKLOG(w) UV_DEC_BACKLOG(w)
stream->accepted_fd = fd; stream->accepted_fd = err;
stream->connection_cb(stream, 0); stream->connection_cb(stream, 0);
if (stream->accepted_fd != -1) { if (stream->accepted_fd != -1) {
@ -550,30 +556,34 @@ void uv__server_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
int uv_accept(uv_stream_t* server, uv_stream_t* client) { int uv_accept(uv_stream_t* server, uv_stream_t* client) {
int err;
/* TODO document this */ /* TODO document this */
assert(server->loop == client->loop); assert(server->loop == client->loop);
if (server->accepted_fd == -1) if (server->accepted_fd == -1)
return uv__set_sys_error(server->loop, EAGAIN); return -EAGAIN;
switch (client->type) { switch (client->type) {
case UV_NAMED_PIPE: case UV_NAMED_PIPE:
case UV_TCP: case UV_TCP:
if (uv__stream_open(client, err = uv__stream_open(client,
server->accepted_fd, server->accepted_fd,
UV_STREAM_READABLE | UV_STREAM_WRITABLE)) { UV_STREAM_READABLE | UV_STREAM_WRITABLE);
if (err) {
/* TODO handle error */ /* TODO handle error */
close(server->accepted_fd); close(server->accepted_fd);
server->accepted_fd = -1; server->accepted_fd = -1;
return -1; return err;
} }
break; break;
case UV_UDP: case UV_UDP:
if (uv_udp_open((uv_udp_t*) client, server->accepted_fd)) { err = uv_udp_open((uv_udp_t*) client, server->accepted_fd);
if (err) {
close(server->accepted_fd); close(server->accepted_fd);
server->accepted_fd = -1; server->accepted_fd = -1;
return -1; return err;
} }
break; break;
@ -588,32 +598,32 @@ int uv_accept(uv_stream_t* server, uv_stream_t* client) {
int uv_listen(uv_stream_t* stream, int backlog, uv_connection_cb cb) { int uv_listen(uv_stream_t* stream, int backlog, uv_connection_cb cb) {
int r; int err;
err = -EINVAL;
switch (stream->type) { switch (stream->type) {
case UV_TCP: case UV_TCP:
r = uv_tcp_listen((uv_tcp_t*)stream, backlog, cb); err = uv_tcp_listen((uv_tcp_t*)stream, backlog, cb);
break; break;
case UV_NAMED_PIPE: case UV_NAMED_PIPE:
r = uv_pipe_listen((uv_pipe_t*)stream, backlog, cb); err = uv_pipe_listen((uv_pipe_t*)stream, backlog, cb);
break; break;
default: default:
assert(0); assert(0);
return -1;
} }
if (r == 0) if (err == 0)
uv__handle_start(stream); uv__handle_start(stream);
return r; return err;
} }
static void uv__drain(uv_stream_t* stream) { static void uv__drain(uv_stream_t* stream) {
uv_shutdown_t* req; uv_shutdown_t* req;
int status; int err;
assert(QUEUE_EMPTY(&stream->write_queue)); assert(QUEUE_EMPTY(&stream->write_queue));
uv__io_stop(stream->loop, &stream->io_watcher, UV__POLLOUT); uv__io_stop(stream->loop, &stream->io_watcher, UV__POLLOUT);
@ -629,14 +639,15 @@ static void uv__drain(uv_stream_t* stream) {
stream->flags &= ~UV_STREAM_SHUTTING; stream->flags &= ~UV_STREAM_SHUTTING;
uv__req_unregister(stream->loop, req); uv__req_unregister(stream->loop, req);
status = shutdown(uv__stream_fd(stream), SHUT_WR); err = 0;
if (status) if (shutdown(uv__stream_fd(stream), SHUT_WR))
uv__set_sys_error(stream->loop, errno); err = -errno;
else
if (err == 0)
stream->flags |= UV_STREAM_SHUT; stream->flags |= UV_STREAM_SHUT;
if (req->cb != NULL) if (req->cb != NULL)
req->cb(req, status); req->cb(req, err);
} }
} }
@ -791,7 +802,7 @@ start:
if (n < 0) { if (n < 0) {
if (errno != EAGAIN && errno != EWOULDBLOCK) { if (errno != EAGAIN && errno != EWOULDBLOCK) {
/* Error */ /* Error */
req->error = errno; req->error = -errno;
uv__write_req_finish(req); uv__write_req_finish(req);
uv__io_stop(stream->loop, &stream->io_watcher, UV__POLLOUT); uv__io_stop(stream->loop, &stream->io_watcher, UV__POLLOUT);
if (!uv__io_active(&stream->io_watcher, UV__POLLIN)) if (!uv__io_active(&stream->io_watcher, UV__POLLIN))
@ -879,10 +890,8 @@ static void uv__write_callbacks(uv_stream_t* stream) {
} }
/* NOTE: call callback AFTER freeing the request data. */ /* NOTE: call callback AFTER freeing the request data. */
if (req->cb) { if (req->cb)
uv__set_sys_error(stream->loop, req->error); req->cb(req, req->error);
req->cb(req, req->error ? -1 : 0);
}
} }
assert(QUEUE_EMPTY(&stream->write_completed_queue)); assert(QUEUE_EMPTY(&stream->write_completed_queue));
@ -943,8 +952,7 @@ static void uv__stream_eof(uv_stream_t* stream, uv_buf_t buf) {
uv__io_stop(stream->loop, &stream->io_watcher, UV__POLLIN); uv__io_stop(stream->loop, &stream->io_watcher, UV__POLLIN);
if (!uv__io_active(&stream->io_watcher, UV__POLLOUT)) if (!uv__io_active(&stream->io_watcher, UV__POLLOUT))
uv__handle_stop(stream); uv__handle_stop(stream);
uv__set_artificial_error(stream->loop, UV_EOF); uv__stream_read_cb(stream, UV_EOF, buf, UV_UNKNOWN_HANDLE);
uv__stream_read_cb(stream, -1, buf, UV_UNKNOWN_HANDLE);
} }
@ -1006,12 +1014,10 @@ static void uv__read(uv_stream_t* stream) {
if (stream->flags & UV_STREAM_READING) { if (stream->flags & UV_STREAM_READING) {
uv__io_start(stream->loop, &stream->io_watcher, UV__POLLIN); uv__io_start(stream->loop, &stream->io_watcher, UV__POLLIN);
} }
uv__set_sys_error(stream->loop, EAGAIN);
uv__stream_read_cb(stream, 0, buf, UV_UNKNOWN_HANDLE); uv__stream_read_cb(stream, 0, buf, UV_UNKNOWN_HANDLE);
} else { } else {
/* Error. User should call uv_close(). */ /* Error. User should call uv_close(). */
uv__set_sys_error(stream->loop, errno); uv__stream_read_cb(stream, -errno, buf, UV_UNKNOWN_HANDLE);
uv__stream_read_cb(stream, -1, buf, UV_UNKNOWN_HANDLE);
assert(!uv__io_active(&stream->io_watcher, UV__POLLIN) && assert(!uv__io_active(&stream->io_watcher, UV__POLLIN) &&
"stream->read_cb(status=-1) did not call uv_close()"); "stream->read_cb(status=-1) did not call uv_close()");
} }
@ -1085,8 +1091,7 @@ int uv_shutdown(uv_shutdown_t* req, uv_stream_t* stream, uv_shutdown_cb cb) {
stream->flags & UV_STREAM_SHUT || stream->flags & UV_STREAM_SHUT ||
stream->flags & UV_CLOSED || stream->flags & UV_CLOSED ||
stream->flags & UV_CLOSING) { stream->flags & UV_CLOSING) {
uv__set_artificial_error(stream->loop, UV_ENOTCONN); return -ENOTCONN;
return -1;
} }
/* Initialize request */ /* Initialize request */
@ -1178,19 +1183,18 @@ static void uv__stream_connect(uv_stream_t* stream) {
SO_ERROR, SO_ERROR,
&error, &error,
&errorsize); &errorsize);
error = -error;
} }
if (error == EINPROGRESS) if (error == -EINPROGRESS)
return; return;
stream->connect_req = NULL; stream->connect_req = NULL;
uv__req_unregister(stream->loop, req); uv__req_unregister(stream->loop, req);
uv__io_stop(stream->loop, &stream->io_watcher, UV__POLLOUT); uv__io_stop(stream->loop, &stream->io_watcher, UV__POLLOUT);
if (req->cb) { if (req->cb)
uv__set_sys_error(stream->loop, error); req->cb(req, error);
req->cb(req, error ? -1 : 0);
}
} }
@ -1209,11 +1213,11 @@ int uv_write2(uv_write_t* req,
"uv_write (unix) does not yet support other types of streams"); "uv_write (unix) does not yet support other types of streams");
if (uv__stream_fd(stream) < 0) if (uv__stream_fd(stream) < 0)
return uv__set_artificial_error(stream->loop, UV_EBADF); return -EBADF;
if (send_handle) { if (send_handle) {
if (stream->type != UV_NAMED_PIPE || !((uv_pipe_t*)stream)->ipc) if (stream->type != UV_NAMED_PIPE || !((uv_pipe_t*)stream)->ipc)
return uv__set_artificial_error(stream->loop, UV_EINVAL); return -EINVAL;
/* XXX We abuse uv_write2() to send over UDP handles to child processes. /* XXX We abuse uv_write2() to send over UDP handles to child processes.
* Don't call uv__stream_fd() on those handles, it's a macro that on OS X * Don't call uv__stream_fd() on those handles, it's a macro that on OS X
@ -1222,7 +1226,7 @@ int uv_write2(uv_write_t* req,
* which works but only by accident. * which works but only by accident.
*/ */
if (uv__handle_fd((uv_handle_t*) send_handle) < 0) if (uv__handle_fd((uv_handle_t*) send_handle) < 0)
return uv__set_artificial_error(stream->loop, UV_EBADF); return -EBADF;
} }
/* It's legal for write_queue_size > 0 even when the write_queue is empty; /* It's legal for write_queue_size > 0 even when the write_queue is empty;
@ -1295,7 +1299,7 @@ static int uv__read_start_common(uv_stream_t* stream,
stream->type == UV_TTY); stream->type == UV_TTY);
if (stream->flags & UV_CLOSING) if (stream->flags & UV_CLOSING)
return uv__set_sys_error(stream->loop, EINVAL); return -EINVAL;
/* The UV_STREAM_READING flag is irrelevant of the state of the tcp - it just /* The UV_STREAM_READING flag is irrelevant of the state of the tcp - it just
* expresses the desired state of the user. * expresses the desired state of the user.

125
deps/uv/src/unix/sunos.c

@ -62,13 +62,22 @@
int uv__platform_loop_init(uv_loop_t* loop, int default_loop) { int uv__platform_loop_init(uv_loop_t* loop, int default_loop) {
int err;
int fd;
loop->fs_fd = -1; loop->fs_fd = -1;
loop->backend_fd = port_create(); loop->backend_fd = -1;
if (loop->backend_fd == -1) fd = port_create();
return -1; if (fd == -1)
return -errno;
uv__cloexec(loop->backend_fd, 1); err = uv__cloexec(fd, 1);
if (err) {
close(fd);
return err;
}
loop->backend_fd = fd;
return 0; return 0;
} }
@ -243,21 +252,17 @@ int uv_exepath(char* buffer, size_t* size) {
ssize_t res; ssize_t res;
char buf[128]; char buf[128];
if (buffer == NULL) if (buffer == NULL || size == NULL)
return (-1); return -EINVAL;
if (size == NULL)
return (-1);
(void) snprintf(buf, sizeof(buf), "/proc/%lu/path/a.out", (unsigned long) getpid()); (void) snprintf(buf, sizeof(buf), "/proc/%lu/path/a.out", (unsigned long) getpid());
res = readlink(buf, buffer, *size - 1); res = readlink(buf, buffer, *size - 1);
if (res == -1)
if (res < 0) return -errno;
return (res);
buffer[res] = '\0'; buffer[res] = '\0';
*size = res; *size = res;
return (0); return 0;
} }
@ -278,18 +283,20 @@ void uv_loadavg(double avg[3]) {
#if defined(PORT_SOURCE_FILE) #if defined(PORT_SOURCE_FILE)
static void uv__fs_event_rearm(uv_fs_event_t *handle) { static int uv__fs_event_rearm(uv_fs_event_t *handle) {
if (handle->fd == -1) if (handle->fd == -1)
return; return -EBADF;
if (port_associate(handle->loop->fs_fd, if (port_associate(handle->loop->fs_fd,
PORT_SOURCE_FILE, PORT_SOURCE_FILE,
(uintptr_t) &handle->fo, (uintptr_t) &handle->fo,
FILE_ATTRIB | FILE_MODIFIED, FILE_ATTRIB | FILE_MODIFIED,
handle) == -1) { handle) == -1) {
uv__set_sys_error(handle->loop, errno); return -errno;
} }
handle->fd = PORT_LOADED; handle->fd = PORT_LOADED;
return 0;
} }
@ -340,7 +347,7 @@ static void uv__fs_event_read(uv_loop_t* loop,
while (handle->fd != PORT_DELETED); while (handle->fd != PORT_DELETED);
if (handle != NULL && handle->fd != PORT_DELETED) if (handle != NULL && handle->fd != PORT_DELETED)
uv__fs_event_rearm(handle); uv__fs_event_rearm(handle); /* FIXME(bnoordhuis) Check return code. */
} }
@ -353,10 +360,9 @@ int uv_fs_event_init(uv_loop_t* loop,
int first_run = 0; int first_run = 0;
if (loop->fs_fd == -1) { if (loop->fs_fd == -1) {
if ((portfd = port_create()) == -1) { portfd = port_create();
uv__set_sys_error(loop, errno); if (portfd == -1)
return -1; return -errno;
}
loop->fs_fd = portfd; loop->fs_fd = portfd;
first_run = 1; first_run = 1;
} }
@ -369,7 +375,7 @@ int uv_fs_event_init(uv_loop_t* loop,
memset(&handle->fo, 0, sizeof handle->fo); memset(&handle->fo, 0, sizeof handle->fo);
handle->fo.fo_name = handle->filename; handle->fo.fo_name = handle->filename;
uv__fs_event_rearm(handle); uv__fs_event_rearm(handle); /* FIXME(bnoordhuis) Check return code. */
if (first_run) { if (first_run) {
uv__io_init(&loop->fs_event_watcher, uv__fs_event_read, portfd); uv__io_init(&loop->fs_event_watcher, uv__fs_event_read, portfd);
@ -398,8 +404,7 @@ int uv_fs_event_init(uv_loop_t* loop,
const char* filename, const char* filename,
uv_fs_event_cb cb, uv_fs_event_cb cb,
int flags) { int flags) {
uv__set_sys_error(loop, ENOSYS); return -ENOSYS;
return -1;
} }
@ -415,76 +420,74 @@ char** uv_setup_args(int argc, char** argv) {
} }
uv_err_t uv_set_process_title(const char* title) { int uv_set_process_title(const char* title) {
return uv_ok_; return 0;
} }
uv_err_t uv_get_process_title(char* buffer, size_t size) { int uv_get_process_title(char* buffer, size_t size) {
if (size > 0) { if (size > 0) {
buffer[0] = '\0'; buffer[0] = '\0';
} }
return uv_ok_; return 0;
} }
uv_err_t uv_resident_set_memory(size_t* rss) { int uv_resident_set_memory(size_t* rss) {
psinfo_t psinfo; psinfo_t psinfo;
uv_err_t err; int err;
int fd; int fd;
fd = open("/proc/self/psinfo", O_RDONLY); fd = open("/proc/self/psinfo", O_RDONLY);
if (fd == -1) if (fd == -1)
return uv__new_sys_error(errno); return -errno;
err = uv_ok_;
if (read(fd, &psinfo, sizeof(psinfo)) == sizeof(psinfo)) /* FIXME(bnoordhuis) Handle EINTR. */
err = -EINVAL;
if (read(fd, &psinfo, sizeof(psinfo)) == sizeof(psinfo)) {
*rss = (size_t)psinfo.pr_rssize * 1024; *rss = (size_t)psinfo.pr_rssize * 1024;
else err = 0;
err = uv__new_sys_error(EINVAL); }
close(fd); close(fd);
return err; return err;
} }
uv_err_t uv_uptime(double* uptime) { int uv_uptime(double* uptime) {
kstat_ctl_t *kc; kstat_ctl_t *kc;
kstat_t *ksp; kstat_t *ksp;
kstat_named_t *knp; kstat_named_t *knp;
long hz = sysconf(_SC_CLK_TCK); long hz = sysconf(_SC_CLK_TCK);
if ((kc = kstat_open()) == NULL) kc = kstat_open();
return uv__new_sys_error(errno); if (kc == NULL)
return -EPERM;
ksp = kstat_lookup(kc, (char*) "unix", 0, (char*) "system_misc"); ksp = kstat_lookup(kc, (char*) "unix", 0, (char*) "system_misc");
if (kstat_read(kc, ksp, NULL) == -1) { if (kstat_read(kc, ksp, NULL) == -1) {
*uptime = -1; *uptime = -1;
} else { } else {
knp = (kstat_named_t*) kstat_data_lookup(ksp, (char*) "clk_intr"); knp = (kstat_named_t*) kstat_data_lookup(ksp, (char*) "clk_intr");
*uptime = knp->value.ul / hz; *uptime = knp->value.ul / hz;
} }
kstat_close(kc); kstat_close(kc);
return uv_ok_; return 0;
} }
uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
int lookup_instance; int lookup_instance;
kstat_ctl_t *kc; kstat_ctl_t *kc;
kstat_t *ksp; kstat_t *ksp;
kstat_named_t *knp; kstat_named_t *knp;
uv_cpu_info_t* cpu_info; uv_cpu_info_t* cpu_info;
if ((kc = kstat_open()) == NULL) { kc = kstat_open();
return uv__new_sys_error(errno); if (kc == NULL)
} return -EPERM;
/* Get count of cpus */ /* Get count of cpus */
lookup_instance = 0; lookup_instance = 0;
@ -492,10 +495,10 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
lookup_instance++; lookup_instance++;
} }
*cpu_infos = (uv_cpu_info_t*) *cpu_infos = malloc(lookup_instance * sizeof(**cpu_infos));
malloc(lookup_instance * sizeof(uv_cpu_info_t));
if (!(*cpu_infos)) { if (!(*cpu_infos)) {
return uv__new_artificial_error(UV_ENOMEM); kstat_close(kc);
return -ENOMEM;
} }
*count = lookup_instance; *count = lookup_instance;
@ -557,7 +560,7 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
kstat_close(kc); kstat_close(kc);
return uv_ok_; return 0;
} }
@ -572,18 +575,16 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
} }
uv_err_t uv_interface_addresses(uv_interface_address_t** addresses, int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
int* count) {
#ifdef SUNOS_NO_IFADDRS #ifdef SUNOS_NO_IFADDRS
return uv__new_artificial_error(UV_ENOSYS); return -ENOSYS;
#else #else
struct ifaddrs *addrs, *ent; struct ifaddrs *addrs, *ent;
char ip[INET6_ADDRSTRLEN]; char ip[INET6_ADDRSTRLEN];
uv_interface_address_t* address; uv_interface_address_t* address;
if (getifaddrs(&addrs) != 0) { if (getifaddrs(&addrs))
return uv__new_sys_error(errno); return -errno;
}
*count = 0; *count = 0;
@ -598,11 +599,9 @@ uv_err_t uv_interface_addresses(uv_interface_address_t** addresses,
(*count)++; (*count)++;
} }
*addresses = (uv_interface_address_t*) *addresses = malloc(*count * sizeof(**addresses));
malloc(*count * sizeof(uv_interface_address_t)); if (!(*addresses))
if (!(*addresses)) { return -ENOMEM;
return uv__new_artificial_error(UV_ENOMEM);
}
address = *addresses; address = *addresses;
@ -639,7 +638,7 @@ uv_err_t uv_interface_addresses(uv_interface_address_t** addresses,
freeifaddrs(addrs); freeifaddrs(addrs);
return uv_ok_; return 0;
#endif /* SUNOS_NO_IFADDRS */ #endif /* SUNOS_NO_IFADDRS */
} }

98
deps/uv/src/unix/tcp.c

@ -36,18 +36,20 @@ int uv_tcp_init(uv_loop_t* loop, uv_tcp_t* tcp) {
static int maybe_new_socket(uv_tcp_t* handle, int domain, int flags) { static int maybe_new_socket(uv_tcp_t* handle, int domain, int flags) {
int sockfd; int sockfd;
int err;
if (uv__stream_fd(handle) != -1) if (uv__stream_fd(handle) != -1)
return 0; return 0;
sockfd = uv__socket(domain, SOCK_STREAM, 0); err = uv__socket(domain, SOCK_STREAM, 0);
if (err < 0)
return err;
sockfd = err;
if (sockfd == -1) err = uv__stream_open((uv_stream_t*) handle, sockfd, flags);
return uv__set_sys_error(handle->loop, errno); if (err) {
if (uv__stream_open((uv_stream_t*)handle, sockfd, flags)) {
close(sockfd); close(sockfd);
return -1; return err;
} }
return 0; return 0;
@ -58,20 +60,22 @@ static int uv__bind(uv_tcp_t* tcp,
int domain, int domain,
struct sockaddr* addr, struct sockaddr* addr,
int addrsize) { int addrsize) {
int err;
int on; int on;
if (maybe_new_socket(tcp, domain, UV_STREAM_READABLE|UV_STREAM_WRITABLE)) err = maybe_new_socket(tcp, domain, UV_STREAM_READABLE | UV_STREAM_WRITABLE);
return -1; if (err)
return err;
on = 1; on = 1;
if (setsockopt(tcp->io_watcher.fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on))) if (setsockopt(tcp->io_watcher.fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)))
return uv__set_sys_error(tcp->loop, errno); return -errno;
errno = 0; errno = 0;
if (bind(tcp->io_watcher.fd, addr, addrsize) && errno != EADDRINUSE) if (bind(tcp->io_watcher.fd, addr, addrsize) && errno != EADDRINUSE)
return uv__set_sys_error(tcp->loop, errno); return -errno;
tcp->delayed_error = errno; tcp->delayed_error = -errno;
return 0; return 0;
} }
@ -81,18 +85,19 @@ static int uv__connect(uv_connect_t* req,
struct sockaddr* addr, struct sockaddr* addr,
socklen_t addrlen, socklen_t addrlen,
uv_connect_cb cb) { uv_connect_cb cb) {
int err;
int r; int r;
assert(handle->type == UV_TCP); assert(handle->type == UV_TCP);
if (handle->connect_req) if (handle->connect_req != NULL)
return uv__set_sys_error(handle->loop, EALREADY); return -EALREADY; /* FIXME(bnoordhuis) -EINVAL or maybe -EBUSY. */
if (maybe_new_socket(handle, err = maybe_new_socket(handle,
addr->sa_family, addr->sa_family,
UV_STREAM_READABLE|UV_STREAM_WRITABLE)) { UV_STREAM_READABLE | UV_STREAM_WRITABLE);
return -1; if (err)
} return err;
handle->delayed_error = 0; handle->delayed_error = 0;
@ -108,9 +113,9 @@ static int uv__connect(uv_connect_t* req,
* error. Solaris wants to report immediately--other unixes want to * error. Solaris wants to report immediately--other unixes want to
* wait. * wait.
*/ */
handle->delayed_error = errno; handle->delayed_error = -errno;
else else
return uv__set_sys_error(handle->loop, errno); return -errno;
} }
uv__req_init(handle->loop, req, UV_CONNECT); uv__req_init(handle->loop, req, UV_CONNECT);
@ -157,16 +162,16 @@ int uv_tcp_getsockname(uv_tcp_t* handle,
socklen_t socklen; socklen_t socklen;
if (handle->delayed_error) if (handle->delayed_error)
return uv__set_sys_error(handle->loop, handle->delayed_error); return handle->delayed_error;
if (uv__stream_fd(handle) < 0) if (uv__stream_fd(handle) < 0)
return uv__set_sys_error(handle->loop, EINVAL); return -EINVAL; /* FIXME(bnoordhuis) -EBADF */
/* sizeof(socklen_t) != sizeof(int) on some systems. */ /* sizeof(socklen_t) != sizeof(int) on some systems. */
socklen = (socklen_t) *namelen; socklen = (socklen_t) *namelen;
if (getsockname(uv__stream_fd(handle), name, &socklen) == -1) if (getsockname(uv__stream_fd(handle), name, &socklen))
return uv__set_sys_error(handle->loop, errno); return -errno;
*namelen = (int) socklen; *namelen = (int) socklen;
return 0; return 0;
@ -179,16 +184,16 @@ int uv_tcp_getpeername(uv_tcp_t* handle,
socklen_t socklen; socklen_t socklen;
if (handle->delayed_error) if (handle->delayed_error)
return uv__set_sys_error(handle->loop, handle->delayed_error); return handle->delayed_error;
if (uv__stream_fd(handle) < 0) if (uv__stream_fd(handle) < 0)
return uv__set_sys_error(handle->loop, EINVAL); return -EINVAL; /* FIXME(bnoordhuis) -EBADF */
/* sizeof(socklen_t) != sizeof(int) on some systems. */ /* sizeof(socklen_t) != sizeof(int) on some systems. */
socklen = (socklen_t) *namelen; socklen = (socklen_t) *namelen;
if (getpeername(uv__stream_fd(handle), name, &socklen) == -1) if (getpeername(uv__stream_fd(handle), name, &socklen))
return uv__set_sys_error(handle->loop, errno); return -errno;
*namelen = (int) socklen; *namelen = (int) socklen;
return 0; return 0;
@ -197,9 +202,10 @@ int uv_tcp_getpeername(uv_tcp_t* handle,
int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) { int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) {
static int single_accept = -1; static int single_accept = -1;
int err;
if (tcp->delayed_error) if (tcp->delayed_error)
return uv__set_sys_error(tcp->loop, tcp->delayed_error); return tcp->delayed_error;
if (single_accept == -1) { if (single_accept == -1) {
const char* val = getenv("UV_TCP_SINGLE_ACCEPT"); const char* val = getenv("UV_TCP_SINGLE_ACCEPT");
@ -209,11 +215,12 @@ int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) {
if (single_accept) if (single_accept)
tcp->flags |= UV_TCP_SINGLE_ACCEPT; tcp->flags |= UV_TCP_SINGLE_ACCEPT;
if (maybe_new_socket(tcp, AF_INET, UV_STREAM_READABLE)) err = maybe_new_socket(tcp, AF_INET, UV_STREAM_READABLE);
return -1; if (err)
return err;
if (listen(tcp->io_watcher.fd, backlog)) if (listen(tcp->io_watcher.fd, backlog))
return uv__set_sys_error(tcp->loop, errno); return -errno;
tcp->connection_cb = cb; tcp->connection_cb = cb;
@ -248,19 +255,20 @@ int uv__tcp_nodelay(int fd, int on) {
int uv__tcp_keepalive(int fd, int on, unsigned int delay) { int uv__tcp_keepalive(int fd, int on, unsigned int delay) {
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on))) if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on)))
return -1; return -errno;
#ifdef TCP_KEEPIDLE #ifdef TCP_KEEPIDLE
if (on && setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &delay, sizeof(delay))) if (on && setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &delay, sizeof(delay)))
return -1; return -errno;
#endif #endif
/* Solaris/SmartOS, if you don't support keep-alive, /* Solaris/SmartOS, if you don't support keep-alive,
* then don't advertise it in your system headers... * then don't advertise it in your system headers...
*/ */
/* FIXME(bnoordhuis) That's possibly because sizeof(delay) should be 1. */
#if defined(TCP_KEEPALIVE) && !defined(__sun) #if defined(TCP_KEEPALIVE) && !defined(__sun)
if (on && setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE, &delay, sizeof(delay))) if (on && setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE, &delay, sizeof(delay)))
return -1; return -errno;
#endif #endif
return 0; return 0;
@ -268,9 +276,13 @@ int uv__tcp_keepalive(int fd, int on, unsigned int delay) {
int uv_tcp_nodelay(uv_tcp_t* handle, int on) { int uv_tcp_nodelay(uv_tcp_t* handle, int on) {
if (uv__stream_fd(handle) != -1) int err;
if (uv__tcp_nodelay(uv__stream_fd(handle), on))
return -1; if (uv__stream_fd(handle) != -1) {
err = uv__tcp_nodelay(uv__stream_fd(handle), on);
if (err)
return err;
}
if (on) if (on)
handle->flags |= UV_TCP_NODELAY; handle->flags |= UV_TCP_NODELAY;
@ -282,9 +294,13 @@ int uv_tcp_nodelay(uv_tcp_t* handle, int on) {
int uv_tcp_keepalive(uv_tcp_t* handle, int on, unsigned int delay) { int uv_tcp_keepalive(uv_tcp_t* handle, int on, unsigned int delay) {
if (uv__stream_fd(handle) != -1) int err;
if (uv__tcp_keepalive(uv__stream_fd(handle), on, delay))
return -1; if (uv__stream_fd(handle) != -1) {
err =uv__tcp_keepalive(uv__stream_fd(handle), on, delay);
if (err)
return err;
}
if (on) if (on)
handle->flags |= UV_TCP_KEEPALIVE; handle->flags |= UV_TCP_KEEPALIVE;

144
deps/uv/src/unix/thread.c

@ -32,22 +32,16 @@
#define NANOSEC ((uint64_t) 1e9) #define NANOSEC ((uint64_t) 1e9)
int uv_thread_join(uv_thread_t *tid) { int uv_thread_join(uv_thread_t *tid) {
if (pthread_join(*tid, NULL)) return -pthread_join(*tid, NULL);
return -1;
else
return 0;
} }
int uv_mutex_init(uv_mutex_t* mutex) { int uv_mutex_init(uv_mutex_t* mutex) {
#ifdef NDEBUG #if defined(NDEBUG) || !defined(PTHREAD_MUTEX_ERRORCHECK)
if (pthread_mutex_init(mutex, NULL)) return -pthread_mutex_init(mutex, NULL);
return -1;
else
return 0;
#else #else
pthread_mutexattr_t attr; pthread_mutexattr_t attr;
int r; int err;
if (pthread_mutexattr_init(&attr)) if (pthread_mutexattr_init(&attr))
abort(); abort();
@ -55,12 +49,12 @@ int uv_mutex_init(uv_mutex_t* mutex) {
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK)) if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK))
abort(); abort();
r = pthread_mutex_init(mutex, &attr); err = pthread_mutex_init(mutex, &attr);
if (pthread_mutexattr_destroy(&attr)) if (pthread_mutexattr_destroy(&attr))
abort(); abort();
return r ? -1 : 0; return -err;
#endif #endif
} }
@ -78,17 +72,16 @@ void uv_mutex_lock(uv_mutex_t* mutex) {
int uv_mutex_trylock(uv_mutex_t* mutex) { int uv_mutex_trylock(uv_mutex_t* mutex) {
int r; int err;
r = pthread_mutex_trylock(mutex); /* FIXME(bnoordhuis) EAGAIN means recursive lock limit reached. Arguably
* a bug, should probably abort rather than return -EAGAIN.
if (r && r != EBUSY && r != EAGAIN) */
err = pthread_mutex_trylock(mutex);
if (err && err != EBUSY && err != EAGAIN)
abort(); abort();
if (r) return -err;
return -1;
else
return 0;
} }
@ -99,10 +92,7 @@ void uv_mutex_unlock(uv_mutex_t* mutex) {
int uv_rwlock_init(uv_rwlock_t* rwlock) { int uv_rwlock_init(uv_rwlock_t* rwlock) {
if (pthread_rwlock_init(rwlock, NULL)) return -pthread_rwlock_init(rwlock, NULL);
return -1;
else
return 0;
} }
@ -119,17 +109,13 @@ void uv_rwlock_rdlock(uv_rwlock_t* rwlock) {
int uv_rwlock_tryrdlock(uv_rwlock_t* rwlock) { int uv_rwlock_tryrdlock(uv_rwlock_t* rwlock) {
int r; int err;
r = pthread_rwlock_tryrdlock(rwlock);
if (r && r != EBUSY && r != EAGAIN) err = pthread_rwlock_tryrdlock(rwlock);
if (err && err != EBUSY && err != EAGAIN)
abort(); abort();
if (r) return -err;
return -1;
else
return 0;
} }
@ -146,17 +132,13 @@ void uv_rwlock_wrlock(uv_rwlock_t* rwlock) {
int uv_rwlock_trywrlock(uv_rwlock_t* rwlock) { int uv_rwlock_trywrlock(uv_rwlock_t* rwlock) {
int r; int err;
r = pthread_rwlock_trywrlock(rwlock); err = pthread_rwlock_trywrlock(rwlock);
if (err && err != EBUSY && err != EAGAIN)
if (r && r != EBUSY && r != EAGAIN)
abort(); abort();
if (r) return -err;
return -1;
else
return 0;
} }
@ -174,10 +156,18 @@ void uv_once(uv_once_t* guard, void (*callback)(void)) {
#if defined(__APPLE__) && defined(__MACH__) #if defined(__APPLE__) && defined(__MACH__)
int uv_sem_init(uv_sem_t* sem, unsigned int value) { int uv_sem_init(uv_sem_t* sem, unsigned int value) {
if (semaphore_create(mach_task_self(), sem, SYNC_POLICY_FIFO, value)) kern_return_t err;
return -1;
else err = semaphore_create(mach_task_self(), sem, SYNC_POLICY_FIFO, value);
if (err == KERN_SUCCESS)
return 0; return 0;
if (err == KERN_INVALID_ARGUMENT)
return -EINVAL;
if (err == KERN_RESOURCE_SHORTAGE)
return -ENOMEM;
abort();
return -EINVAL; /* Satisfy the compiler. */
} }
@ -207,20 +197,27 @@ void uv_sem_wait(uv_sem_t* sem) {
int uv_sem_trywait(uv_sem_t* sem) { int uv_sem_trywait(uv_sem_t* sem) {
mach_timespec_t interval; mach_timespec_t interval;
kern_return_t err;
interval.tv_sec = 0; interval.tv_sec = 0;
interval.tv_nsec = 0; interval.tv_nsec = 0;
if (semaphore_timedwait(*sem, interval) == KERN_SUCCESS) err = semaphore_timedwait(*sem, interval);
if (err == KERN_SUCCESS)
return 0; return 0;
else if (err == KERN_OPERATION_TIMED_OUT)
return -1; return -EAGAIN;
abort();
return -EINVAL; /* Satisfy the compiler. */
} }
#else /* !(defined(__APPLE__) && defined(__MACH__)) */ #else /* !(defined(__APPLE__) && defined(__MACH__)) */
int uv_sem_init(uv_sem_t* sem, unsigned int value) { int uv_sem_init(uv_sem_t* sem, unsigned int value) {
return sem_init(sem, 0, value); if (sem_init(sem, 0, value))
return -errno;
return 0;
} }
@ -255,10 +252,13 @@ int uv_sem_trywait(uv_sem_t* sem) {
r = sem_trywait(sem); r = sem_trywait(sem);
while (r == -1 && errno == EINTR); while (r == -1 && errno == EINTR);
if (r && errno != EAGAIN) if (r) {
if (errno == EAGAIN)
return -EAGAIN;
abort(); abort();
}
return r; return 0;
} }
#endif /* defined(__APPLE__) && defined(__MACH__) */ #endif /* defined(__APPLE__) && defined(__MACH__) */
@ -267,29 +267,31 @@ int uv_sem_trywait(uv_sem_t* sem) {
#if defined(__APPLE__) && defined(__MACH__) #if defined(__APPLE__) && defined(__MACH__)
int uv_cond_init(uv_cond_t* cond) { int uv_cond_init(uv_cond_t* cond) {
if (pthread_cond_init(cond, NULL)) return -pthread_cond_init(cond, NULL);
return -1;
else
return 0;
} }
#else /* !(defined(__APPLE__) && defined(__MACH__)) */ #else /* !(defined(__APPLE__) && defined(__MACH__)) */
int uv_cond_init(uv_cond_t* cond) { int uv_cond_init(uv_cond_t* cond) {
pthread_condattr_t attr; pthread_condattr_t attr;
int err;
if (pthread_condattr_init(&attr)) err = pthread_condattr_init(&attr);
return -1; if (err)
return -err;
#if !defined(__ANDROID__) #if !defined(__ANDROID__)
if (pthread_condattr_setclock(&attr, CLOCK_MONOTONIC)) err = pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
if (err)
goto error2; goto error2;
#endif #endif
if (pthread_cond_init(cond, &attr)) err = pthread_cond_init(cond, &attr);
if (err)
goto error2; goto error2;
if (pthread_condattr_destroy(&attr)) err = pthread_condattr_destroy(&attr);
if (err)
goto error; goto error;
return 0; return 0;
@ -298,7 +300,7 @@ error:
pthread_cond_destroy(cond); pthread_cond_destroy(cond);
error2: error2:
pthread_condattr_destroy(&attr); pthread_condattr_destroy(&attr);
return -1; return -err;
} }
#endif /* defined(__APPLE__) && defined(__MACH__) */ #endif /* defined(__APPLE__) && defined(__MACH__) */
@ -352,26 +354,31 @@ int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex, uint64_t timeout) {
return 0; return 0;
if (r == ETIMEDOUT) if (r == ETIMEDOUT)
return -1; return -ETIMEDOUT;
abort(); abort();
return -1; /* Satisfy the compiler. */ return -EINVAL; /* Satisfy the compiler. */
} }
#if defined(__APPLE__) && defined(__MACH__) #if defined(__APPLE__) && defined(__MACH__)
int uv_barrier_init(uv_barrier_t* barrier, unsigned int count) { int uv_barrier_init(uv_barrier_t* barrier, unsigned int count) {
int err;
barrier->n = count; barrier->n = count;
barrier->count = 0; barrier->count = 0;
if (uv_mutex_init(&barrier->mutex)) err = uv_mutex_init(&barrier->mutex);
return -1; if (err)
return -err;
if (uv_sem_init(&barrier->turnstile1, 0)) err = uv_sem_init(&barrier->turnstile1, 0);
if (err)
goto error2; goto error2;
if (uv_sem_init(&barrier->turnstile2, 1)) err = uv_sem_init(&barrier->turnstile2, 1);
if (err)
goto error; goto error;
return 0; return 0;
@ -380,7 +387,7 @@ error:
uv_sem_destroy(&barrier->turnstile1); uv_sem_destroy(&barrier->turnstile1);
error2: error2:
uv_mutex_destroy(&barrier->mutex); uv_mutex_destroy(&barrier->mutex);
return -1; return -err;
} }
@ -417,10 +424,7 @@ void uv_barrier_wait(uv_barrier_t* barrier) {
#else /* !(defined(__APPLE__) && defined(__MACH__)) */ #else /* !(defined(__APPLE__) && defined(__MACH__)) */
int uv_barrier_init(uv_barrier_t* barrier, unsigned int count) { int uv_barrier_init(uv_barrier_t* barrier, unsigned int count) {
if (pthread_barrier_init(barrier, NULL, count)) return -pthread_barrier_init(barrier, NULL, count);
return -1;
else
return 0;
} }

15
deps/uv/src/unix/threadpool.c

@ -182,7 +182,7 @@ static int uv__work_cancel(uv_loop_t* loop, uv_req_t* req, struct uv__work* w) {
uv_mutex_unlock(&mutex); uv_mutex_unlock(&mutex);
if (!cancelled) if (!cancelled)
return -1; return -EBUSY;
w->work = uv__cancelled; w->work = uv__cancelled;
uv_mutex_lock(&loop->wq_mutex); uv_mutex_lock(&loop->wq_mutex);
@ -216,7 +216,7 @@ void uv__work_done(uv_async_t* handle, int status) {
QUEUE_REMOVE(q); QUEUE_REMOVE(q);
w = container_of(q, struct uv__work, wq); w = container_of(q, struct uv__work, wq);
err = (w->work == uv__cancelled) ? -UV_ECANCELED : 0; err = (w->work == uv__cancelled) ? -ECANCELED : 0;
w->done(w, err); w->done(w, err);
} }
} }
@ -229,7 +229,7 @@ static void uv__queue_work(struct uv__work* w) {
} }
static void uv__queue_done(struct uv__work* w, int status) { static void uv__queue_done(struct uv__work* w, int err) {
uv_work_t* req; uv_work_t* req;
req = container_of(w, uv_work_t, work_req); req = container_of(w, uv_work_t, work_req);
@ -238,10 +238,7 @@ static void uv__queue_done(struct uv__work* w, int status) {
if (req->after_work_cb == NULL) if (req->after_work_cb == NULL)
return; return;
if (status == -UV_ECANCELED) req->after_work_cb(req, err);
uv__set_artificial_error(req->loop, UV_ECANCELED);
req->after_work_cb(req, status ? -1 : 0);
} }
@ -250,7 +247,7 @@ int uv_queue_work(uv_loop_t* loop,
uv_work_cb work_cb, uv_work_cb work_cb,
uv_after_work_cb after_work_cb) { uv_after_work_cb after_work_cb) {
if (work_cb == NULL) if (work_cb == NULL)
return uv__set_artificial_error(loop, UV_EINVAL); return -EINVAL;
uv__req_init(loop, req, UV_WORK); uv__req_init(loop, req, UV_WORK);
req->loop = loop; req->loop = loop;
@ -279,7 +276,7 @@ int uv_cancel(uv_req_t* req) {
wreq = &((uv_work_t*) req)->work_req; wreq = &((uv_work_t*) req)->work_req;
break; break;
default: default:
return -1; return -EINVAL;
} }
return uv__work_cancel(loop, req, wreq); return uv__work_cancel(loop, req, wreq);

2
deps/uv/src/unix/timer.c

@ -92,7 +92,7 @@ int uv_timer_stop(uv_timer_t* handle) {
int uv_timer_again(uv_timer_t* handle) { int uv_timer_again(uv_timer_t* handle) {
if (handle->timer_cb == NULL) if (handle->timer_cb == NULL)
return uv__set_artificial_error(handle->loop, UV_EINVAL); return -EINVAL;
if (handle->repeat) { if (handle->repeat) {
uv_timer_stop(handle); uv_timer_stop(handle);

16
deps/uv/src/unix/tty.c

@ -37,8 +37,11 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) {
uv__stream_init(loop, (uv_stream_t*)tty, UV_TTY); uv__stream_init(loop, (uv_stream_t*)tty, UV_TTY);
#if defined(__APPLE__) #if defined(__APPLE__)
if (uv__stream_try_select((uv_stream_t*) tty, &fd)) {
return -1; int err = uv__stream_try_select((uv_stream_t*) tty, &fd);
if (err)
return err;
}
#endif /* defined(__APPLE__) */ #endif /* defined(__APPLE__) */
if (readable) { if (readable) {
@ -102,18 +105,15 @@ int uv_tty_set_mode(uv_tty_t* tty, int mode) {
} }
fatal: fatal:
uv__set_sys_error(tty->loop, errno); return -errno;
return -1;
} }
int uv_tty_get_winsize(uv_tty_t* tty, int* width, int* height) { int uv_tty_get_winsize(uv_tty_t* tty, int* width, int* height) {
struct winsize ws; struct winsize ws;
if (ioctl(uv__stream_fd(tty), TIOCGWINSZ, &ws) < 0) { if (ioctl(uv__stream_fd(tty), TIOCGWINSZ, &ws))
uv__set_sys_error(tty->loop, errno); return -errno;
return -1;
}
*width = ws.ws_col; *width = ws.ws_col;
*height = ws.ws_row; *height = ws.ws_row;

113
deps/uv/src/unix/udp.c

@ -72,10 +72,8 @@ void uv__udp_finish_close(uv_udp_t* handle) {
free(req->bufs); free(req->bufs);
req->bufs = NULL; req->bufs = NULL;
if (req->send_cb) { if (req->send_cb != NULL)
uv__set_artificial_error(handle->loop, UV_ECANCELED); req->send_cb(req, -ECANCELED);
req->send_cb(req, -1);
}
} }
/* Now tear down the handle. */ /* Now tear down the handle. */
@ -163,13 +161,10 @@ static void uv__udp_run_completed(uv_udp_t* handle) {
/* req->status >= 0 == bytes written /* req->status >= 0 == bytes written
* req->status < 0 == errno * req->status < 0 == errno
*/ */
if (req->status >= 0) { if (req->status >= 0)
req->send_cb(req, 0); req->send_cb(req, 0);
} else
else { req->send_cb(req, req->status);
uv__set_sys_error(handle->loop, -req->status);
req->send_cb(req, -1);
}
} }
} }
@ -224,14 +219,10 @@ static void uv__udp_recvmsg(uv_loop_t* loop,
while (nread == -1 && errno == EINTR); while (nread == -1 && errno == EINTR);
if (nread == -1) { if (nread == -1) {
if (errno == EAGAIN || errno == EWOULDBLOCK) { if (errno == EAGAIN || errno == EWOULDBLOCK)
uv__set_sys_error(handle->loop, EAGAIN);
handle->recv_cb(handle, 0, buf, NULL, 0); handle->recv_cb(handle, 0, buf, NULL, 0);
} else
else { handle->recv_cb(handle, -errno, buf, NULL, 0);
uv__set_sys_error(handle->loop, errno);
handle->recv_cb(handle, -1, buf, NULL, 0);
}
} }
else { else {
flags = 0; flags = 0;
@ -291,30 +282,32 @@ static int uv__bind(uv_udp_t* handle,
struct sockaddr* addr, struct sockaddr* addr,
socklen_t len, socklen_t len,
unsigned flags) { unsigned flags) {
int err;
int yes; int yes;
int fd; int fd;
err = -EINVAL;
fd = -1; fd = -1;
/* Check for bad flags. */ /* Check for bad flags. */
if (flags & ~UV_UDP_IPV6ONLY) if (flags & ~UV_UDP_IPV6ONLY)
return uv__set_sys_error(handle->loop, EINVAL); return -EINVAL;
/* Cannot set IPv6-only mode on non-IPv6 socket. */ /* Cannot set IPv6-only mode on non-IPv6 socket. */
if ((flags & UV_UDP_IPV6ONLY) && domain != AF_INET6) if ((flags & UV_UDP_IPV6ONLY) && domain != AF_INET6)
return uv__set_sys_error(handle->loop, EINVAL); return -EINVAL;
fd = handle->io_watcher.fd; fd = handle->io_watcher.fd;
if (fd == -1) { if (fd == -1) {
fd = uv__socket(domain, SOCK_DGRAM, 0); fd = uv__socket(domain, SOCK_DGRAM, 0);
if (fd == -1) if (fd == -1)
return uv__set_sys_error(handle->loop, errno); return -errno;
handle->io_watcher.fd = fd; handle->io_watcher.fd = fd;
} }
yes = 1; yes = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes) == -1) { if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes) == -1) {
uv__set_sys_error(handle->loop, errno); err = -errno;
goto out; goto out;
} }
@ -329,7 +322,7 @@ static int uv__bind(uv_udp_t* handle,
#ifdef SO_REUSEPORT #ifdef SO_REUSEPORT
yes = 1; yes = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof yes) == -1) { if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof yes) == -1) {
uv__set_sys_error(handle->loop, errno); err = -errno;
goto out; goto out;
} }
#endif #endif
@ -338,17 +331,17 @@ static int uv__bind(uv_udp_t* handle,
#ifdef IPV6_V6ONLY #ifdef IPV6_V6ONLY
yes = 1; yes = 1;
if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &yes, sizeof yes) == -1) { if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &yes, sizeof yes) == -1) {
uv__set_sys_error(handle->loop, errno); err = -errno;
goto out; goto out;
} }
#else #else
uv__set_sys_error(handle->loop, ENOTSUP); err = -ENOTSUP;
goto out; goto out;
#endif #endif
} }
if (bind(fd, addr, len) == -1) { if (bind(fd, addr, len) == -1) {
uv__set_sys_error(handle->loop, errno); err = -errno;
goto out; goto out;
} }
@ -357,7 +350,7 @@ static int uv__bind(uv_udp_t* handle,
out: out:
close(handle->io_watcher.fd); close(handle->io_watcher.fd);
handle->io_watcher.fd = -1; handle->io_watcher.fd = -1;
return -1; return err;
} }
@ -405,10 +398,13 @@ static int uv__send(uv_udp_send_t* req,
struct sockaddr* addr, struct sockaddr* addr,
socklen_t addrlen, socklen_t addrlen,
uv_udp_send_cb send_cb) { uv_udp_send_cb send_cb) {
int err;
assert(bufcnt > 0); assert(bufcnt > 0);
if (uv__udp_maybe_deferred_bind(handle, addr->sa_family)) err = uv__udp_maybe_deferred_bind(handle, addr->sa_family);
return -1; if (err)
return err;
uv__req_init(handle->loop, req, UV_UDP_SEND); uv__req_init(handle->loop, req, UV_UDP_SEND);
@ -418,13 +414,13 @@ static int uv__send(uv_udp_send_t* req,
req->handle = handle; req->handle = handle;
req->bufcnt = bufcnt; req->bufcnt = bufcnt;
if (bufcnt <= (int) ARRAY_SIZE(req->bufsml)) { if (bufcnt <= (int) ARRAY_SIZE(req->bufsml))
req->bufs = req->bufsml; req->bufs = req->bufsml;
} else
else if ((req->bufs = malloc(bufcnt * sizeof(bufs[0]))) == NULL) { req->bufs = malloc(bufcnt * sizeof(*bufs));
uv__set_sys_error(handle->loop, ENOMEM);
return -1; if (req->bufs == NULL)
} return -ENOMEM;
memcpy(req->bufs, bufs, bufcnt * sizeof(bufs[0])); memcpy(req->bufs, bufs, bufcnt * sizeof(bufs[0]));
QUEUE_INSERT_TAIL(&handle->write_queue, &req->queue); QUEUE_INSERT_TAIL(&handle->write_queue, &req->queue);
@ -469,11 +465,11 @@ int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock) {
/* Check for already active socket. */ /* Check for already active socket. */
if (handle->io_watcher.fd != -1) if (handle->io_watcher.fd != -1)
return uv__set_artificial_error(handle->loop, UV_EALREADY); return -EALREADY; /* FIXME(bnoordhuis) Should be -EBUSY. */
yes = 1; yes = 1;
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes) == -1) if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes))
return uv__set_sys_error(handle->loop, errno); return -errno;
/* On the BSDs, SO_REUSEADDR lets you reuse an address that's in the TIME_WAIT /* On the BSDs, SO_REUSEADDR lets you reuse an address that's in the TIME_WAIT
* state (i.e. was until recently tied to a socket) while SO_REUSEPORT lets * state (i.e. was until recently tied to a socket) while SO_REUSEPORT lets
@ -485,8 +481,8 @@ int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock) {
*/ */
#ifdef SO_REUSEPORT #ifdef SO_REUSEPORT
yes = 1; yes = 1;
if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof yes) == -1) if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof yes))
return uv__set_sys_error(handle->loop, errno); return -errno;
#endif #endif
handle->io_watcher.fd = sock; handle->io_watcher.fd = sock;
@ -519,7 +515,7 @@ int uv_udp_set_membership(uv_udp_t* handle,
optname = IP_DROP_MEMBERSHIP; optname = IP_DROP_MEMBERSHIP;
break; break;
default: default:
return uv__set_artificial_error(handle->loop, UV_EINVAL); return -EINVAL;
} }
if (setsockopt(handle->io_watcher.fd, if (setsockopt(handle->io_watcher.fd,
@ -527,7 +523,7 @@ int uv_udp_set_membership(uv_udp_t* handle,
optname, optname,
&mreq, &mreq,
sizeof(mreq))) { sizeof(mreq))) {
return uv__set_sys_error(handle->loop, errno); return -errno;
} }
return 0; return 0;
@ -542,10 +538,10 @@ static int uv__setsockopt_maybe_char(uv_udp_t* handle, int option, int val) {
#endif #endif
if (val < 0 || val > 255) if (val < 0 || val > 255)
return uv__set_sys_error(handle->loop, EINVAL); return -EINVAL;
if (setsockopt(handle->io_watcher.fd, IPPROTO_IP, option, &arg, sizeof(arg))) if (setsockopt(handle->io_watcher.fd, IPPROTO_IP, option, &arg, sizeof(arg)))
return uv__set_sys_error(handle->loop, errno); return -errno;
return 0; return 0;
} }
@ -557,7 +553,7 @@ int uv_udp_set_broadcast(uv_udp_t* handle, int on) {
SO_BROADCAST, SO_BROADCAST,
&on, &on,
sizeof(on))) { sizeof(on))) {
return uv__set_sys_error(handle->loop, errno); return -errno;
} }
return 0; return 0;
@ -566,10 +562,10 @@ int uv_udp_set_broadcast(uv_udp_t* handle, int on) {
int uv_udp_set_ttl(uv_udp_t* handle, int ttl) { int uv_udp_set_ttl(uv_udp_t* handle, int ttl) {
if (ttl < 1 || ttl > 255) if (ttl < 1 || ttl > 255)
return uv__set_sys_error(handle->loop, EINVAL); return -EINVAL;
if (setsockopt(handle->io_watcher.fd, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl))) if (setsockopt(handle->io_watcher.fd, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl)))
return uv__set_sys_error(handle->loop, errno); return -errno;
return 0; return 0;
} }
@ -589,13 +585,13 @@ int uv_udp_getsockname(uv_udp_t* handle, struct sockaddr* name, int* namelen) {
socklen_t socklen; socklen_t socklen;
if (handle->io_watcher.fd == -1) if (handle->io_watcher.fd == -1)
return uv__set_sys_error(handle->loop, EINVAL); return -EINVAL; /* FIXME(bnoordhuis) -EBADF */
/* sizeof(socklen_t) != sizeof(int) on some systems. */ /* sizeof(socklen_t) != sizeof(int) on some systems. */
socklen = (socklen_t) *namelen; socklen = (socklen_t) *namelen;
if (getsockname(handle->io_watcher.fd, name, &socklen) == -1) if (getsockname(handle->io_watcher.fd, name, &socklen))
return uv__set_sys_error(handle->loop, errno); return -errno;
*namelen = (int) socklen; *namelen = (int) socklen;
return 0; return 0;
@ -637,18 +633,17 @@ int uv__udp_send6(uv_udp_send_t* req,
int uv__udp_recv_start(uv_udp_t* handle, int uv__udp_recv_start(uv_udp_t* handle,
uv_alloc_cb alloc_cb, uv_alloc_cb alloc_cb,
uv_udp_recv_cb recv_cb) { uv_udp_recv_cb recv_cb) {
if (alloc_cb == NULL || recv_cb == NULL) { int err;
uv__set_artificial_error(handle->loop, UV_EINVAL);
return -1;
}
if (uv__io_active(&handle->io_watcher, UV__POLLIN)) { if (alloc_cb == NULL || recv_cb == NULL)
uv__set_artificial_error(handle->loop, UV_EALREADY); return -EINVAL;
return -1;
} if (uv__io_active(&handle->io_watcher, UV__POLLIN))
return -EALREADY; /* FIXME(bnoordhuis) Should be -EBUSY. */
if (uv__udp_maybe_deferred_bind(handle, AF_INET)) err = uv__udp_maybe_deferred_bind(handle, AF_INET);
return -1; if (err)
return err;
handle->alloc_cb = alloc_cb; handle->alloc_cb = alloc_cb;
handle->recv_cb = recv_cb; handle->recv_cb = recv_cb;

193
deps/uv/src/uv-common.c

@ -28,6 +28,16 @@
#include <stdlib.h> /* malloc */ #include <stdlib.h> /* malloc */
#include <string.h> /* memset */ #include <string.h> /* memset */
#if defined(UV_PLATFORM_HAS_IP6_LINK_LOCAL_ADDRESS) && !defined(_WIN32)
# include <net/if.h> /* if_nametoindex */
#endif
/* EAI_* constants. */
#if !defined(_WIN32)
# include <sys/types.h>
# include <sys/socket.h>
# include <netdb.h>
#endif
#define XX(uc, lc) case UV_##uc: return sizeof(uv_##lc##_t); #define XX(uc, lc) case UV_##uc: return sizeof(uv_##lc##_t);
@ -92,11 +102,9 @@ uv_buf_t uv_buf_init(char* base, unsigned int len) {
} }
const uv_err_t uv_ok_ = { UV_OK, 0 }; #define UV_ERR_NAME_GEN(name, _) case UV_ ## name: return #name;
const char* uv_err_name(int err) {
#define UV_ERR_NAME_GEN(val, name, s) case UV_##name : return #name; switch (err) {
const char* uv_err_name(uv_err_t err) {
switch (err.code) {
UV_ERRNO_MAP(UV_ERR_NAME_GEN) UV_ERRNO_MAP(UV_ERR_NAME_GEN)
default: default:
assert(0); assert(0);
@ -106,9 +114,9 @@ const char* uv_err_name(uv_err_t err) {
#undef UV_ERR_NAME_GEN #undef UV_ERR_NAME_GEN
#define UV_STRERROR_GEN(val, name, s) case UV_##name : return s; #define UV_STRERROR_GEN(name, msg) case UV_ ## name: return msg;
const char* uv_strerror(uv_err_t err) { const char* uv_strerror(int err) {
switch (err.code) { switch (err) {
UV_ERRNO_MAP(UV_STRERROR_GEN) UV_ERRNO_MAP(UV_STRERROR_GEN)
default: default:
return "Unknown system error"; return "Unknown system error";
@ -117,47 +125,6 @@ const char* uv_strerror(uv_err_t err) {
#undef UV_STRERROR_GEN #undef UV_STRERROR_GEN
int uv__set_error(uv_loop_t* loop, uv_err_code code, int sys_error) {
loop->last_err.code = code;
loop->last_err.sys_errno_ = sys_error;
return -1;
}
int uv__set_sys_error(uv_loop_t* loop, int sys_error) {
loop->last_err.code = uv_translate_sys_error(sys_error);
loop->last_err.sys_errno_ = sys_error;
return -1;
}
int uv__set_artificial_error(uv_loop_t* loop, uv_err_code code) {
loop->last_err = uv__new_artificial_error(code);
return -1;
}
uv_err_t uv__new_sys_error(int sys_error) {
uv_err_t error;
error.code = uv_translate_sys_error(sys_error);
error.sys_errno_ = sys_error;
return error;
}
uv_err_t uv__new_artificial_error(uv_err_code code) {
uv_err_t error;
error.code = code;
error.sys_errno_ = 0;
return error;
}
uv_err_t uv_last_error(uv_loop_t* loop) {
return loop->last_err;
}
struct sockaddr_in uv_ip4_addr(const char* ip, int port) { struct sockaddr_in uv_ip4_addr(const char* ip, int port) {
struct sockaddr_in addr; struct sockaddr_in addr;
@ -173,11 +140,36 @@ struct sockaddr_in uv_ip4_addr(const char* ip, int port) {
struct sockaddr_in6 uv_ip6_addr(const char* ip, int port) { struct sockaddr_in6 uv_ip6_addr(const char* ip, int port) {
struct sockaddr_in6 addr; struct sockaddr_in6 addr;
char address_part[40];
size_t address_part_size;
const char* zone_index;
memset(&addr, 0, sizeof(struct sockaddr_in6)); memset(&addr, 0, sizeof(struct sockaddr_in6));
addr.sin6_family = AF_INET6; addr.sin6_family = AF_INET6;
addr.sin6_port = htons(port); addr.sin6_port = htons(port);
#if defined(UV_PLATFORM_HAS_IP6_LINK_LOCAL_ADDRESS)
zone_index = strchr(ip, '%');
if (zone_index != NULL) {
address_part_size = sizeof(address_part);
assert((unsigned)(zone_index - ip) < address_part_size);
strncpy(address_part, ip, zone_index - ip);
address_part[address_part_size - 1] = '\0';
ip = address_part;
zone_index++; /* skip '%' */
/* NOTE: unknown interface (id=0) is silently ignored */
#ifdef _WIN32
addr.sin6_scope_id = atoi(zone_index);
#else
addr.sin6_scope_id = if_nametoindex(zone_index);
#endif
}
#endif
/* result code is ignored - we assume ip is a valid IPv6 address */
uv_inet_pton(AF_INET6, ip, &addr.sin6_addr); uv_inet_pton(AF_INET6, ip, &addr.sin6_addr);
return addr; return addr;
@ -185,20 +177,18 @@ struct sockaddr_in6 uv_ip6_addr(const char* ip, int port) {
int uv_ip4_name(struct sockaddr_in* src, char* dst, size_t size) { int uv_ip4_name(struct sockaddr_in* src, char* dst, size_t size) {
uv_err_t err = uv_inet_ntop(AF_INET, &src->sin_addr, dst, size); return uv_inet_ntop(AF_INET, &src->sin_addr, dst, size);
return err.code != UV_OK;
} }
int uv_ip6_name(struct sockaddr_in6* src, char* dst, size_t size) { int uv_ip6_name(struct sockaddr_in6* src, char* dst, size_t size) {
uv_err_t err = uv_inet_ntop(AF_INET6, &src->sin6_addr, dst, size); return uv_inet_ntop(AF_INET6, &src->sin6_addr, dst, size);
return err.code != UV_OK;
} }
int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr) { int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr) {
if (handle->type != UV_TCP || addr.sin_family != AF_INET) if (handle->type != UV_TCP || addr.sin_family != AF_INET)
return uv__set_artificial_error(handle->loop, UV_EINVAL); return UV_EINVAL;
else else
return uv__tcp_bind(handle, addr); return uv__tcp_bind(handle, addr);
} }
@ -206,7 +196,7 @@ int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr) {
int uv_tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr) { int uv_tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr) {
if (handle->type != UV_TCP || addr.sin6_family != AF_INET6) if (handle->type != UV_TCP || addr.sin6_family != AF_INET6)
return uv__set_artificial_error(handle->loop, UV_EINVAL); return UV_EINVAL;
else else
return uv__tcp_bind6(handle, addr); return uv__tcp_bind6(handle, addr);
} }
@ -216,7 +206,7 @@ int uv_udp_bind(uv_udp_t* handle,
struct sockaddr_in addr, struct sockaddr_in addr,
unsigned int flags) { unsigned int flags) {
if (handle->type != UV_UDP || addr.sin_family != AF_INET) if (handle->type != UV_UDP || addr.sin_family != AF_INET)
return uv__set_artificial_error(handle->loop, UV_EINVAL); return UV_EINVAL;
else else
return uv__udp_bind(handle, addr, flags); return uv__udp_bind(handle, addr, flags);
} }
@ -226,7 +216,7 @@ int uv_udp_bind6(uv_udp_t* handle,
struct sockaddr_in6 addr, struct sockaddr_in6 addr,
unsigned int flags) { unsigned int flags) {
if (handle->type != UV_UDP || addr.sin6_family != AF_INET6) if (handle->type != UV_UDP || addr.sin6_family != AF_INET6)
return uv__set_artificial_error(handle->loop, UV_EINVAL); return UV_EINVAL;
else else
return uv__udp_bind6(handle, addr, flags); return uv__udp_bind6(handle, addr, flags);
} }
@ -237,7 +227,7 @@ int uv_tcp_connect(uv_connect_t* req,
struct sockaddr_in address, struct sockaddr_in address,
uv_connect_cb cb) { uv_connect_cb cb) {
if (handle->type != UV_TCP || address.sin_family != AF_INET) if (handle->type != UV_TCP || address.sin_family != AF_INET)
return uv__set_artificial_error(handle->loop, UV_EINVAL); return UV_EINVAL;
else else
return uv__tcp_connect(req, handle, address, cb); return uv__tcp_connect(req, handle, address, cb);
} }
@ -248,7 +238,7 @@ int uv_tcp_connect6(uv_connect_t* req,
struct sockaddr_in6 address, struct sockaddr_in6 address,
uv_connect_cb cb) { uv_connect_cb cb) {
if (handle->type != UV_TCP || address.sin6_family != AF_INET6) if (handle->type != UV_TCP || address.sin6_family != AF_INET6)
return uv__set_artificial_error(handle->loop, UV_EINVAL); return UV_EINVAL;
else else
return uv__tcp_connect6(req, handle, address, cb); return uv__tcp_connect6(req, handle, address, cb);
} }
@ -260,11 +250,10 @@ int uv_udp_send(uv_udp_send_t* req,
int bufcnt, int bufcnt,
struct sockaddr_in addr, struct sockaddr_in addr,
uv_udp_send_cb send_cb) { uv_udp_send_cb send_cb) {
if (handle->type != UV_UDP || addr.sin_family != AF_INET) { if (handle->type != UV_UDP || addr.sin_family != AF_INET)
return uv__set_artificial_error(handle->loop, UV_EINVAL); return UV_EINVAL;
} else
return uv__udp_send(req, handle, bufs, bufcnt, addr, send_cb);
return uv__udp_send(req, handle, bufs, bufcnt, addr, send_cb);
} }
@ -274,31 +263,28 @@ int uv_udp_send6(uv_udp_send_t* req,
int bufcnt, int bufcnt,
struct sockaddr_in6 addr, struct sockaddr_in6 addr,
uv_udp_send_cb send_cb) { uv_udp_send_cb send_cb) {
if (handle->type != UV_UDP || addr.sin6_family != AF_INET6) { if (handle->type != UV_UDP || addr.sin6_family != AF_INET6)
return uv__set_artificial_error(handle->loop, UV_EINVAL); return UV_EINVAL;
} else
return uv__udp_send6(req, handle, bufs, bufcnt, addr, send_cb);
return uv__udp_send6(req, handle, bufs, bufcnt, addr, send_cb);
} }
int uv_udp_recv_start(uv_udp_t* handle, int uv_udp_recv_start(uv_udp_t* handle,
uv_alloc_cb alloc_cb, uv_alloc_cb alloc_cb,
uv_udp_recv_cb recv_cb) { uv_udp_recv_cb recv_cb) {
if (handle->type != UV_UDP || alloc_cb == NULL || recv_cb == NULL) { if (handle->type != UV_UDP || alloc_cb == NULL || recv_cb == NULL)
return uv__set_artificial_error(handle->loop, UV_EINVAL); return UV_EINVAL;
} else
return uv__udp_recv_start(handle, alloc_cb, recv_cb);
return uv__udp_recv_start(handle, alloc_cb, recv_cb);
} }
int uv_udp_recv_stop(uv_udp_t* handle) { int uv_udp_recv_stop(uv_udp_t* handle) {
if (handle->type != UV_UDP) { if (handle->type != UV_UDP)
return uv__set_artificial_error(handle->loop, UV_EINVAL); return UV_EINVAL;
} else
return uv__udp_recv_stop(handle);
return uv__udp_recv_stop(handle);
} }
@ -332,7 +318,7 @@ int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) {
ctx = malloc(sizeof(*ctx)); ctx = malloc(sizeof(*ctx));
if (ctx == NULL) if (ctx == NULL)
return -1; return UV_ENOMEM;
ctx->entry = entry; ctx->entry = entry;
ctx->arg = arg; ctx->arg = arg;
@ -439,3 +425,50 @@ void uv_stop(uv_loop_t* loop) {
uint64_t uv_now(uv_loop_t* loop) { uint64_t uv_now(uv_loop_t* loop) {
return loop->time; return loop->time;
} }
int uv__getaddrinfo_translate_error(int sys_err) {
switch (sys_err) {
case 0: return 0;
#if defined(EAI_ADDRFAMILY)
case EAI_ADDRFAMILY: return UV_EAI_ADDRFAMILY;
#endif
#if defined(EAI_AGAIN)
case EAI_AGAIN: return UV_EAI_AGAIN;
#endif
#if defined(EAI_BADFLAGS)
case EAI_BADFLAGS: return UV_EAI_BADFLAGS;
#endif
#if defined(EAI_CANCELED)
case EAI_CANCELED: return UV_EAI_CANCELED;
#endif
#if defined(EAI_FAIL)
case EAI_FAIL: return UV_EAI_FAIL;
#endif
#if defined(EAI_FAMILY)
case EAI_FAMILY: return UV_EAI_FAMILY;
#endif
#if defined(EAI_MEMORY)
case EAI_MEMORY: return UV_EAI_MEMORY;
#endif
#if defined(EAI_NODATA)
case EAI_NODATA: return UV_EAI_NODATA;
#endif
#if defined(EAI_NONAME)
# if !defined(EAI_NODATA) || EAI_NODATA != EAI_NONAME
case EAI_NONAME: return UV_EAI_NONAME;
# endif
#endif
#if defined(EAI_SERVICE)
case EAI_SERVICE: return UV_EAI_SERVICE;
#endif
#if defined(EAI_SOCKTYPE)
case EAI_SOCKTYPE: return UV_EAI_SOCKTYPE;
#endif
#if defined(EAI_SYSTEM)
case EAI_SYSTEM: return UV_EAI_SYSTEM;
#endif
}
assert(!"unknown EAI_* error code");
abort();
}

12
deps/uv/src/uv-common.h

@ -31,7 +31,7 @@
#include <stddef.h> #include <stddef.h>
#if defined(_MSC_VER) && _MSC_VER < 1600 #if defined(_MSC_VER) && _MSC_VER < 1600
# include "uv-private/stdint-msvc2008.h" # include "stdint-msvc2008.h"
#else #else
# include <stdint.h> # include <stdint.h>
#endif #endif
@ -69,15 +69,6 @@ enum {
# define UV__HANDLE_CLOSING 0x01 # define UV__HANDLE_CLOSING 0x01
#endif #endif
extern const uv_err_t uv_ok_;
uv_err_code uv_translate_sys_error(int sys_errno);
int uv__set_error(uv_loop_t* loop, uv_err_code code, int sys_error);
int uv__set_sys_error(uv_loop_t* loop, int sys_error);
int uv__set_artificial_error(uv_loop_t* loop, uv_err_code code);
uv_err_t uv__new_sys_error(int sys_error);
uv_err_t uv__new_artificial_error(uv_err_code code);
int uv__tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr); int uv__tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr);
int uv__tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr); int uv__tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr);
@ -115,6 +106,7 @@ int uv__udp_recv_stop(uv_udp_t* handle);
void uv__fs_poll_close(uv_fs_poll_t* handle); void uv__fs_poll_close(uv_fs_poll_t* handle);
int uv__getaddrinfo_translate_error(int sys_err); /* EAI_* error. */
#define uv__has_active_reqs(loop) \ #define uv__has_active_reqs(loop) \
(QUEUE_EMPTY(&(loop)->active_reqs) == 0) (QUEUE_EMPTY(&(loop)->active_reqs) == 0)

2
deps/uv/src/version.c

@ -31,7 +31,7 @@
#define UV_VERSION_MAJOR 0 #define UV_VERSION_MAJOR 0
#define UV_VERSION_MINOR 11 #define UV_VERSION_MINOR 11
#define UV_VERSION_PATCH 5 #define UV_VERSION_PATCH 6
#define UV_VERSION_IS_RELEASE 1 #define UV_VERSION_IS_RELEASE 1

2
deps/uv/src/win/core.c

@ -118,8 +118,6 @@ static void uv_loop_init(uv_loop_t* loop) {
loop->timer_counter = 0; loop->timer_counter = 0;
loop->stop_flag = 0; loop->stop_flag = 0;
loop->last_err = uv_ok_;
} }

9
deps/uv/src/win/error.c

@ -63,9 +63,12 @@ void uv_fatal_error(const int errorno, const char* syscall) {
} }
uv_err_code uv_translate_sys_error(int sys_errno) { int uv_translate_sys_error(int sys_errno) {
if (sys_errno <= 0) {
return sys_errno; /* If < 0 then it's already a libuv error. */
}
switch (sys_errno) { switch (sys_errno) {
case ERROR_SUCCESS: return UV_OK;
case ERROR_NOACCESS: return UV_EACCES; case ERROR_NOACCESS: return UV_EACCES;
case WSAEACCES: return UV_EACCES; case WSAEACCES: return UV_EACCES;
case ERROR_ADDRESS_ALREADY_ASSOCIATED: return UV_EADDRINUSE; case ERROR_ADDRESS_ALREADY_ASSOCIATED: return UV_EADDRINUSE;
@ -117,6 +120,7 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
case ERROR_OPEN_FAILED: return UV_EIO; case ERROR_OPEN_FAILED: return UV_EIO;
case ERROR_SETMARK_DETECTED: return UV_EIO; case ERROR_SETMARK_DETECTED: return UV_EIO;
case ERROR_SIGNAL_REFUSED: return UV_EIO; case ERROR_SIGNAL_REFUSED: return UV_EIO;
case WSAEISCONN: return UV_EISCONN;
case ERROR_CANT_RESOLVE_FILENAME: return UV_ELOOP; case ERROR_CANT_RESOLVE_FILENAME: return UV_ELOOP;
case ERROR_TOO_MANY_OPEN_FILES: return UV_EMFILE; case ERROR_TOO_MANY_OPEN_FILES: return UV_EMFILE;
case WSAEMFILE: return UV_EMFILE; case WSAEMFILE: return UV_EMFILE;
@ -161,4 +165,3 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
default: return UV_UNKNOWN; default: return UV_UNKNOWN;
} }
} }

12
deps/uv/src/win/fs-event.c

@ -149,8 +149,7 @@ int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle,
if (!uv_utf8_to_utf16(filename, filenamew, if (!uv_utf8_to_utf16(filename, filenamew,
name_size / sizeof(WCHAR))) { name_size / sizeof(WCHAR))) {
uv__set_sys_error(loop, GetLastError()); return uv_translate_sys_error(GetLastError());
return -1;
} }
/* Determine whether filename is a file or a directory. */ /* Determine whether filename is a file or a directory. */
@ -279,15 +278,14 @@ error:
handle->buffer = NULL; handle->buffer = NULL;
} }
uv__set_sys_error(loop, last_error); return uv_translate_sys_error(last_error);
return -1;
} }
void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req, void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req,
uv_fs_event_t* handle) { uv_fs_event_t* handle) {
FILE_NOTIFY_INFORMATION* file_info; FILE_NOTIFY_INFORMATION* file_info;
int sizew, size, result; int err, sizew, size, result;
char* filename = NULL; char* filename = NULL;
WCHAR* filenamew, *long_filenamew = NULL; WCHAR* filenamew, *long_filenamew = NULL;
DWORD offset = 0; DWORD offset = 0;
@ -445,8 +443,8 @@ void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req,
handle->cb(handle, NULL, UV_CHANGE, 0); handle->cb(handle, NULL, UV_CHANGE, 0);
} }
} else { } else {
uv__set_sys_error(loop, GET_REQ_ERROR(req)); err = GET_REQ_ERROR(req);
handle->cb(handle, NULL, 0, -1); handle->cb(handle, NULL, 0, uv_translate_sys_error(err));
} }
if (!(handle->flags & UV__HANDLE_CLOSING)) { if (!(handle->flags & UV__HANDLE_CLOSING)) {

158
deps/uv/src/win/fs.c

@ -44,35 +44,28 @@
if (!QueueUserWorkItem(&uv_fs_thread_proc, \ if (!QueueUserWorkItem(&uv_fs_thread_proc, \
req, \ req, \
WT_EXECUTEDEFAULT)) { \ WT_EXECUTEDEFAULT)) { \
uv__set_sys_error((loop), GetLastError()); \ return uv_translate_sys_error(GetLastError()); \
return -1; \
} \ } \
uv__req_register(loop, req); uv__req_register(loop, req);
#define SET_UV_LAST_ERROR_FROM_REQ(req) \
uv__set_error(req->loop, req->errorno, req->sys_errno_);
#define SET_REQ_RESULT(req, result_value) \ #define SET_REQ_RESULT(req, result_value) \
req->result = (result_value); \ req->result = (result_value); \
if (req->result == -1) { \ if (req->result == -1) { \
req->sys_errno_ = _doserrno; \ req->sys_errno_ = _doserrno; \
req->errorno = uv_translate_sys_error(req->sys_errno_); \ req->result = uv_translate_sys_error(req->sys_errno_); \
} }
#define SET_REQ_WIN32_ERROR(req, sys_errno) \ #define SET_REQ_WIN32_ERROR(req, sys_errno) \
req->result = -1; \
req->sys_errno_ = (sys_errno); \ req->sys_errno_ = (sys_errno); \
req->errorno = uv_translate_sys_error(req->sys_errno_); req->result = uv_translate_sys_error(req->sys_errno_); \
#define SET_REQ_UV_ERROR(req, uv_errno, sys_errno) \ #define SET_REQ_UV_ERROR(req, uv_errno, sys_errno) \
req->result = -1; \ req->result = (uv_errno); \
req->sys_errno_ = (sys_errno); \ req->sys_errno_ = (sys_errno); \
req->errorno = (uv_errno);
#define VERIFY_FD(fd, req) \ #define VERIFY_FD(fd, req) \
if (fd == -1) { \ if (fd == -1) { \
req->result = -1; \ req->result = UV_EBADF; \
req->errorno = UV_EBADF; \
req->sys_errno_ = ERROR_INVALID_HANDLE; \ req->sys_errno_ = ERROR_INVALID_HANDLE; \
return; \ return; \
} }
@ -131,8 +124,7 @@ INLINE static int fs__capture_path(uv_loop_t* loop, uv_fs_t* req,
NULL, NULL,
0); 0);
if (pathw_len == 0) { if (pathw_len == 0) {
uv__set_sys_error(loop, GetLastError()); return GetLastError();
return -1;
} }
buf_sz += pathw_len * sizeof(WCHAR); buf_sz += pathw_len * sizeof(WCHAR);
@ -151,8 +143,7 @@ INLINE static int fs__capture_path(uv_loop_t* loop, uv_fs_t* req,
NULL, NULL,
0); 0);
if (new_pathw_len == 0) { if (new_pathw_len == 0) {
uv__set_sys_error(loop, GetLastError()); return GetLastError();
return -1;
} }
buf_sz += new_pathw_len * sizeof(WCHAR); buf_sz += new_pathw_len * sizeof(WCHAR);
@ -168,8 +159,7 @@ INLINE static int fs__capture_path(uv_loop_t* loop, uv_fs_t* req,
buf = (char*) malloc(buf_sz); buf = (char*) malloc(buf_sz);
if (buf == NULL) { if (buf == NULL) {
uv__set_artificial_error(loop, UV_ENOMEM); return ERROR_OUTOFMEMORY;
return -1;
} }
pos = buf; pos = buf;
@ -229,7 +219,6 @@ INLINE static void uv_fs_req_init(uv_loop_t* loop, uv_fs_t* req,
req->fs_type = fs_type; req->fs_type = fs_type;
req->result = 0; req->result = 0;
req->ptr = NULL; req->ptr = NULL;
req->errorno = UV_OK;
req->path = NULL; req->path = NULL;
if (cb != NULL) { if (cb != NULL) {
@ -726,8 +715,7 @@ void fs__readdir(uv_fs_t* req) {
/* Figure out whether path is a file or a directory. */ /* Figure out whether path is a file or a directory. */
if (!(GetFileAttributesW(pathw) & FILE_ATTRIBUTE_DIRECTORY)) { if (!(GetFileAttributesW(pathw) & FILE_ATTRIBUTE_DIRECTORY)) {
req->result = -1; req->result = UV_ENOTDIR;
req->errorno = UV_ENOTDIR;
req->sys_errno_ = ERROR_SUCCESS; req->sys_errno_ = ERROR_SUCCESS;
return; return;
} }
@ -839,6 +827,9 @@ INLINE static int fs__stat_handle(HANDLE handle, uv_stat_t* statbuf) {
statbuf->st_blksize = 0; statbuf->st_blksize = 0;
statbuf->st_blocks = 0; statbuf->st_blocks = 0;
statbuf->st_flags = 0;
statbuf->st_gen = 0;
if (info.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) { if (info.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
if (fs__readlink_handle(handle, NULL, &statbuf->st_size) != 0) { if (fs__readlink_handle(handle, NULL, &statbuf->st_size) != 0) {
return -1; return -1;
@ -863,6 +854,7 @@ INLINE static int fs__stat_handle(HANDLE handle, uv_stat_t* statbuf) {
FILETIME_TO_TIMESPEC(statbuf->st_mtim, info.ftLastWriteTime); FILETIME_TO_TIMESPEC(statbuf->st_mtim, info.ftLastWriteTime);
FILETIME_TO_TIMESPEC(statbuf->st_atim, info.ftLastAccessTime); FILETIME_TO_TIMESPEC(statbuf->st_atim, info.ftLastAccessTime);
FILETIME_TO_TIMESPEC(statbuf->st_ctim, info.ftCreationTime); FILETIME_TO_TIMESPEC(statbuf->st_ctim, info.ftCreationTime);
FILETIME_TO_TIMESPEC(statbuf->st_birthtim, info.ftCreationTime);
statbuf->st_nlink = (info.nNumberOfLinks <= SHRT_MAX) ? statbuf->st_nlink = (info.nNumberOfLinks <= SHRT_MAX) ?
(short) info.nNumberOfLinks : SHRT_MAX; (short) info.nNumberOfLinks : SHRT_MAX;
@ -1473,10 +1465,13 @@ static DWORD WINAPI uv_fs_thread_proc(void* parameter) {
int uv_fs_open(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, int uv_fs_open(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags,
int mode, uv_fs_cb cb) { int mode, uv_fs_cb cb) {
int err;
uv_fs_req_init(loop, req, UV_FS_OPEN, cb); uv_fs_req_init(loop, req, UV_FS_OPEN, cb);
if (fs__capture_path(loop, req, path, NULL, cb != NULL) < 0) { err = fs__capture_path(loop, req, path, NULL, cb != NULL);
return -1; if (err) {
return uv_translate_sys_error(err);
} }
req->file_flags = flags; req->file_flags = flags;
@ -1487,7 +1482,6 @@ int uv_fs_open(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags,
return 0; return 0;
} else { } else {
fs__open(req); fs__open(req);
SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result; return req->result;
} }
} }
@ -1502,7 +1496,6 @@ int uv_fs_close(uv_loop_t* loop, uv_fs_t* req, uv_file fd, uv_fs_cb cb) {
return 0; return 0;
} else { } else {
fs__close(req); fs__close(req);
SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result; return req->result;
} }
} }
@ -1522,7 +1515,6 @@ int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, uv_file fd, void* buf,
return 0; return 0;
} else { } else {
fs__read(req); fs__read(req);
SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result; return req->result;
} }
} }
@ -1542,7 +1534,6 @@ int uv_fs_write(uv_loop_t* loop, uv_fs_t* req, uv_file fd, void* buf,
return 0; return 0;
} else { } else {
fs__write(req); fs__write(req);
SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result; return req->result;
} }
} }
@ -1550,10 +1541,13 @@ int uv_fs_write(uv_loop_t* loop, uv_fs_t* req, uv_file fd, void* buf,
int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path, int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path,
uv_fs_cb cb) { uv_fs_cb cb) {
int err;
uv_fs_req_init(loop, req, UV_FS_UNLINK, cb); uv_fs_req_init(loop, req, UV_FS_UNLINK, cb);
if (fs__capture_path(loop, req, path, NULL, cb != NULL) < 0) { err = fs__capture_path(loop, req, path, NULL, cb != NULL);
return -1; if (err) {
return uv_translate_sys_error(err);
} }
if (cb) { if (cb) {
@ -1561,7 +1555,6 @@ int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path,
return 0; return 0;
} else { } else {
fs__unlink(req); fs__unlink(req);
SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result; return req->result;
} }
} }
@ -1569,10 +1562,13 @@ int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path,
int uv_fs_mkdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode, int uv_fs_mkdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode,
uv_fs_cb cb) { uv_fs_cb cb) {
int err;
uv_fs_req_init(loop, req, UV_FS_MKDIR, cb); uv_fs_req_init(loop, req, UV_FS_MKDIR, cb);
if (fs__capture_path(loop, req, path, NULL, cb != NULL) < 0) { err = fs__capture_path(loop, req, path, NULL, cb != NULL);
return -1; if (err) {
return uv_translate_sys_error(err);
} }
req->mode = mode; req->mode = mode;
@ -1582,17 +1578,19 @@ int uv_fs_mkdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode,
return 0; return 0;
} else { } else {
fs__mkdir(req); fs__mkdir(req);
SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result; return req->result;
} }
} }
int uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { int uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
int err;
uv_fs_req_init(loop, req, UV_FS_RMDIR, cb); uv_fs_req_init(loop, req, UV_FS_RMDIR, cb);
if (fs__capture_path(loop, req, path, NULL, cb != NULL) < 0) { err = fs__capture_path(loop, req, path, NULL, cb != NULL);
return -1; if (err) {
return uv_translate_sys_error(err);
} }
if (cb) { if (cb) {
@ -1600,7 +1598,6 @@ int uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
return 0; return 0;
} else { } else {
fs__rmdir(req); fs__rmdir(req);
SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result; return req->result;
} }
} }
@ -1608,10 +1605,13 @@ int uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
int uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, int uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags,
uv_fs_cb cb) { uv_fs_cb cb) {
int err;
uv_fs_req_init(loop, req, UV_FS_READDIR, cb); uv_fs_req_init(loop, req, UV_FS_READDIR, cb);
if (fs__capture_path(loop, req, path, NULL, cb != NULL) < 0) { err = fs__capture_path(loop, req, path, NULL, cb != NULL);
return -1; if (err) {
return uv_translate_sys_error(err);
} }
req->file_flags; req->file_flags;
@ -1621,7 +1621,6 @@ int uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags,
return 0; return 0;
} else { } else {
fs__readdir(req); fs__readdir(req);
SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result; return req->result;
} }
} }
@ -1629,10 +1628,13 @@ int uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags,
int uv_fs_link(uv_loop_t* loop, uv_fs_t* req, const char* path, int uv_fs_link(uv_loop_t* loop, uv_fs_t* req, const char* path,
const char* new_path, uv_fs_cb cb) { const char* new_path, uv_fs_cb cb) {
int err;
uv_fs_req_init(loop, req, UV_FS_LINK, cb); uv_fs_req_init(loop, req, UV_FS_LINK, cb);
if (fs__capture_path(loop, req, path, new_path, cb != NULL) < 0) { err = fs__capture_path(loop, req, path, new_path, cb != NULL);
return -1; if (err) {
return uv_translate_sys_error(err);
} }
if (cb) { if (cb) {
@ -1640,7 +1642,6 @@ int uv_fs_link(uv_loop_t* loop, uv_fs_t* req, const char* path,
return 0; return 0;
} else { } else {
fs__link(req); fs__link(req);
SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result; return req->result;
} }
} }
@ -1648,10 +1649,13 @@ int uv_fs_link(uv_loop_t* loop, uv_fs_t* req, const char* path,
int uv_fs_symlink(uv_loop_t* loop, uv_fs_t* req, const char* path, int uv_fs_symlink(uv_loop_t* loop, uv_fs_t* req, const char* path,
const char* new_path, int flags, uv_fs_cb cb) { const char* new_path, int flags, uv_fs_cb cb) {
int err;
uv_fs_req_init(loop, req, UV_FS_SYMLINK, cb); uv_fs_req_init(loop, req, UV_FS_SYMLINK, cb);
if (fs__capture_path(loop, req, path, new_path, cb != NULL) < 0) { err = fs__capture_path(loop, req, path, new_path, cb != NULL);
return -1; if (err) {
return uv_translate_sys_error(err);
} }
req->file_flags = flags; req->file_flags = flags;
@ -1661,7 +1665,6 @@ int uv_fs_symlink(uv_loop_t* loop, uv_fs_t* req, const char* path,
return 0; return 0;
} else { } else {
fs__symlink(req); fs__symlink(req);
SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result; return req->result;
} }
} }
@ -1669,10 +1672,13 @@ int uv_fs_symlink(uv_loop_t* loop, uv_fs_t* req, const char* path,
int uv_fs_readlink(uv_loop_t* loop, uv_fs_t* req, const char* path, int uv_fs_readlink(uv_loop_t* loop, uv_fs_t* req, const char* path,
uv_fs_cb cb) { uv_fs_cb cb) {
int err;
uv_fs_req_init(loop, req, UV_FS_READLINK, cb); uv_fs_req_init(loop, req, UV_FS_READLINK, cb);
if (fs__capture_path(loop, req, path, NULL, cb != NULL) < 0) { err = fs__capture_path(loop, req, path, NULL, cb != NULL);
return -1; if (err) {
return uv_translate_sys_error(err);
} }
if (cb) { if (cb) {
@ -1680,7 +1686,6 @@ int uv_fs_readlink(uv_loop_t* loop, uv_fs_t* req, const char* path,
return 0; return 0;
} else { } else {
fs__readlink(req); fs__readlink(req);
SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result; return req->result;
} }
} }
@ -1688,10 +1693,13 @@ int uv_fs_readlink(uv_loop_t* loop, uv_fs_t* req, const char* path,
int uv_fs_chown(uv_loop_t* loop, uv_fs_t* req, const char* path, int uid, int uv_fs_chown(uv_loop_t* loop, uv_fs_t* req, const char* path, int uid,
int gid, uv_fs_cb cb) { int gid, uv_fs_cb cb) {
int err;
uv_fs_req_init(loop, req, UV_FS_CHOWN, cb); uv_fs_req_init(loop, req, UV_FS_CHOWN, cb);
if (fs__capture_path(loop, req, path, NULL, cb != NULL) < 0) { err = fs__capture_path(loop, req, path, NULL, cb != NULL);
return -1; if (err) {
return uv_translate_sys_error(err);
} }
if (cb) { if (cb) {
@ -1699,7 +1707,6 @@ int uv_fs_chown(uv_loop_t* loop, uv_fs_t* req, const char* path, int uid,
return 0; return 0;
} else { } else {
fs__chown(req); fs__chown(req);
SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result; return req->result;
} }
} }
@ -1714,17 +1721,19 @@ int uv_fs_fchown(uv_loop_t* loop, uv_fs_t* req, uv_file fd, int uid,
return 0; return 0;
} else { } else {
fs__fchown(req); fs__fchown(req);
SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result; return req->result;
} }
} }
int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
int err;
uv_fs_req_init(loop, req, UV_FS_STAT, cb); uv_fs_req_init(loop, req, UV_FS_STAT, cb);
if (fs__capture_path(loop, req, path, NULL, cb != NULL) < 0) { err = fs__capture_path(loop, req, path, NULL, cb != NULL);
return -1; if (err) {
return uv_translate_sys_error(err);
} }
if (cb) { if (cb) {
@ -1732,17 +1741,19 @@ int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
return 0; return 0;
} else { } else {
fs__stat(req); fs__stat(req);
SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result; return req->result;
} }
} }
int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
int err;
uv_fs_req_init(loop, req, UV_FS_LSTAT, cb); uv_fs_req_init(loop, req, UV_FS_LSTAT, cb);
if (fs__capture_path(loop, req, path, NULL, cb != NULL) < 0) { err = fs__capture_path(loop, req, path, NULL, cb != NULL);
return -1; if (err) {
return uv_translate_sys_error(err);
} }
if (cb) { if (cb) {
@ -1750,7 +1761,6 @@ int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
return 0; return 0;
} else { } else {
fs__lstat(req); fs__lstat(req);
SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result; return req->result;
} }
} }
@ -1765,7 +1775,6 @@ int uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file fd, uv_fs_cb cb) {
return 0; return 0;
} else { } else {
fs__fstat(req); fs__fstat(req);
SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result; return req->result;
} }
} }
@ -1773,10 +1782,13 @@ int uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file fd, uv_fs_cb cb) {
int uv_fs_rename(uv_loop_t* loop, uv_fs_t* req, const char* path, int uv_fs_rename(uv_loop_t* loop, uv_fs_t* req, const char* path,
const char* new_path, uv_fs_cb cb) { const char* new_path, uv_fs_cb cb) {
int err;
uv_fs_req_init(loop, req, UV_FS_RENAME, cb); uv_fs_req_init(loop, req, UV_FS_RENAME, cb);
if (fs__capture_path(loop, req, path, new_path, cb != NULL) < 0) { err = fs__capture_path(loop, req, path, new_path, cb != NULL);
return -1; if (err) {
return uv_translate_sys_error(err);
} }
if (cb) { if (cb) {
@ -1784,7 +1796,6 @@ int uv_fs_rename(uv_loop_t* loop, uv_fs_t* req, const char* path,
return 0; return 0;
} else { } else {
fs__rename(req); fs__rename(req);
SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result; return req->result;
} }
} }
@ -1799,7 +1810,6 @@ int uv_fs_fsync(uv_loop_t* loop, uv_fs_t* req, uv_file fd, uv_fs_cb cb) {
return 0; return 0;
} else { } else {
fs__fsync(req); fs__fsync(req);
SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result; return req->result;
} }
} }
@ -1814,7 +1824,6 @@ int uv_fs_fdatasync(uv_loop_t* loop, uv_fs_t* req, uv_file fd, uv_fs_cb cb) {
return 0; return 0;
} else { } else {
fs__fdatasync(req); fs__fdatasync(req);
SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result; return req->result;
} }
} }
@ -1832,7 +1841,6 @@ int uv_fs_ftruncate(uv_loop_t* loop, uv_fs_t* req, uv_file fd,
return 0; return 0;
} else { } else {
fs__ftruncate(req); fs__ftruncate(req);
SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result; return req->result;
} }
} }
@ -1853,7 +1861,6 @@ int uv_fs_sendfile(uv_loop_t* loop, uv_fs_t* req, uv_file fd_out,
return 0; return 0;
} else { } else {
fs__sendfile(req); fs__sendfile(req);
SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result; return req->result;
} }
} }
@ -1861,10 +1868,13 @@ int uv_fs_sendfile(uv_loop_t* loop, uv_fs_t* req, uv_file fd_out,
int uv_fs_chmod(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode, int uv_fs_chmod(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode,
uv_fs_cb cb) { uv_fs_cb cb) {
int err;
uv_fs_req_init(loop, req, UV_FS_CHMOD, cb); uv_fs_req_init(loop, req, UV_FS_CHMOD, cb);
if (fs__capture_path(loop, req, path, NULL, cb != NULL) < 0) { err = fs__capture_path(loop, req, path, NULL, cb != NULL);
return -1; if (err) {
return uv_translate_sys_error(err);
} }
req->mode = mode; req->mode = mode;
@ -1874,7 +1884,6 @@ int uv_fs_chmod(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode,
return 0; return 0;
} else { } else {
fs__chmod(req); fs__chmod(req);
SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result; return req->result;
} }
} }
@ -1892,7 +1901,6 @@ int uv_fs_fchmod(uv_loop_t* loop, uv_fs_t* req, uv_file fd, int mode,
return 0; return 0;
} else { } else {
fs__fchmod(req); fs__fchmod(req);
SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result; return req->result;
} }
} }
@ -1900,10 +1908,13 @@ int uv_fs_fchmod(uv_loop_t* loop, uv_fs_t* req, uv_file fd, int mode,
int uv_fs_utime(uv_loop_t* loop, uv_fs_t* req, const char* path, double atime, int uv_fs_utime(uv_loop_t* loop, uv_fs_t* req, const char* path, double atime,
double mtime, uv_fs_cb cb) { double mtime, uv_fs_cb cb) {
int err;
uv_fs_req_init(loop, req, UV_FS_UTIME, cb); uv_fs_req_init(loop, req, UV_FS_UTIME, cb);
if (fs__capture_path(loop, req, path, NULL, cb != NULL) < 0) { err = fs__capture_path(loop, req, path, NULL, cb != NULL);
return -1; if (err) {
return uv_translate_sys_error(err);
} }
req->atime = atime; req->atime = atime;
@ -1914,7 +1925,6 @@ int uv_fs_utime(uv_loop_t* loop, uv_fs_t* req, const char* path, double atime,
return 0; return 0;
} else { } else {
fs__utime(req); fs__utime(req);
SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result; return req->result;
} }
} }
@ -1933,7 +1943,6 @@ int uv_fs_futime(uv_loop_t* loop, uv_fs_t* req, uv_file fd, double atime,
return 0; return 0;
} else { } else {
fs__futime(req); fs__futime(req);
SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result; return req->result;
} }
} }
@ -1942,7 +1951,6 @@ int uv_fs_futime(uv_loop_t* loop, uv_fs_t* req, uv_file fd, double atime,
void uv_process_fs_req(uv_loop_t* loop, uv_fs_t* req) { void uv_process_fs_req(uv_loop_t* loop, uv_fs_t* req) {
assert(req->cb); assert(req->cb);
uv__req_unregister(loop, req); uv__req_unregister(loop, req);
SET_UV_LAST_ERROR_FROM_REQ(req);
req->cb(req); req->cb(req);
} }

53
deps/uv/src/win/getaddrinfo.c

@ -56,26 +56,6 @@
#define ALIGNED_SIZE(X) ((((X) + 3) >> 2) << 2) #define ALIGNED_SIZE(X) ((((X) + 3) >> 2) << 2)
/*
* getaddrinfo error code mapping
* Falls back to uv_translate_sys_error if no match
*/
static uv_err_code uv_translate_eai_error(int eai_errno) {
switch (eai_errno) {
case ERROR_SUCCESS: return UV_OK;
case EAI_BADFLAGS: return UV_EBADF;
case EAI_FAIL: return UV_EFAULT;
case EAI_FAMILY: return UV_EAIFAMNOSUPPORT;
case EAI_MEMORY: return UV_ENOMEM;
case EAI_NONAME: return UV_ENOENT;
case EAI_AGAIN: return UV_EAGAIN;
case EAI_SERVICE: return UV_EAISERVICE;
case EAI_SOCKTYPE: return UV_EAISOCKTYPE;
default: return uv_translate_sys_error(eai_errno);
}
}
/* getaddrinfo worker thread implementation */ /* getaddrinfo worker thread implementation */
static DWORD WINAPI getaddrinfo_thread_proc(void* parameter) { static DWORD WINAPI getaddrinfo_thread_proc(void* parameter) {
uv_getaddrinfo_t* req = (uv_getaddrinfo_t*) parameter; uv_getaddrinfo_t* req = (uv_getaddrinfo_t*) parameter;
@ -115,7 +95,7 @@ void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t* req) {
struct addrinfo* addrinfo_ptr; struct addrinfo* addrinfo_ptr;
char* alloc_ptr = NULL; char* alloc_ptr = NULL;
char* cur_ptr = NULL; char* cur_ptr = NULL;
int status = 0; int err = 0;
/* release input parameter memory */ /* release input parameter memory */
if (req->alloc != NULL) { if (req->alloc != NULL) {
@ -133,8 +113,8 @@ void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t* req) {
if (addrinfow_ptr->ai_canonname != NULL) { if (addrinfow_ptr->ai_canonname != NULL) {
name_len = uv_utf16_to_utf8(addrinfow_ptr->ai_canonname, -1, NULL, 0); name_len = uv_utf16_to_utf8(addrinfow_ptr->ai_canonname, -1, NULL, 0);
if (name_len == 0) { if (name_len == 0) {
uv__set_sys_error(loop, GetLastError()); /* FIXME(bnoordhuis) Retain GetLastError(). */
status = -1; err = UV_EAI_SYSTEM;
goto complete; goto complete;
} }
addrinfo_len += ALIGNED_SIZE(name_len); addrinfo_len += ALIGNED_SIZE(name_len);
@ -199,13 +179,11 @@ void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t* req) {
} }
} }
} else { } else {
uv__set_artificial_error(loop, UV_ENOMEM); err = UV_EAI_MEMORY;
status = -1;
} }
} else { } else {
/* GetAddrInfo failed */ /* GetAddrInfo failed */
uv__set_artificial_error(loop, uv_translate_eai_error(req->retcode)); err = uv__getaddrinfo_translate_error(req->retcode);
status = -1;
} }
/* return memory to system */ /* return memory to system */
@ -218,7 +196,7 @@ complete:
uv__req_unregister(loop, req); uv__req_unregister(loop, req);
/* finally do callback with converted result */ /* finally do callback with converted result */
req->getaddrinfo_cb(req, status, (struct addrinfo*)alloc_ptr); req->getaddrinfo_cb(req, err, (struct addrinfo*)alloc_ptr);
} }
@ -238,7 +216,7 @@ void uv_freeaddrinfo(struct addrinfo* ai) {
* and save the UNICODE string pointers in the req * and save the UNICODE string pointers in the req
* We also copy hints so that caller does not need to keep memory until the * We also copy hints so that caller does not need to keep memory until the
* callback. * callback.
* return UV_OK if a callback will be made * return 0 if a callback will be made
* return error code if validation fails * return error code if validation fails
* *
* To minimize allocation we calculate total size required, * To minimize allocation we calculate total size required,
@ -255,10 +233,11 @@ int uv_getaddrinfo(uv_loop_t* loop,
int servicesize = 0; int servicesize = 0;
int hintssize = 0; int hintssize = 0;
char* alloc_ptr = NULL; char* alloc_ptr = NULL;
int err;
if (req == NULL || getaddrinfo_cb == NULL || if (req == NULL || getaddrinfo_cb == NULL ||
(node == NULL && service == NULL)) { (node == NULL && service == NULL)) {
uv__set_sys_error(loop, WSAEINVAL); err = WSAEINVAL;
goto error; goto error;
} }
@ -273,7 +252,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
if (node != NULL) { if (node != NULL) {
nodesize = ALIGNED_SIZE(uv_utf8_to_utf16(node, NULL, 0) * sizeof(WCHAR)); nodesize = ALIGNED_SIZE(uv_utf8_to_utf16(node, NULL, 0) * sizeof(WCHAR));
if (nodesize == 0) { if (nodesize == 0) {
uv__set_sys_error(loop, GetLastError()); err = GetLastError();
goto error; goto error;
} }
} }
@ -282,7 +261,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
servicesize = ALIGNED_SIZE(uv_utf8_to_utf16(service, NULL, 0) * servicesize = ALIGNED_SIZE(uv_utf8_to_utf16(service, NULL, 0) *
sizeof(WCHAR)); sizeof(WCHAR));
if (servicesize == 0) { if (servicesize == 0) {
uv__set_sys_error(loop, GetLastError()); err = GetLastError();
goto error; goto error;
} }
} }
@ -293,7 +272,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
/* allocate memory for inputs, and partition it as needed */ /* allocate memory for inputs, and partition it as needed */
alloc_ptr = (char*)malloc(nodesize + servicesize + hintssize); alloc_ptr = (char*)malloc(nodesize + servicesize + hintssize);
if (!alloc_ptr) { if (!alloc_ptr) {
uv__set_sys_error(loop, WSAENOBUFS); err = WSAENOBUFS;
goto error; goto error;
} }
@ -307,7 +286,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
if (uv_utf8_to_utf16(node, if (uv_utf8_to_utf16(node,
(WCHAR*) alloc_ptr, (WCHAR*) alloc_ptr,
nodesize / sizeof(WCHAR)) == 0) { nodesize / sizeof(WCHAR)) == 0) {
uv__set_sys_error(loop, GetLastError()); err = GetLastError();
goto error; goto error;
} }
alloc_ptr += nodesize; alloc_ptr += nodesize;
@ -322,7 +301,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
if (uv_utf8_to_utf16(service, if (uv_utf8_to_utf16(service,
(WCHAR*) alloc_ptr, (WCHAR*) alloc_ptr,
servicesize / sizeof(WCHAR)) == 0) { servicesize / sizeof(WCHAR)) == 0) {
uv__set_sys_error(loop, GetLastError()); err = GetLastError();
goto error; goto error;
} }
alloc_ptr += servicesize; alloc_ptr += servicesize;
@ -349,7 +328,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
if (QueueUserWorkItem(&getaddrinfo_thread_proc, if (QueueUserWorkItem(&getaddrinfo_thread_proc,
req, req,
WT_EXECUTELONGFUNCTION) == 0) { WT_EXECUTELONGFUNCTION) == 0) {
uv__set_sys_error(loop, GetLastError()); err = GetLastError();
goto error; goto error;
} }
@ -361,5 +340,5 @@ error:
if (req != NULL && req->alloc != NULL) { if (req != NULL && req->alloc != NULL) {
free(req->alloc); free(req->alloc);
} }
return -1; return uv_translate_sys_error(err);
} }

13
deps/uv/src/win/internal.h

@ -135,7 +135,7 @@ void uv_udp_endgame(uv_loop_t* loop, uv_udp_t* handle);
/* /*
* Pipes * Pipes
*/ */
uv_err_t uv_stdio_pipe_server(uv_loop_t* loop, uv_pipe_t* handle, DWORD access, int uv_stdio_pipe_server(uv_loop_t* loop, uv_pipe_t* handle, DWORD access,
char* name, size_t nameSize); char* name, size_t nameSize);
int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb); int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb);
@ -197,7 +197,7 @@ void uv_tty_endgame(uv_loop_t* loop, uv_tty_t* handle);
void uv_process_poll_req(uv_loop_t* loop, uv_poll_t* handle, void uv_process_poll_req(uv_loop_t* loop, uv_poll_t* handle,
uv_req_t* req); uv_req_t* req);
void uv_poll_close(uv_loop_t* loop, uv_poll_t* handle); int uv_poll_close(uv_loop_t* loop, uv_poll_t* handle);
void uv_poll_endgame(uv_loop_t* loop, uv_poll_t* handle); void uv_poll_endgame(uv_loop_t* loop, uv_poll_t* handle);
@ -254,6 +254,12 @@ void uv_process_close(uv_loop_t* loop, uv_process_t* handle);
void uv_process_endgame(uv_loop_t* loop, uv_process_t* handle); void uv_process_endgame(uv_loop_t* loop, uv_process_t* handle);
/*
* Error
*/
int uv_translate_sys_error(int sys_errno);
/* /*
* Getaddrinfo * Getaddrinfo
*/ */
@ -295,13 +301,12 @@ void uv__util_init();
int uv_parent_pid(); int uv_parent_pid();
void uv_fatal_error(const int errorno, const char* syscall); void uv_fatal_error(const int errorno, const char* syscall);
uv_err_code uv_translate_sys_error(int sys_errno);
/* /*
* Process stdio handles. * Process stdio handles.
*/ */
uv_err_t uv__stdio_create(uv_loop_t* loop, uv_process_options_t* options, int uv__stdio_create(uv_loop_t* loop, uv_process_options_t* options,
BYTE** buffer_ptr); BYTE** buffer_ptr);
void uv__stdio_destroy(BYTE* buffer); void uv__stdio_destroy(BYTE* buffer);
void uv__stdio_noinherit(BYTE* buffer); void uv__stdio_noinherit(BYTE* buffer);

2
deps/uv/src/win/loop-watcher.c

@ -53,7 +53,7 @@ void uv_loop_watcher_endgame(uv_loop_t* loop, uv_handle_t* handle) {
return 0; \ return 0; \
\ \
if (cb == NULL) \ if (cb == NULL) \
return uv__set_artificial_error(handle->loop, UV_EINVAL); \ return UV_EINVAL; \
\ \
old_head = loop->name##_handles; \ old_head = loop->name##_handles; \
\ \

155
deps/uv/src/win/pipe.c

@ -157,11 +157,10 @@ static HANDLE open_named_pipe(WCHAR* name, DWORD* duplex_flags) {
} }
uv_err_t uv_stdio_pipe_server(uv_loop_t* loop, uv_pipe_t* handle, DWORD access, int uv_stdio_pipe_server(uv_loop_t* loop, uv_pipe_t* handle, DWORD access,
char* name, size_t nameSize) { char* name, size_t nameSize) {
HANDLE pipeHandle; HANDLE pipeHandle;
int errorno; int err;
uv_err_t err;
char* ptr = (char*)handle; char* ptr = (char*)handle;
for (;;) { for (;;) {
@ -177,9 +176,8 @@ uv_err_t uv_stdio_pipe_server(uv_loop_t* loop, uv_pipe_t* handle, DWORD access,
break; break;
} }
errorno = GetLastError(); err = GetLastError();
if (errorno != ERROR_PIPE_BUSY && errorno != ERROR_ACCESS_DENIED) { if (err != ERROR_PIPE_BUSY && err != ERROR_ACCESS_DENIED) {
err = uv__new_sys_error(errorno);
goto error; goto error;
} }
@ -191,14 +189,14 @@ uv_err_t uv_stdio_pipe_server(uv_loop_t* loop, uv_pipe_t* handle, DWORD access,
loop->iocp, loop->iocp,
(ULONG_PTR)handle, (ULONG_PTR)handle,
0) == NULL) { 0) == NULL) {
err = uv__new_sys_error(GetLastError()); err = GetLastError();
goto error; goto error;
} }
uv_pipe_connection_init(handle); uv_pipe_connection_init(handle);
handle->handle = pipeHandle; handle->handle = pipeHandle;
return uv_ok_; return 0;
error: error:
if (pipeHandle != INVALID_HANDLE_VALUE) { if (pipeHandle != INVALID_HANDLE_VALUE) {
@ -278,6 +276,7 @@ static DWORD WINAPI pipe_shutdown_thread_proc(void* parameter) {
void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) { void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) {
int err;
DWORD result; DWORD result;
uv_shutdown_t* req; uv_shutdown_t* req;
NTSTATUS nt_status; NTSTATUS nt_status;
@ -297,8 +296,7 @@ void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) {
/* Already closing. Cancel the shutdown. */ /* Already closing. Cancel the shutdown. */
if (req->cb) { if (req->cb) {
uv__set_artificial_error(loop, UV_ECANCELED); req->cb(req, UV_ECANCELED);
req->cb(req, -1);
} }
DECREASE_PENDING_REQ_COUNT(handle); DECREASE_PENDING_REQ_COUNT(handle);
@ -318,8 +316,8 @@ void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) {
handle->flags |= UV_HANDLE_WRITABLE; /* Questionable */ handle->flags |= UV_HANDLE_WRITABLE; /* Questionable */
if (req->cb) { if (req->cb) {
uv__set_sys_error(loop, pRtlNtStatusToDosError(nt_status)); err = pRtlNtStatusToDosError(nt_status);
req->cb(req, -1); req->cb(req, uv_translate_sys_error(err));
} }
DECREASE_PENDING_REQ_COUNT(handle); DECREASE_PENDING_REQ_COUNT(handle);
@ -345,8 +343,8 @@ void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) {
handle->flags |= UV_HANDLE_WRITABLE; /* Questionable */ handle->flags |= UV_HANDLE_WRITABLE; /* Questionable */
if (req->cb) { if (req->cb) {
uv__set_sys_error(loop, GetLastError()); err = GetLastError();
req->cb(req, -1); req->cb(req, uv_translate_sys_error(err));
} }
DECREASE_PENDING_REQ_COUNT(handle); DECREASE_PENDING_REQ_COUNT(handle);
@ -396,17 +394,15 @@ void uv_pipe_pending_instances(uv_pipe_t* handle, int count) {
/* Creates a pipe server. */ /* Creates a pipe server. */
int uv_pipe_bind(uv_pipe_t* handle, const char* name) { int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
uv_loop_t* loop = handle->loop; uv_loop_t* loop = handle->loop;
int i, errorno, nameSize; int i, err, nameSize;
uv_pipe_accept_t* req; uv_pipe_accept_t* req;
if (handle->flags & UV_HANDLE_BOUND) { if (handle->flags & UV_HANDLE_BOUND) {
uv__set_sys_error(loop, WSAEINVAL); return UV_EINVAL;
return -1;
} }
if (!name) { if (!name) {
uv__set_sys_error(loop, WSAEINVAL); return UV_EINVAL;
return -1;
} }
if (!(handle->flags & UV_HANDLE_PIPESERVER)) { if (!(handle->flags & UV_HANDLE_PIPESERVER)) {
@ -436,8 +432,7 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
} }
if (!uv_utf8_to_utf16(name, handle->name, nameSize / sizeof(WCHAR))) { if (!uv_utf8_to_utf16(name, handle->name, nameSize / sizeof(WCHAR))) {
uv__set_sys_error(loop, GetLastError()); return uv_translate_sys_error(GetLastError());
return -1;
} }
/* /*
@ -451,19 +446,17 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
PIPE_UNLIMITED_INSTANCES, 65536, 65536, 0, NULL); PIPE_UNLIMITED_INSTANCES, 65536, 65536, 0, NULL);
if (handle->accept_reqs[0].pipeHandle == INVALID_HANDLE_VALUE) { if (handle->accept_reqs[0].pipeHandle == INVALID_HANDLE_VALUE) {
errorno = GetLastError(); err = GetLastError();
if (errorno == ERROR_ACCESS_DENIED) { if (err == ERROR_ACCESS_DENIED) {
uv__set_error(loop, UV_EADDRINUSE, errorno); err = WSAEADDRINUSE; /* Translates to UV_EADDRINUSE. */
} else if (errorno == ERROR_PATH_NOT_FOUND || errorno == ERROR_INVALID_NAME) { } else if (err == ERROR_PATH_NOT_FOUND || err == ERROR_INVALID_NAME) {
uv__set_error(loop, UV_EACCES, errorno); err = WSAEACCES; /* Translates to UV_EACCES. */
} else {
uv__set_sys_error(loop, errorno);
} }
goto error; goto error;
} }
if (uv_set_pipe_handle(loop, handle, handle->accept_reqs[0].pipeHandle, 0)) { if (uv_set_pipe_handle(loop, handle, handle->accept_reqs[0].pipeHandle, 0)) {
uv__set_sys_error(loop, GetLastError()); err = GetLastError();
goto error; goto error;
} }
@ -484,7 +477,7 @@ error:
handle->accept_reqs[0].pipeHandle = INVALID_HANDLE_VALUE; handle->accept_reqs[0].pipeHandle = INVALID_HANDLE_VALUE;
} }
return -1; return uv_translate_sys_error(err);
} }
@ -531,7 +524,7 @@ static DWORD WINAPI pipe_connect_thread_proc(void* parameter) {
void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle, void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle,
const char* name, uv_connect_cb cb) { const char* name, uv_connect_cb cb) {
uv_loop_t* loop = handle->loop; uv_loop_t* loop = handle->loop;
int errorno, nameSize; int err, nameSize;
HANDLE pipeHandle = INVALID_HANDLE_VALUE; HANDLE pipeHandle = INVALID_HANDLE_VALUE;
DWORD duplex_flags; DWORD duplex_flags;
@ -548,7 +541,7 @@ void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle,
} }
if (!uv_utf8_to_utf16(name, handle->name, nameSize / sizeof(WCHAR))) { if (!uv_utf8_to_utf16(name, handle->name, nameSize / sizeof(WCHAR))) {
errorno = GetLastError(); err = GetLastError();
goto error; goto error;
} }
@ -559,7 +552,7 @@ void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle,
if (!QueueUserWorkItem(&pipe_connect_thread_proc, if (!QueueUserWorkItem(&pipe_connect_thread_proc,
req, req,
WT_EXECUTELONGFUNCTION)) { WT_EXECUTELONGFUNCTION)) {
errorno = GetLastError(); err = GetLastError();
goto error; goto error;
} }
@ -569,7 +562,7 @@ void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle,
return; return;
} }
errorno = GetLastError(); err = GetLastError();
goto error; goto error;
} }
@ -579,7 +572,7 @@ void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle,
(uv_pipe_t*) req->handle, (uv_pipe_t*) req->handle,
pipeHandle, pipeHandle,
duplex_flags)) { duplex_flags)) {
errorno = GetLastError(); err = GetLastError();
goto error; goto error;
} }
@ -600,7 +593,7 @@ error:
} }
/* Make this req pending reporting an error. */ /* Make this req pending reporting an error. */
SET_REQ_ERROR(req, errorno); SET_REQ_ERROR(req, err);
uv_insert_pending_req(loop, (uv_req_t*) req); uv_insert_pending_req(loop, (uv_req_t*) req);
handle->reqs_pending++; handle->reqs_pending++;
REGISTER_HANDLE_REQ(loop, handle, req); REGISTER_HANDLE_REQ(loop, handle, req);
@ -725,8 +718,7 @@ int uv_pipe_accept(uv_pipe_t* server, uv_stream_t* client) {
if (server->ipc) { if (server->ipc) {
if (!server->pending_ipc_info.socket_info) { if (!server->pending_ipc_info.socket_info) {
/* No valid pending sockets. */ /* No valid pending sockets. */
uv__set_sys_error(loop, WSAEWOULDBLOCK); return WSAEWOULDBLOCK;
return -1;
} }
return uv_tcp_import((uv_tcp_t*)client, server->pending_ipc_info.socket_info, return uv_tcp_import((uv_tcp_t*)client, server->pending_ipc_info.socket_info,
@ -740,8 +732,7 @@ int uv_pipe_accept(uv_pipe_t* server, uv_stream_t* client) {
if (!req) { if (!req) {
/* No valid connections found, so we error out. */ /* No valid connections found, so we error out. */
uv__set_sys_error(loop, WSAEWOULDBLOCK); return WSAEWOULDBLOCK;
return -1;
} }
/* Initialize the client handle and copy the pipeHandle to the client */ /* Initialize the client handle and copy the pipeHandle to the client */
@ -773,18 +764,15 @@ int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) {
} }
if (!(handle->flags & UV_HANDLE_BOUND)) { if (!(handle->flags & UV_HANDLE_BOUND)) {
uv__set_artificial_error(loop, UV_EINVAL); return WSAEINVAL;
return -1;
} }
if (handle->flags & UV_HANDLE_READING) { if (handle->flags & UV_HANDLE_READING) {
uv__set_artificial_error(loop, UV_EISCONN); return WSAEISCONN;
return -1;
} }
if (!(handle->flags & UV_HANDLE_PIPESERVER)) { if (!(handle->flags & UV_HANDLE_PIPESERVER)) {
uv__set_artificial_error(loop, UV_ENOTSUP); return ERROR_NOT_SUPPORTED;
return -1;
} }
handle->flags |= UV_HANDLE_LISTENING; handle->flags |= UV_HANDLE_LISTENING;
@ -1044,22 +1032,21 @@ static void uv_queue_non_overlapped_write(uv_pipe_t* handle) {
static int uv_pipe_write_impl(uv_loop_t* loop, uv_write_t* req, static int uv_pipe_write_impl(uv_loop_t* loop, uv_write_t* req,
uv_pipe_t* handle, uv_buf_t bufs[], int bufcnt, uv_pipe_t* handle, uv_buf_t bufs[], int bufcnt,
uv_stream_t* send_handle, uv_write_cb cb) { uv_stream_t* send_handle, uv_write_cb cb) {
int err;
int result; int result;
uv_tcp_t* tcp_send_handle; uv_tcp_t* tcp_send_handle;
uv_write_t* ipc_header_req; uv_write_t* ipc_header_req;
uv_ipc_frame_uv_stream ipc_frame; uv_ipc_frame_uv_stream ipc_frame;
if (bufcnt != 1 && (bufcnt != 0 || !send_handle)) { if (bufcnt != 1 && (bufcnt != 0 || !send_handle)) {
uv__set_artificial_error(loop, UV_ENOTSUP); return ERROR_NOT_SUPPORTED;
return -1;
} }
/* Only TCP handles are supported for sharing. */ /* Only TCP handles are supported for sharing. */
if (send_handle && ((send_handle->type != UV_TCP) || if (send_handle && ((send_handle->type != UV_TCP) ||
(!(send_handle->flags & UV_HANDLE_BOUND) && (!(send_handle->flags & UV_HANDLE_BOUND) &&
!(send_handle->flags & UV_HANDLE_CONNECTION)))) { !(send_handle->flags & UV_HANDLE_CONNECTION)))) {
uv__set_artificial_error(loop, UV_ENOTSUP); return ERROR_NOT_SUPPORTED;
return -1;
} }
assert(handle->handle != INVALID_HANDLE_VALUE); assert(handle->handle != INVALID_HANDLE_VALUE);
@ -1081,9 +1068,10 @@ static int uv_pipe_write_impl(uv_loop_t* loop, uv_write_t* req,
if (send_handle) { if (send_handle) {
tcp_send_handle = (uv_tcp_t*)send_handle; tcp_send_handle = (uv_tcp_t*)send_handle;
if (uv_tcp_duplicate_socket(tcp_send_handle, handle->ipc_pid, err = uv_tcp_duplicate_socket(tcp_send_handle, handle->ipc_pid,
&ipc_frame.socket_info)) { &ipc_frame.socket_info);
return -1; if (err) {
return err;
} }
ipc_frame.header.flags |= UV_IPC_TCP_SERVER; ipc_frame.header.flags |= UV_IPC_TCP_SERVER;
@ -1142,18 +1130,18 @@ static int uv_pipe_write_impl(uv_loop_t* loop, uv_write_t* req,
NULL, NULL,
&ipc_header_req->overlapped); &ipc_header_req->overlapped);
if (!result && GetLastError() != ERROR_IO_PENDING) { if (!result && GetLastError() != ERROR_IO_PENDING) {
uv__set_sys_error(loop, GetLastError()); err = GetLastError();
CloseHandle(ipc_header_req->overlapped.hEvent); CloseHandle(ipc_header_req->overlapped.hEvent);
return -1; return err;
} }
if (!result) { if (!result) {
/* Request not completed immediately. Wait for it.*/ /* Request not completed immediately. Wait for it.*/
if (WaitForSingleObject(ipc_header_req->overlapped.hEvent, INFINITE) != if (WaitForSingleObject(ipc_header_req->overlapped.hEvent, INFINITE) !=
WAIT_OBJECT_0) { WAIT_OBJECT_0) {
uv__set_sys_error(loop, GetLastError()); err = GetLastError();
CloseHandle(ipc_header_req->overlapped.hEvent); CloseHandle(ipc_header_req->overlapped.hEvent);
return -1; return err;
} }
} }
ipc_header_req->queued_bytes = 0; ipc_header_req->queued_bytes = 0;
@ -1181,7 +1169,7 @@ static int uv_pipe_write_impl(uv_loop_t* loop, uv_write_t* req,
NULL); NULL);
if (!result) { if (!result) {
return uv__set_sys_error(loop, GetLastError()); return err;
} else { } else {
/* Request completed immediately. */ /* Request completed immediately. */
req->queued_bytes = 0; req->queued_bytes = 0;
@ -1216,9 +1204,9 @@ static int uv_pipe_write_impl(uv_loop_t* loop, uv_write_t* req,
&req->overlapped); &req->overlapped);
if (!result && GetLastError() != ERROR_IO_PENDING) { if (!result && GetLastError() != ERROR_IO_PENDING) {
uv__set_sys_error(loop, GetLastError()); err = GetLastError();
CloseHandle(req->overlapped.hEvent); CloseHandle(req->overlapped.hEvent);
return -1; return err;
} }
if (result) { if (result) {
@ -1228,9 +1216,9 @@ static int uv_pipe_write_impl(uv_loop_t* loop, uv_write_t* req,
/* Request queued by the kernel. */ /* Request queued by the kernel. */
if (WaitForSingleObject(ipc_header_req->overlapped.hEvent, INFINITE) != if (WaitForSingleObject(ipc_header_req->overlapped.hEvent, INFINITE) !=
WAIT_OBJECT_0) { WAIT_OBJECT_0) {
uv__set_sys_error(loop, GetLastError()); err = GetLastError();
CloseHandle(ipc_header_req->overlapped.hEvent); CloseHandle(ipc_header_req->overlapped.hEvent);
return -1; return uv_translate_sys_error(err);
} }
} }
CloseHandle(req->overlapped.hEvent); CloseHandle(req->overlapped.hEvent);
@ -1248,8 +1236,7 @@ static int uv_pipe_write_impl(uv_loop_t* loop, uv_write_t* req,
&req->overlapped); &req->overlapped);
if (!result && GetLastError() != ERROR_IO_PENDING) { if (!result && GetLastError() != ERROR_IO_PENDING) {
uv__set_sys_error(loop, GetLastError()); return GetLastError();
return -1;
} }
if (result) { if (result) {
@ -1269,8 +1256,7 @@ static int uv_pipe_write_impl(uv_loop_t* loop, uv_write_t* req,
if (!RegisterWaitForSingleObject(&req->wait_handle, if (!RegisterWaitForSingleObject(&req->wait_handle,
req->overlapped.hEvent, post_completion_write_wait, (void*) req, req->overlapped.hEvent, post_completion_write_wait, (void*) req,
INFINITE, WT_EXECUTEINWAITTHREAD)) { INFINITE, WT_EXECUTEINWAITTHREAD)) {
uv__set_sys_error(loop, GetLastError()); return GetLastError();
return -1;
} }
} }
} }
@ -1292,8 +1278,7 @@ int uv_pipe_write(uv_loop_t* loop, uv_write_t* req, uv_pipe_t* handle,
int uv_pipe_write2(uv_loop_t* loop, uv_write_t* req, uv_pipe_t* handle, int uv_pipe_write2(uv_loop_t* loop, uv_write_t* req, uv_pipe_t* handle,
uv_buf_t bufs[], int bufcnt, uv_stream_t* send_handle, uv_write_cb cb) { uv_buf_t bufs[], int bufcnt, uv_stream_t* send_handle, uv_write_cb cb) {
if (!handle->ipc) { if (!handle->ipc) {
uv__set_artificial_error(loop, UV_EINVAL); return WSAEINVAL;
return -1;
} }
return uv_pipe_write_impl(loop, req, handle, bufs, bufcnt, send_handle, cb); return uv_pipe_write_impl(loop, req, handle, bufs, bufcnt, send_handle, cb);
@ -1309,11 +1294,10 @@ static void uv_pipe_read_eof(uv_loop_t* loop, uv_pipe_t* handle,
handle->flags &= ~UV_HANDLE_READABLE; handle->flags &= ~UV_HANDLE_READABLE;
uv_read_stop((uv_stream_t*) handle); uv_read_stop((uv_stream_t*) handle);
uv__set_artificial_error(loop, UV_EOF);
if (handle->read2_cb) { if (handle->read2_cb) {
handle->read2_cb(handle, -1, uv_null_buf_, UV_UNKNOWN_HANDLE); handle->read2_cb(handle, UV_EOF, uv_null_buf_, UV_UNKNOWN_HANDLE);
} else { } else {
handle->read_cb((uv_stream_t*) handle, -1, uv_null_buf_); handle->read_cb((uv_stream_t*) handle, UV_EOF, uv_null_buf_);
} }
} }
@ -1326,11 +1310,13 @@ static void uv_pipe_read_error(uv_loop_t* loop, uv_pipe_t* handle, int error,
uv_read_stop((uv_stream_t*) handle); uv_read_stop((uv_stream_t*) handle);
uv__set_sys_error(loop, error);
if (handle->read2_cb) { if (handle->read2_cb) {
handle->read2_cb(handle, -1, buf, UV_UNKNOWN_HANDLE); handle->read2_cb(handle,
uv_translate_sys_error(error),
buf,
UV_UNKNOWN_HANDLE);
} else { } else {
handle->read_cb((uv_stream_t*)handle, -1, buf); handle->read_cb((uv_stream_t*)handle, uv_translate_sys_error(error), buf);
} }
} }
@ -1493,6 +1479,8 @@ void uv_process_pipe_read_req(uv_loop_t* loop, uv_pipe_t* handle,
void uv_process_pipe_write_req(uv_loop_t* loop, uv_pipe_t* handle, void uv_process_pipe_write_req(uv_loop_t* loop, uv_pipe_t* handle,
uv_write_t* req) { uv_write_t* req) {
int err;
assert(handle->type == UV_NAMED_PIPE); assert(handle->type == UV_NAMED_PIPE);
assert(handle->write_queue_size >= req->queued_bytes); assert(handle->write_queue_size >= req->queued_bytes);
@ -1519,12 +1507,8 @@ void uv_process_pipe_write_req(uv_loop_t* loop, uv_pipe_t* handle,
} }
} else { } else {
if (req->cb) { if (req->cb) {
if (!REQ_SUCCESS(req)) { err = GET_REQ_ERROR(req);
uv__set_sys_error(loop, GET_REQ_ERROR(req)); req->cb(req, uv_translate_sys_error(err));
((uv_write_cb)req->cb)(req, -1);
} else {
((uv_write_cb)req->cb)(req, 0);
}
} }
} }
@ -1575,18 +1559,20 @@ void uv_process_pipe_accept_req(uv_loop_t* loop, uv_pipe_t* handle,
void uv_process_pipe_connect_req(uv_loop_t* loop, uv_pipe_t* handle, void uv_process_pipe_connect_req(uv_loop_t* loop, uv_pipe_t* handle,
uv_connect_t* req) { uv_connect_t* req) {
int err;
assert(handle->type == UV_NAMED_PIPE); assert(handle->type == UV_NAMED_PIPE);
UNREGISTER_HANDLE_REQ(loop, handle, req); UNREGISTER_HANDLE_REQ(loop, handle, req);
if (req->cb) { if (req->cb) {
err = 0;
if (REQ_SUCCESS(req)) { if (REQ_SUCCESS(req)) {
uv_pipe_connection_init(handle); uv_pipe_connection_init(handle);
((uv_connect_cb)req->cb)(req, 0);
} else { } else {
uv__set_sys_error(loop, GET_REQ_ERROR(req)); err = GET_REQ_ERROR(req);
((uv_connect_cb)req->cb)(req, -1);
} }
req->cb(req, uv_translate_sys_error(err));
} }
DECREASE_PENDING_REQ_COUNT(handle); DECREASE_PENDING_REQ_COUNT(handle);
@ -1710,8 +1696,7 @@ int uv_pipe_open(uv_pipe_t* pipe, uv_file file) {
if (os_handle == INVALID_HANDLE_VALUE || if (os_handle == INVALID_HANDLE_VALUE ||
uv_set_pipe_handle(pipe->loop, pipe, os_handle, 0) == -1) { uv_set_pipe_handle(pipe->loop, pipe, os_handle, 0) == -1) {
uv__set_sys_error(pipe->loop, WSAEINVAL); return UV_EINVAL;
return -1;
} }
uv_pipe_connection_init(pipe); uv_pipe_connection_init(pipe);

50
deps/uv/src/win/poll.c

@ -135,8 +135,7 @@ static int uv__fast_poll_cancel_poll_req(uv_loop_t* loop, uv_poll_t* handle) {
if (result == SOCKET_ERROR) { if (result == SOCKET_ERROR) {
DWORD error = WSAGetLastError(); DWORD error = WSAGetLastError();
if (error != WSA_IO_PENDING) { if (error != WSA_IO_PENDING) {
uv__set_sys_error(loop, WSAGetLastError()); return WSAGetLastError();
return -1;
} }
} }
@ -166,8 +165,7 @@ static void uv__fast_poll_process_poll_req(uv_loop_t* loop, uv_poll_t* handle,
DWORD error = GET_REQ_SOCK_ERROR(req); DWORD error = GET_REQ_SOCK_ERROR(req);
if (error != WSAEINTR && handle->events != 0) { if (error != WSAEINTR && handle->events != 0) {
handle->events = 0; /* Stop the watcher */ handle->events = 0; /* Stop the watcher */
uv__set_sys_error(loop, error); handle->poll_cb(handle, uv_translate_sys_error(error), 0);
handle->poll_cb(handle, -1, 0);
} }
} else if (afd_poll_info->NumberOfHandles >= 1) { } else if (afd_poll_info->NumberOfHandles >= 1) {
@ -228,17 +226,18 @@ static int uv__fast_poll_set(uv_loop_t* loop, uv_poll_t* handle, int events) {
} }
static void uv__fast_poll_close(uv_loop_t* loop, uv_poll_t* handle) { static int uv__fast_poll_close(uv_loop_t* loop, uv_poll_t* handle) {
handle->events = 0; handle->events = 0;
uv__handle_closing(handle); uv__handle_closing(handle);
if (handle->submitted_events_1 == 0 && if (handle->submitted_events_1 == 0 &&
handle->submitted_events_2 == 0) { handle->submitted_events_2 == 0) {
uv_want_endgame(loop, (uv_handle_t*) handle); uv_want_endgame(loop, (uv_handle_t*) handle);
return 0;
} else { } else {
/* Cancel outstanding poll requests by executing another, unique poll */ /* Cancel outstanding poll requests by executing another, unique poll */
/* request that forces the outstanding ones to return. */ /* request that forces the outstanding ones to return. */
uv__fast_poll_cancel_poll_req(loop, handle); return uv__fast_poll_cancel_poll_req(loop, handle);
} }
} }
@ -409,6 +408,8 @@ static void uv__slow_poll_submit_poll_req(uv_loop_t* loop, uv_poll_t* handle) {
static void uv__slow_poll_process_poll_req(uv_loop_t* loop, uv_poll_t* handle, static void uv__slow_poll_process_poll_req(uv_loop_t* loop, uv_poll_t* handle,
uv_req_t* req) { uv_req_t* req) {
unsigned char mask_events; unsigned char mask_events;
int err;
if (req == &handle->poll_req_1) { if (req == &handle->poll_req_1) {
handle->submitted_events_1 = 0; handle->submitted_events_1 = 0;
mask_events = handle->mask_events_1; mask_events = handle->mask_events_1;
@ -422,9 +423,9 @@ static void uv__slow_poll_process_poll_req(uv_loop_t* loop, uv_poll_t* handle,
if (!REQ_SUCCESS(req)) { if (!REQ_SUCCESS(req)) {
/* Error. */ /* Error. */
if (handle->events != 0) { if (handle->events != 0) {
err = GET_REQ_ERROR(req);
handle->events = 0; /* Stop the watcher */ handle->events = 0; /* Stop the watcher */
uv__set_sys_error(loop, GET_REQ_ERROR(req)); handle->poll_cb(handle, uv_translate_sys_error(err), 0);
handle->poll_cb(handle, -1, 0);
} }
} else { } else {
/* Got some events. */ /* Got some events. */
@ -467,7 +468,7 @@ static int uv__slow_poll_set(uv_loop_t* loop, uv_poll_t* handle, int events) {
} }
static void uv__slow_poll_close(uv_loop_t* loop, uv_poll_t* handle) { static int uv__slow_poll_close(uv_loop_t* loop, uv_poll_t* handle) {
handle->events = 0; handle->events = 0;
uv__handle_closing(handle); uv__handle_closing(handle);
@ -475,6 +476,8 @@ static void uv__slow_poll_close(uv_loop_t* loop, uv_poll_t* handle) {
handle->submitted_events_2 == 0) { handle->submitted_events_2 == 0) {
uv_want_endgame(loop, (uv_handle_t*) handle); uv_want_endgame(loop, (uv_handle_t*) handle);
} }
return 0;
} }
@ -522,8 +525,7 @@ int uv_poll_init_socket(uv_loop_t* loop, uv_poll_t* handle,
SO_PROTOCOL_INFOW, SO_PROTOCOL_INFOW,
(char*) &protocol_info, (char*) &protocol_info,
&len) != 0) { &len) != 0) {
uv__set_sys_error(loop, WSAGetLastError()); return WSAGetLastError();
return -1;
} }
/* Get the peer socket that is needed to enable fast poll. If the returned */ /* Get the peer socket that is needed to enable fast poll. If the returned */
@ -555,12 +557,16 @@ int uv_poll_init_socket(uv_loop_t* loop, uv_poll_t* handle,
int uv_poll_start(uv_poll_t* handle, int events, uv_poll_cb cb) { int uv_poll_start(uv_poll_t* handle, int events, uv_poll_cb cb) {
int err;
if (!(handle->flags & UV_HANDLE_POLL_SLOW)) { if (!(handle->flags & UV_HANDLE_POLL_SLOW)) {
if (uv__fast_poll_set(handle->loop, handle, events) < 0) err = uv__fast_poll_set(handle->loop, handle, events);
return -1;
} else { } else {
if (uv__slow_poll_set(handle->loop, handle, events) < 0) err = uv__slow_poll_set(handle->loop, handle, events);
return -1; }
if (err) {
return uv_translate_sys_error(err);
} }
handle->poll_cb = cb; handle->poll_cb = cb;
@ -570,11 +576,15 @@ int uv_poll_start(uv_poll_t* handle, int events, uv_poll_cb cb) {
int uv_poll_stop(uv_poll_t* handle) { int uv_poll_stop(uv_poll_t* handle) {
int err;
if (!(handle->flags & UV_HANDLE_POLL_SLOW)) { if (!(handle->flags & UV_HANDLE_POLL_SLOW)) {
return uv__fast_poll_set(handle->loop, handle, 0); err = uv__fast_poll_set(handle->loop, handle, 0);
} else { } else {
return uv__slow_poll_set(handle->loop, handle, 0); err = uv__slow_poll_set(handle->loop, handle, 0);
} }
return uv_translate_sys_error(err);
} }
@ -587,11 +597,11 @@ void uv_process_poll_req(uv_loop_t* loop, uv_poll_t* handle, uv_req_t* req) {
} }
void uv_poll_close(uv_loop_t* loop, uv_poll_t* handle) { int uv_poll_close(uv_loop_t* loop, uv_poll_t* handle) {
if (!(handle->flags & UV_HANDLE_POLL_SLOW)) { if (!(handle->flags & UV_HANDLE_POLL_SLOW)) {
uv__fast_poll_close(loop, handle); return uv__fast_poll_close(loop, handle);
} else { } else {
uv__slow_poll_close(loop, handle); return uv__slow_poll_close(loop, handle);
} }
} }

50
deps/uv/src/win/process-stdio.c

@ -94,14 +94,14 @@ void uv_disable_stdio_inheritance(void) {
} }
static uv_err_t uv__create_stdio_pipe_pair(uv_loop_t* loop, static int uv__create_stdio_pipe_pair(uv_loop_t* loop,
uv_pipe_t* server_pipe, HANDLE* child_pipe_ptr, unsigned int flags) { uv_pipe_t* server_pipe, HANDLE* child_pipe_ptr, unsigned int flags) {
char pipe_name[64]; char pipe_name[64];
SECURITY_ATTRIBUTES sa; SECURITY_ATTRIBUTES sa;
DWORD server_access = 0; DWORD server_access = 0;
DWORD client_access = 0; DWORD client_access = 0;
HANDLE child_pipe = INVALID_HANDLE_VALUE; HANDLE child_pipe = INVALID_HANDLE_VALUE;
uv_err_t err; int err;
if (flags & UV_READABLE_PIPE) { if (flags & UV_READABLE_PIPE) {
server_access |= PIPE_ACCESS_OUTBOUND; server_access |= PIPE_ACCESS_OUTBOUND;
@ -118,7 +118,7 @@ static uv_err_t uv__create_stdio_pipe_pair(uv_loop_t* loop,
server_access, server_access,
pipe_name, pipe_name,
sizeof(pipe_name)); sizeof(pipe_name));
if (err.code != UV_OK) if (err)
goto error; goto error;
/* Create child pipe handle. */ /* Create child pipe handle. */
@ -134,7 +134,7 @@ static uv_err_t uv__create_stdio_pipe_pair(uv_loop_t* loop,
server_pipe->ipc ? FILE_FLAG_OVERLAPPED : 0, server_pipe->ipc ? FILE_FLAG_OVERLAPPED : 0,
NULL); NULL);
if (child_pipe == INVALID_HANDLE_VALUE) { if (child_pipe == INVALID_HANDLE_VALUE) {
err = uv__new_sys_error(GetLastError()); err = GetLastError();
goto error; goto error;
} }
@ -158,7 +158,7 @@ static uv_err_t uv__create_stdio_pipe_pair(uv_loop_t* loop,
/* both ends of the pipe created. */ /* both ends of the pipe created. */
if (!ConnectNamedPipe(server_pipe->handle, NULL)) { if (!ConnectNamedPipe(server_pipe->handle, NULL)) {
if (GetLastError() != ERROR_PIPE_CONNECTED) { if (GetLastError() != ERROR_PIPE_CONNECTED) {
err = uv__new_sys_error(GetLastError()); err = GetLastError();
goto error; goto error;
} }
} }
@ -167,7 +167,7 @@ static uv_err_t uv__create_stdio_pipe_pair(uv_loop_t* loop,
server_pipe->flags |= UV_HANDLE_READABLE | UV_HANDLE_WRITABLE; server_pipe->flags |= UV_HANDLE_READABLE | UV_HANDLE_WRITABLE;
*child_pipe_ptr = child_pipe; *child_pipe_ptr = child_pipe;
return uv_ok_; return 0;
error: error:
if (server_pipe->handle != INVALID_HANDLE_VALUE) { if (server_pipe->handle != INVALID_HANDLE_VALUE) {
@ -195,8 +195,7 @@ static int uv__duplicate_handle(uv_loop_t* loop, HANDLE handle, HANDLE* dup) {
handle == NULL || handle == NULL ||
handle == (HANDLE) -2) { handle == (HANDLE) -2) {
*dup = INVALID_HANDLE_VALUE; *dup = INVALID_HANDLE_VALUE;
uv__set_artificial_error(loop, UV_EBADF); return ERROR_INVALID_HANDLE;
return -1;
} }
current_process = GetCurrentProcess(); current_process = GetCurrentProcess();
@ -209,8 +208,7 @@ static int uv__duplicate_handle(uv_loop_t* loop, HANDLE handle, HANDLE* dup) {
TRUE, TRUE,
DUPLICATE_SAME_ACCESS)) { DUPLICATE_SAME_ACCESS)) {
*dup = INVALID_HANDLE_VALUE; *dup = INVALID_HANDLE_VALUE;
uv__set_sys_error(loop, GetLastError()); return GetLastError();
return -1;
} }
return 0; return 0;
@ -222,8 +220,7 @@ static int uv__duplicate_fd(uv_loop_t* loop, int fd, HANDLE* dup) {
if (fd == -1) { if (fd == -1) {
*dup = INVALID_HANDLE_VALUE; *dup = INVALID_HANDLE_VALUE;
uv__set_artificial_error(loop, UV_EBADF); return ERROR_INVALID_HANDLE;
return -1;
} }
handle = (HANDLE) _get_osfhandle(fd); handle = (HANDLE) _get_osfhandle(fd);
@ -231,7 +228,7 @@ static int uv__duplicate_fd(uv_loop_t* loop, int fd, HANDLE* dup) {
} }
uv_err_t uv__create_nul_handle(HANDLE* handle_ptr, int uv__create_nul_handle(HANDLE* handle_ptr,
DWORD access) { DWORD access) {
HANDLE handle; HANDLE handle;
SECURITY_ATTRIBUTES sa; SECURITY_ATTRIBUTES sa;
@ -248,25 +245,25 @@ uv_err_t uv__create_nul_handle(HANDLE* handle_ptr,
0, 0,
NULL); NULL);
if (handle == INVALID_HANDLE_VALUE) { if (handle == INVALID_HANDLE_VALUE) {
return uv__new_sys_error(GetLastError()); return GetLastError();
} }
*handle_ptr = handle; *handle_ptr = handle;
return uv_ok_; return 0;
} }
uv_err_t uv__stdio_create(uv_loop_t* loop, uv_process_options_t* options, int uv__stdio_create(uv_loop_t* loop, uv_process_options_t* options,
BYTE** buffer_ptr) { BYTE** buffer_ptr) {
BYTE* buffer; BYTE* buffer;
int count, i; int count, i;
uv_err_t err; int err;
count = options->stdio_count; count = options->stdio_count;
if (count < 0 || count > 255) { if (count < 0 || count > 255) {
/* Only support FDs 0-255 */ /* Only support FDs 0-255 */
return uv__new_artificial_error(UV_ENOTSUP); return ERROR_NOT_SUPPORTED;
} else if (count < 3) { } else if (count < 3) {
/* There should always be at least 3 stdio handles. */ /* There should always be at least 3 stdio handles. */
count = 3; count = 3;
@ -275,7 +272,7 @@ uv_err_t uv__stdio_create(uv_loop_t* loop, uv_process_options_t* options,
/* Allocate the child stdio buffer */ /* Allocate the child stdio buffer */
buffer = (BYTE*) malloc(CHILD_STDIO_SIZE(count)); buffer = (BYTE*) malloc(CHILD_STDIO_SIZE(count));
if (buffer == NULL) { if (buffer == NULL) {
return uv__new_artificial_error(UV_ENOMEM); return ERROR_OUTOFMEMORY;
} }
/* Prepopulate the buffer with INVALID_HANDLE_VALUE handles so we can */ /* Prepopulate the buffer with INVALID_HANDLE_VALUE handles so we can */
@ -309,7 +306,7 @@ uv_err_t uv__stdio_create(uv_loop_t* loop, uv_process_options_t* options,
err = uv__create_nul_handle(&CHILD_STDIO_HANDLE(buffer, i), err = uv__create_nul_handle(&CHILD_STDIO_HANDLE(buffer, i),
access); access);
if (err.code != UV_OK) if (err)
goto error; goto error;
CHILD_STDIO_CRT_FLAGS(buffer, i) = FOPEN | FDEV; CHILD_STDIO_CRT_FLAGS(buffer, i) = FOPEN | FDEV;
@ -333,7 +330,7 @@ uv_err_t uv__stdio_create(uv_loop_t* loop, uv_process_options_t* options,
parent_pipe, parent_pipe,
&child_pipe, &child_pipe,
fdopt.flags); fdopt.flags);
if (err.code != UV_OK) if (err)
goto error; goto error;
CHILD_STDIO_HANDLE(buffer, i) = child_pipe; CHILD_STDIO_HANDLE(buffer, i) = child_pipe;
@ -346,10 +343,11 @@ uv_err_t uv__stdio_create(uv_loop_t* loop, uv_process_options_t* options,
HANDLE child_handle; HANDLE child_handle;
/* Make an inheritable duplicate of the handle. */ /* Make an inheritable duplicate of the handle. */
if (uv__duplicate_fd(loop, fdopt.data.fd, &child_handle) < 0) { err = uv__duplicate_fd(loop, fdopt.data.fd, &child_handle);
if (err) {
/* If fdopt.data.fd is not valid and fd fd <= 2, then ignore the */ /* If fdopt.data.fd is not valid and fd fd <= 2, then ignore the */
/* error. */ /* error. */
if (fdopt.data.fd <= 2 && loop->last_err.code == UV_EBADF) { if (fdopt.data.fd <= 2 && err == ERROR_INVALID_HANDLE) {
CHILD_STDIO_CRT_FLAGS(buffer, i) = 0; CHILD_STDIO_CRT_FLAGS(buffer, i) = 0;
CHILD_STDIO_HANDLE(buffer, i) = INVALID_HANDLE_VALUE; CHILD_STDIO_HANDLE(buffer, i) = INVALID_HANDLE_VALUE;
break; break;
@ -373,7 +371,7 @@ uv_err_t uv__stdio_create(uv_loop_t* loop, uv_process_options_t* options,
case FILE_TYPE_UNKNOWN: case FILE_TYPE_UNKNOWN:
if (GetLastError() != 0) { if (GetLastError() != 0) {
uv__set_sys_error(loop, GetLastError()); err = GetLastError();
CloseHandle(child_handle); CloseHandle(child_handle);
goto error; goto error;
} }
@ -411,7 +409,7 @@ uv_err_t uv__stdio_create(uv_loop_t* loop, uv_process_options_t* options,
stream_handle == INVALID_HANDLE_VALUE) { stream_handle == INVALID_HANDLE_VALUE) {
/* The handle is already closed, or not yet created, or the */ /* The handle is already closed, or not yet created, or the */
/* stream type is not supported. */ /* stream type is not supported. */
uv__set_artificial_error(loop, UV_ENOTSUP); err = ERROR_NOT_SUPPORTED;
goto error; goto error;
} }
@ -433,7 +431,7 @@ uv_err_t uv__stdio_create(uv_loop_t* loop, uv_process_options_t* options,
} }
*buffer_ptr = buffer; *buffer_ptr = buffer;
return uv_ok_; return 0;
error: error:
uv__stdio_destroy(buffer); uv__stdio_destroy(buffer);

136
deps/uv/src/win/process.c

@ -90,7 +90,7 @@ static void uv__init_global_job_handle(void) {
} }
static uv_err_t uv_utf8_to_utf16_alloc(const char* s, WCHAR** ws_ptr) { static int uv_utf8_to_utf16_alloc(const char* s, WCHAR** ws_ptr) {
int ws_len, r; int ws_len, r;
WCHAR* ws; WCHAR* ws;
@ -101,12 +101,12 @@ static uv_err_t uv_utf8_to_utf16_alloc(const char* s, WCHAR** ws_ptr) {
NULL, NULL,
0); 0);
if (ws_len <= 0) { if (ws_len <= 0) {
return uv__new_sys_error(GetLastError()); return GetLastError();
} }
ws = (WCHAR*) malloc(ws_len * sizeof(WCHAR)); ws = (WCHAR*) malloc(ws_len * sizeof(WCHAR));
if (ws == NULL) { if (ws == NULL) {
return uv__new_artificial_error(UV_ENOMEM); return ERROR_OUTOFMEMORY;
} }
r = MultiByteToWideChar(CP_UTF8, r = MultiByteToWideChar(CP_UTF8,
@ -118,7 +118,7 @@ static uv_err_t uv_utf8_to_utf16_alloc(const char* s, WCHAR** ws_ptr) {
assert(r == ws_len); assert(r == ws_len);
*ws_ptr = ws; *ws_ptr = ws;
return uv_ok_; return 0;
} }
@ -126,7 +126,7 @@ static void uv_process_init(uv_loop_t* loop, uv_process_t* handle) {
uv__handle_init(loop, (uv_handle_t*) handle, UV_PROCESS); uv__handle_init(loop, (uv_handle_t*) handle, UV_PROCESS);
handle->exit_cb = NULL; handle->exit_cb = NULL;
handle->pid = 0; handle->pid = 0;
handle->spawn_error = uv_ok_; handle->spawn_error = 0;
handle->exit_signal = 0; handle->exit_signal = 0;
handle->wait_handle = INVALID_HANDLE_VALUE; handle->wait_handle = INVALID_HANDLE_VALUE;
handle->process_handle = INVALID_HANDLE_VALUE; handle->process_handle = INVALID_HANDLE_VALUE;
@ -225,7 +225,7 @@ static WCHAR* search_path_join_test(const WCHAR* dir,
attrs = GetFileAttributesW(result); attrs = GetFileAttributesW(result);
if (attrs != INVALID_FILE_ATTRIBUTES && if (attrs != INVALID_FILE_ATTRIBUTES &&
!(attrs & (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_REPARSE_POINT))) { !(attrs & FILE_ATTRIBUTE_DIRECTORY)) {
return result; return result;
} }
@ -498,7 +498,7 @@ WCHAR* quote_cmd_arg(const WCHAR *source, WCHAR *target) {
} }
uv_err_t make_program_args(char** args, int verbatim_arguments, WCHAR** dst_ptr) { int make_program_args(char** args, int verbatim_arguments, WCHAR** dst_ptr) {
char** arg; char** arg;
WCHAR* dst = NULL; WCHAR* dst = NULL;
WCHAR* temp_buffer = NULL; WCHAR* temp_buffer = NULL;
@ -506,7 +506,7 @@ uv_err_t make_program_args(char** args, int verbatim_arguments, WCHAR** dst_ptr)
size_t temp_buffer_len = 0; size_t temp_buffer_len = 0;
WCHAR* pos; WCHAR* pos;
int arg_count = 0; int arg_count = 0;
uv_err_t err = uv_ok_; int err = 0;
/* Count the required size. */ /* Count the required size. */
for (arg = args; *arg; arg++) { for (arg = args; *arg; arg++) {
@ -519,7 +519,7 @@ uv_err_t make_program_args(char** args, int verbatim_arguments, WCHAR** dst_ptr)
NULL, NULL,
0); 0);
if (arg_len == 0) { if (arg_len == 0) {
return uv__new_sys_error(GetLastError()); return GetLastError();
} }
dst_len += arg_len; dst_len += arg_len;
@ -537,14 +537,14 @@ uv_err_t make_program_args(char** args, int verbatim_arguments, WCHAR** dst_ptr)
/* Allocate buffer for the final command line. */ /* Allocate buffer for the final command line. */
dst = (WCHAR*) malloc(dst_len * sizeof(WCHAR)); dst = (WCHAR*) malloc(dst_len * sizeof(WCHAR));
if (dst == NULL) { if (dst == NULL) {
err = uv__new_artificial_error(UV_ENOMEM); err = ERROR_OUTOFMEMORY;
goto error; goto error;
} }
/* Allocate temporary working buffer. */ /* Allocate temporary working buffer. */
temp_buffer = (WCHAR*) malloc(temp_buffer_len * sizeof(WCHAR)); temp_buffer = (WCHAR*) malloc(temp_buffer_len * sizeof(WCHAR));
if (temp_buffer == NULL) { if (temp_buffer == NULL) {
err = uv__new_artificial_error(UV_ENOMEM); err = ERROR_OUTOFMEMORY;
goto error; goto error;
} }
@ -560,6 +560,7 @@ uv_err_t make_program_args(char** args, int verbatim_arguments, WCHAR** dst_ptr)
temp_buffer, temp_buffer,
(int) (dst + dst_len - pos)); (int) (dst + dst_len - pos));
if (arg_len == 0) { if (arg_len == 0) {
err = GetLastError();
goto error; goto error;
} }
@ -578,7 +579,7 @@ uv_err_t make_program_args(char** args, int verbatim_arguments, WCHAR** dst_ptr)
free(temp_buffer); free(temp_buffer);
*dst_ptr = dst; *dst_ptr = dst;
return uv_ok_; return 0;
error: error:
free(dst); free(dst);
@ -617,7 +618,7 @@ static void check_required_vars_contains_var(env_var_t* required, int count,
* these get defined if the input environment block does not contain any * these get defined if the input environment block does not contain any
* values for them. * values for them.
*/ */
uv_err_t make_program_env(char* env_block[], WCHAR** dst_ptr) { int make_program_env(char* env_block[], WCHAR** dst_ptr) {
WCHAR* dst; WCHAR* dst;
WCHAR* ptr; WCHAR* ptr;
char** env; char** env;
@ -645,7 +646,7 @@ uv_err_t make_program_env(char* env_block[], WCHAR** dst_ptr) {
NULL, NULL,
0); 0);
if (len <= 0) { if (len <= 0) {
return uv__new_sys_error(GetLastError()); return GetLastError();
} }
env_len += len; env_len += len;
@ -656,7 +657,7 @@ uv_err_t make_program_env(char* env_block[], WCHAR** dst_ptr) {
env_len += required_vars[i].len; env_len += required_vars[i].len;
var_size = GetEnvironmentVariableW(required_vars[i].wide, NULL, 0); var_size = GetEnvironmentVariableW(required_vars[i].wide, NULL, 0);
if (var_size == 0) { if (var_size == 0) {
return uv__new_sys_error(GetLastError()); return GetLastError();
} }
required_vars[i].value_len = var_size; required_vars[i].value_len = var_size;
env_len += var_size; env_len += var_size;
@ -665,7 +666,7 @@ uv_err_t make_program_env(char* env_block[], WCHAR** dst_ptr) {
dst = malloc(env_len * sizeof(WCHAR)); dst = malloc(env_len * sizeof(WCHAR));
if (!dst) { if (!dst) {
return uv__new_artificial_error(UV_ENOMEM); return ERROR_OUTOFMEMORY;
} }
ptr = dst; ptr = dst;
@ -679,7 +680,7 @@ uv_err_t make_program_env(char* env_block[], WCHAR** dst_ptr) {
(int) (env_len - (ptr - dst))); (int) (env_len - (ptr - dst)));
if (len <= 0) { if (len <= 0) {
free(dst); free(dst);
return uv__new_sys_error(GetLastError()); return GetLastError();
} }
} }
@ -702,7 +703,7 @@ uv_err_t make_program_env(char* env_block[], WCHAR** dst_ptr) {
*ptr = L'\0'; *ptr = L'\0';
*dst_ptr = dst; *dst_ptr = dst;
return uv_ok_; return 0;
} }
@ -727,7 +728,8 @@ static void CALLBACK exit_wait_callback(void* data, BOOLEAN didTimeout) {
/* Called on main thread after a child process has exited. */ /* Called on main thread after a child process has exited. */
void uv_process_proc_exit(uv_loop_t* loop, uv_process_t* handle) { void uv_process_proc_exit(uv_loop_t* loop, uv_process_t* handle) {
DWORD exit_code; int exit_code;
DWORD status;
assert(handle->exit_cb_pending); assert(handle->exit_cb_pending);
handle->exit_cb_pending = 0; handle->exit_cb_pending = 0;
@ -749,17 +751,19 @@ void uv_process_proc_exit(uv_loop_t* loop, uv_process_t* handle) {
/* callback.*/ /* callback.*/
uv__handle_stop(handle); uv__handle_stop(handle);
if (handle->spawn_error.code != UV_OK) { if (handle->spawn_error) {
/* Spawning failed. */ /* Spawning failed. */
exit_code = (DWORD) -1; exit_code = uv_translate_sys_error(handle->spawn_error);
} else if (!GetExitCodeProcess(handle->process_handle, &exit_code)) { } else if (!GetExitCodeProcess(handle->process_handle, &status)) {
/* Unable to to obtain the exit code. This should never happen. */ /* Unable to to obtain the exit code. This should never happen. */
exit_code = (DWORD) -1; exit_code = uv_translate_sys_error(GetLastError());
} else {
/* Make sure the exit code is >= 0. */
exit_code = status & INT_MAX;
} }
/* Fire the exit callback. */ /* Fire the exit callback. */
if (handle->exit_cb) { if (handle->exit_cb) {
loop->last_err = handle->spawn_error;
handle->exit_cb(handle, exit_code, handle->exit_signal); handle->exit_cb(handle, exit_code, handle->exit_signal);
} }
} }
@ -801,7 +805,7 @@ void uv_process_endgame(uv_loop_t* loop, uv_process_t* handle) {
int uv_spawn(uv_loop_t* loop, uv_process_t* process, int uv_spawn(uv_loop_t* loop, uv_process_t* process,
uv_process_options_t options) { uv_process_options_t options) {
int i; int i;
uv_err_t err = uv_ok_; int err = 0;
WCHAR* path = NULL; WCHAR* path = NULL;
BOOL result; BOOL result;
WCHAR* application_path = NULL, *application = NULL, *arguments = NULL, WCHAR* application_path = NULL, *application = NULL, *arguments = NULL,
@ -811,14 +815,12 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process,
DWORD process_flags; DWORD process_flags;
if (options.flags & (UV_PROCESS_SETGID | UV_PROCESS_SETUID)) { if (options.flags & (UV_PROCESS_SETGID | UV_PROCESS_SETUID)) {
uv__set_artificial_error(loop, UV_ENOTSUP); return UV_ENOTSUP;
return -1;
} }
if (options.file == NULL || if (options.file == NULL ||
options.args == NULL) { options.args == NULL) {
uv__set_artificial_error(loop, UV_EINVAL); return UV_EINVAL;
return -1;
} }
assert(options.file != NULL); assert(options.file != NULL);
@ -832,25 +834,25 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process,
process->exit_cb = options.exit_cb; process->exit_cb = options.exit_cb;
err = uv_utf8_to_utf16_alloc(options.file, &application); err = uv_utf8_to_utf16_alloc(options.file, &application);
if (err.code != UV_OK) if (err)
goto done; goto done;
err = make_program_args(options.args, err = make_program_args(options.args,
options.flags & UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS, options.flags & UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS,
&arguments); &arguments);
if (err.code != UV_OK) if (err)
goto done; goto done;
if (options.env) { if (options.env) {
err = make_program_env(options.env, &env); err = make_program_env(options.env, &env);
if (err.code != UV_OK) if (err)
goto done; goto done;
} }
if (options.cwd) { if (options.cwd) {
/* Explicit cwd */ /* Explicit cwd */
err = uv_utf8_to_utf16_alloc(options.cwd, &cwd); err = uv_utf8_to_utf16_alloc(options.cwd, &cwd);
if (err.code != UV_OK) if (err)
goto done; goto done;
} else { } else {
@ -859,19 +861,19 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process,
cwd_len = GetCurrentDirectoryW(0, NULL); cwd_len = GetCurrentDirectoryW(0, NULL);
if (!cwd_len) { if (!cwd_len) {
err = uv__new_sys_error(GetLastError()); err = GetLastError();
goto done; goto done;
} }
cwd = (WCHAR*) malloc(cwd_len * sizeof(WCHAR)); cwd = (WCHAR*) malloc(cwd_len * sizeof(WCHAR));
if (cwd == NULL) { if (cwd == NULL) {
err = uv__new_artificial_error(UV_ENOMEM); err = ERROR_OUTOFMEMORY;
goto done; goto done;
} }
r = GetCurrentDirectoryW(cwd_len, cwd); r = GetCurrentDirectoryW(cwd_len, cwd);
if (r == 0 || r >= cwd_len) { if (r == 0 || r >= cwd_len) {
err = uv__new_sys_error(GetLastError()); err = GetLastError();
goto done; goto done;
} }
} }
@ -882,20 +884,20 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process,
path_len = GetEnvironmentVariableW(L"PATH", NULL, 0); path_len = GetEnvironmentVariableW(L"PATH", NULL, 0);
if (path_len == 0) { if (path_len == 0) {
err = uv__new_sys_error(GetLastError()); err = GetLastError();
goto done; goto done;
} }
path = (WCHAR*) malloc(path_len * sizeof(WCHAR)); path = (WCHAR*) malloc(path_len * sizeof(WCHAR));
if (path == NULL) { if (path == NULL) {
err = uv__new_artificial_error(UV_ENOMEM); err = ERROR_OUTOFMEMORY;
goto done; goto done;
} }
r = GetEnvironmentVariableW(L"PATH", path, path_len); r = GetEnvironmentVariableW(L"PATH", path, path_len);
if (r == 0 || r >= path_len) { if (r == 0 || r >= path_len) {
err = uv__new_sys_error(GetLastError()); err = GetLastError();
goto done; goto done;
} }
} }
@ -905,13 +907,12 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process,
path); path);
if (application_path == NULL) { if (application_path == NULL) {
/* Not found. */ /* Not found. */
err = uv__new_artificial_error(UV_ENOENT); err = ERROR_FILE_NOT_FOUND;
goto done; goto done;
} }
err = uv__stdio_create(loop, &options, &process->child_stdio_buffer); err = uv__stdio_create(loop, &options, &process->child_stdio_buffer);
if (err.code != UV_OK) if (err)
goto done; goto done;
startup.cb = sizeof(startup); startup.cb = sizeof(startup);
@ -1008,7 +1009,7 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process,
} else { } else {
/* CreateProcessW failed. */ /* CreateProcessW failed. */
err = uv__new_sys_error(GetLastError()); err = GetLastError();
} }
done: done:
@ -1032,7 +1033,7 @@ done:
uv__handle_start(process); uv__handle_start(process);
/* If an error happened, queue the exit req. */ /* If an error happened, queue the exit req. */
if (err.code != UV_OK) { if (err) {
process->exit_cb_pending = 1; process->exit_cb_pending = 1;
uv_insert_pending_req(loop, (uv_req_t*) &process->exit_req); uv_insert_pending_req(loop, (uv_req_t*) &process->exit_req);
} }
@ -1041,28 +1042,29 @@ done:
} }
static uv_err_t uv__kill(HANDLE process_handle, int signum) { static int uv__kill(HANDLE process_handle, int signum) {
switch (signum) { switch (signum) {
case SIGTERM: case SIGTERM:
case SIGKILL: case SIGKILL:
case SIGINT: { case SIGINT: {
/* Unconditionally terminate the process. On Windows, killed processes */ /* Unconditionally terminate the process. On Windows, killed processes */
/* normally return 1. */ /* normally return 1. */
DWORD error, status; DWORD status;
int err;
if (TerminateProcess(process_handle, 1)) if (TerminateProcess(process_handle, 1))
return uv_ok_; return 0;
/* If the process already exited before TerminateProcess was called, */ /* If the process already exited before TerminateProcess was called, */
/* TerminateProcess will fail with ERROR_ACESS_DENIED. */ /* TerminateProcess will fail with ERROR_ACESS_DENIED. */
error = GetLastError(); err = GetLastError();
if (error == ERROR_ACCESS_DENIED && if (err == ERROR_ACCESS_DENIED &&
GetExitCodeProcess(process_handle, &status) && GetExitCodeProcess(process_handle, &status) &&
status != STILL_ACTIVE) { status != STILL_ACTIVE) {
return uv__new_artificial_error(UV_ESRCH); return UV_ESRCH;
} }
return uv__new_sys_error(error); return uv_translate_sys_error(err);
} }
case 0: { case 0: {
@ -1070,34 +1072,31 @@ static uv_err_t uv__kill(HANDLE process_handle, int signum) {
DWORD status; DWORD status;
if (!GetExitCodeProcess(process_handle, &status)) if (!GetExitCodeProcess(process_handle, &status))
return uv__new_sys_error(GetLastError()); return uv_translate_sys_error(GetLastError());
if (status != STILL_ACTIVE) if (status != STILL_ACTIVE)
return uv__new_artificial_error(UV_ESRCH); return UV_ESRCH;
return uv_ok_; return 0;
} }
default: default:
/* Unsupported signal. */ /* Unsupported signal. */
return uv__new_artificial_error(UV_ENOSYS); return UV_ENOSYS;
} }
} }
int uv_process_kill(uv_process_t* process, int signum) { int uv_process_kill(uv_process_t* process, int signum) {
uv_err_t err; int err;
if (process->process_handle == INVALID_HANDLE_VALUE) { if (process->process_handle == INVALID_HANDLE_VALUE) {
uv__set_artificial_error(process->loop, UV_EINVAL); return UV_EINVAL;
return -1;
} }
err = uv__kill(process->process_handle, signum); err = uv__kill(process->process_handle, signum);
if (err) {
if (err.code != UV_OK) { return err; /* err is already translated. */
uv__set_error(process->loop, err.code, err.sys_errno_);
return -1;
} }
process->exit_signal = signum; process->exit_signal = signum;
@ -1106,21 +1105,22 @@ int uv_process_kill(uv_process_t* process, int signum) {
} }
uv_err_t uv_kill(int pid, int signum) { int uv_kill(int pid, int signum) {
uv_err_t err; int err;
HANDLE process_handle = OpenProcess(PROCESS_TERMINATE | HANDLE process_handle = OpenProcess(PROCESS_TERMINATE |
PROCESS_QUERY_INFORMATION, FALSE, pid); PROCESS_QUERY_INFORMATION, FALSE, pid);
if (process_handle == NULL) { if (process_handle == NULL) {
if (GetLastError() == ERROR_INVALID_PARAMETER) { err = GetLastError();
return uv__new_artificial_error(UV_ESRCH); if (err == ERROR_INVALID_PARAMETER) {
return UV_ESRCH;
} else { } else {
return uv__new_sys_error(GetLastError()); return uv_translate_sys_error(err);
} }
} }
err = uv__kill(process_handle, signum); err = uv__kill(process_handle, signum);
CloseHandle(process_handle); CloseHandle(process_handle);
return err; return err; /* err is already translated. */
} }

26
deps/uv/src/win/signal.c

@ -124,20 +124,20 @@ static BOOL WINAPI uv__signal_control_handler(DWORD type) {
} }
static uv_err_t uv__signal_register_control_handler() { static int uv__signal_register_control_handler() {
/* When this function is called, the uv__signal_lock must be held. */ /* When this function is called, the uv__signal_lock must be held. */
/* If the console control handler has already been hooked, just add a */ /* If the console control handler has already been hooked, just add a */
/* reference. */ /* reference. */
if (uv__signal_control_handler_refs > 0) if (uv__signal_control_handler_refs > 0)
return uv_ok_; return 0;
if (!SetConsoleCtrlHandler(uv__signal_control_handler, TRUE)) if (!SetConsoleCtrlHandler(uv__signal_control_handler, TRUE))
return uv__new_sys_error(GetLastError()); return GetLastError();
uv__signal_control_handler_refs++; uv__signal_control_handler_refs++;
return uv_ok_; return 0;
} }
@ -162,7 +162,7 @@ static void uv__signal_unregister_control_handler() {
} }
static uv_err_t uv__signal_register(int signum) { static int uv__signal_register(int signum) {
switch (signum) { switch (signum) {
case SIGINT: case SIGINT:
case SIGBREAK: case SIGBREAK:
@ -171,7 +171,7 @@ static uv_err_t uv__signal_register(int signum) {
case SIGWINCH: case SIGWINCH:
/* SIGWINCH is generated in tty.c. No need to register anything. */ /* SIGWINCH is generated in tty.c. No need to register anything. */
return uv_ok_; return 0;
case SIGILL: case SIGILL:
case SIGABRT_COMPAT: case SIGABRT_COMPAT:
@ -180,11 +180,11 @@ static uv_err_t uv__signal_register(int signum) {
case SIGTERM: case SIGTERM:
case SIGABRT: case SIGABRT:
/* Signal is never raised. */ /* Signal is never raised. */
return uv_ok_; return 0;
default: default:
/* Invalid signal. */ /* Invalid signal. */
return uv__new_artificial_error(UV_EINVAL); return ERROR_INVALID_PARAMETER;
} }
} }
@ -259,14 +259,13 @@ int uv_signal_stop(uv_signal_t* handle) {
int uv_signal_start(uv_signal_t* handle, uv_signal_cb signal_cb, int signum) { int uv_signal_start(uv_signal_t* handle, uv_signal_cb signal_cb, int signum) {
uv_err_t err; int err;
/* If the user supplies signum == 0, then return an error already. If the */ /* If the user supplies signum == 0, then return an error already. If the */
/* signum is otherwise invalid then uv__signal_register will find out */ /* signum is otherwise invalid then uv__signal_register will find out */
/* eventually. */ /* eventually. */
if (signum == 0) { if (signum == 0) {
uv__set_artificial_error(handle->loop, UV_EINVAL); return UV_EINVAL;
return -1;
} }
/* Short circuit: if the signal watcher is already watching {signum} don't */ /* Short circuit: if the signal watcher is already watching {signum} don't */
@ -288,11 +287,10 @@ int uv_signal_start(uv_signal_t* handle, uv_signal_cb signal_cb, int signum) {
EnterCriticalSection(&uv__signal_lock); EnterCriticalSection(&uv__signal_lock);
err = uv__signal_register(signum); err = uv__signal_register(signum);
if (err.code != UV_OK) { if (err) {
/* Uh-oh, didn't work. */ /* Uh-oh, didn't work. */
handle->loop->last_err = err;
LeaveCriticalSection(&uv__signal_lock); LeaveCriticalSection(&uv__signal_lock);
return -1; return uv_translate_sys_error(err);
} }
handle->signum = signum; handle->signum = signum;

106
deps/uv/src/win/stream.c

@ -28,148 +28,176 @@
int uv_listen(uv_stream_t* stream, int backlog, uv_connection_cb cb) { int uv_listen(uv_stream_t* stream, int backlog, uv_connection_cb cb) {
int err;
err = ERROR_INVALID_PARAMETER;
switch (stream->type) { switch (stream->type) {
case UV_TCP: case UV_TCP:
return uv_tcp_listen((uv_tcp_t*)stream, backlog, cb); err = uv_tcp_listen((uv_tcp_t*)stream, backlog, cb);
break;
case UV_NAMED_PIPE: case UV_NAMED_PIPE:
return uv_pipe_listen((uv_pipe_t*)stream, backlog, cb); err = uv_pipe_listen((uv_pipe_t*)stream, backlog, cb);
break;
default: default:
assert(0); assert(0);
return -1;
} }
return uv_translate_sys_error(err);
} }
int uv_accept(uv_stream_t* server, uv_stream_t* client) { int uv_accept(uv_stream_t* server, uv_stream_t* client) {
int err;
err = ERROR_INVALID_PARAMETER;
switch (server->type) { switch (server->type) {
case UV_TCP: case UV_TCP:
return uv_tcp_accept((uv_tcp_t*)server, (uv_tcp_t*)client); err = uv_tcp_accept((uv_tcp_t*)server, (uv_tcp_t*)client);
break;
case UV_NAMED_PIPE: case UV_NAMED_PIPE:
return uv_pipe_accept((uv_pipe_t*)server, client); err = uv_pipe_accept((uv_pipe_t*)server, client);
break;
default: default:
assert(0); assert(0);
return -1;
} }
return uv_translate_sys_error(err);
} }
int uv_read_start(uv_stream_t* handle, uv_alloc_cb alloc_cb, int uv_read_start(uv_stream_t* handle, uv_alloc_cb alloc_cb,
uv_read_cb read_cb) { uv_read_cb read_cb) {
int err;
if (handle->flags & UV_HANDLE_READING) { if (handle->flags & UV_HANDLE_READING) {
uv__set_artificial_error(handle->loop, UV_EALREADY); return UV_EALREADY;
return -1;
} }
if (!(handle->flags & UV_HANDLE_READABLE)) { if (!(handle->flags & UV_HANDLE_READABLE)) {
uv__set_artificial_error(handle->loop, UV_ENOTCONN); return UV_ENOTCONN;
return -1;
} }
err = ERROR_INVALID_PARAMETER;
switch (handle->type) { switch (handle->type) {
case UV_TCP: case UV_TCP:
return uv_tcp_read_start((uv_tcp_t*)handle, alloc_cb, read_cb); err = uv_tcp_read_start((uv_tcp_t*)handle, alloc_cb, read_cb);
break;
case UV_NAMED_PIPE: case UV_NAMED_PIPE:
return uv_pipe_read_start((uv_pipe_t*)handle, alloc_cb, read_cb); err = uv_pipe_read_start((uv_pipe_t*)handle, alloc_cb, read_cb);
break;
case UV_TTY: case UV_TTY:
return uv_tty_read_start((uv_tty_t*) handle, alloc_cb, read_cb); err = uv_tty_read_start((uv_tty_t*) handle, alloc_cb, read_cb);
break;
default: default:
assert(0); assert(0);
return -1;
} }
return uv_translate_sys_error(err);
} }
int uv_read2_start(uv_stream_t* handle, uv_alloc_cb alloc_cb, int uv_read2_start(uv_stream_t* handle, uv_alloc_cb alloc_cb,
uv_read2_cb read_cb) { uv_read2_cb read_cb) {
int err;
if (handle->flags & UV_HANDLE_READING) { if (handle->flags & UV_HANDLE_READING) {
uv__set_artificial_error(handle->loop, UV_EALREADY); return UV_EALREADY;
return -1;
} }
if (!(handle->flags & UV_HANDLE_READABLE)) { if (!(handle->flags & UV_HANDLE_READABLE)) {
uv__set_artificial_error(handle->loop, UV_ENOTCONN); return UV_ENOTCONN;
return -1;
} }
err = ERROR_INVALID_PARAMETER;
switch (handle->type) { switch (handle->type) {
case UV_NAMED_PIPE: case UV_NAMED_PIPE:
return uv_pipe_read2_start((uv_pipe_t*)handle, alloc_cb, read_cb); err = uv_pipe_read2_start((uv_pipe_t*)handle, alloc_cb, read_cb);
break;
default: default:
assert(0); assert(0);
return -1;
} }
return uv_translate_sys_error(err);
} }
int uv_read_stop(uv_stream_t* handle) { int uv_read_stop(uv_stream_t* handle) {
int err;
if (!(handle->flags & UV_HANDLE_READING)) if (!(handle->flags & UV_HANDLE_READING))
return 0; return 0;
err = 0;
if (handle->type == UV_TTY) { if (handle->type == UV_TTY) {
return uv_tty_read_stop((uv_tty_t*) handle); err = uv_tty_read_stop((uv_tty_t*) handle);
} else { } else {
handle->flags &= ~UV_HANDLE_READING; handle->flags &= ~UV_HANDLE_READING;
DECREASE_ACTIVE_COUNT(handle->loop, handle); DECREASE_ACTIVE_COUNT(handle->loop, handle);
return 0;
} }
return uv_translate_sys_error(err);
} }
int uv_write(uv_write_t* req, uv_stream_t* handle, uv_buf_t bufs[], int bufcnt, int uv_write(uv_write_t* req, uv_stream_t* handle, uv_buf_t bufs[], int bufcnt,
uv_write_cb cb) { uv_write_cb cb) {
uv_loop_t* loop = handle->loop; uv_loop_t* loop = handle->loop;
int err;
if (!(handle->flags & UV_HANDLE_WRITABLE)) { if (!(handle->flags & UV_HANDLE_WRITABLE)) {
uv__set_artificial_error(loop, UV_EPIPE); return UV_EPIPE;
return -1;
} }
err = ERROR_INVALID_PARAMETER;
switch (handle->type) { switch (handle->type) {
case UV_TCP: case UV_TCP:
return uv_tcp_write(loop, req, (uv_tcp_t*) handle, bufs, bufcnt, cb); err = uv_tcp_write(loop, req, (uv_tcp_t*) handle, bufs, bufcnt, cb);
break;
case UV_NAMED_PIPE: case UV_NAMED_PIPE:
return uv_pipe_write(loop, req, (uv_pipe_t*) handle, bufs, bufcnt, cb); err = uv_pipe_write(loop, req, (uv_pipe_t*) handle, bufs, bufcnt, cb);
break;
case UV_TTY: case UV_TTY:
return uv_tty_write(loop, req, (uv_tty_t*) handle, bufs, bufcnt, cb); err = uv_tty_write(loop, req, (uv_tty_t*) handle, bufs, bufcnt, cb);
break;
default: default:
assert(0); assert(0);
uv__set_sys_error(loop, WSAEINVAL);
return -1;
} }
return uv_translate_sys_error(err);
} }
int uv_write2(uv_write_t* req, uv_stream_t* handle, uv_buf_t bufs[], int bufcnt, int uv_write2(uv_write_t* req, uv_stream_t* handle, uv_buf_t bufs[], int bufcnt,
uv_stream_t* send_handle, uv_write_cb cb) { uv_stream_t* send_handle, uv_write_cb cb) {
uv_loop_t* loop = handle->loop; uv_loop_t* loop = handle->loop;
int err;
if (!(handle->flags & UV_HANDLE_WRITABLE)) { if (!(handle->flags & UV_HANDLE_WRITABLE)) {
uv__set_artificial_error(loop, UV_EPIPE); return UV_EPIPE;
return -1;
} }
err = ERROR_INVALID_PARAMETER;
switch (handle->type) { switch (handle->type) {
case UV_NAMED_PIPE: case UV_NAMED_PIPE:
return uv_pipe_write2(loop, req, (uv_pipe_t*) handle, bufs, bufcnt, send_handle, cb); err = uv_pipe_write2(loop, req, (uv_pipe_t*) handle, bufs, bufcnt, send_handle, cb);
break;
default: default:
assert(0); assert(0);
uv__set_sys_error(loop, WSAEINVAL);
return -1;
} }
return uv_translate_sys_error(err);
} }
int uv_shutdown(uv_shutdown_t* req, uv_stream_t* handle, uv_shutdown_cb cb) { int uv_shutdown(uv_shutdown_t* req, uv_stream_t* handle, uv_shutdown_cb cb) {
uv_loop_t* loop = handle->loop; uv_loop_t* loop = handle->loop;
if (!(handle->flags & UV_HANDLE_WRITABLE)) { if (!(handle->flags & UV_HANDLE_WRITABLE)) {
uv__set_artificial_error(loop, UV_EPIPE); return UV_EPIPE;
return -1;
} }
if (!(handle->flags & UV_HANDLE_WRITABLE)) { if (!(handle->flags & UV_HANDLE_WRITABLE)) {
uv__set_artificial_error(loop, UV_EPIPE); return UV_EPIPE;
return -1;
} }
uv_req_init(loop, (uv_req_t*) req); uv_req_init(loop, (uv_req_t*) req);

305
deps/uv/src/win/tcp.c

@ -50,8 +50,7 @@ static int uv__tcp_nodelay(uv_tcp_t* handle, SOCKET socket, int enable) {
TCP_NODELAY, TCP_NODELAY,
(const char*)&enable, (const char*)&enable,
sizeof enable) == -1) { sizeof enable) == -1) {
uv__set_sys_error(handle->loop, WSAGetLastError()); return WSAGetLastError();
return -1;
} }
return 0; return 0;
} }
@ -63,8 +62,7 @@ static int uv__tcp_keepalive(uv_tcp_t* handle, SOCKET socket, int enable, unsign
SO_KEEPALIVE, SO_KEEPALIVE,
(const char*)&enable, (const char*)&enable,
sizeof enable) == -1) { sizeof enable) == -1) {
uv__set_sys_error(handle->loop, WSAGetLastError()); return WSAGetLastError();
return -1;
} }
if (enable && setsockopt(socket, if (enable && setsockopt(socket,
@ -72,8 +70,7 @@ static int uv__tcp_keepalive(uv_tcp_t* handle, SOCKET socket, int enable, unsign
TCP_KEEPALIVE, TCP_KEEPALIVE,
(const char*)&delay, (const char*)&delay,
sizeof delay) == -1) { sizeof delay) == -1) {
uv__set_sys_error(handle->loop, WSAGetLastError()); return WSAGetLastError();
return -1;
} }
return 0; return 0;
@ -84,13 +81,13 @@ static int uv_tcp_set_socket(uv_loop_t* loop, uv_tcp_t* handle,
SOCKET socket, int family, int imported) { SOCKET socket, int family, int imported) {
DWORD yes = 1; DWORD yes = 1;
int non_ifs_lsp; int non_ifs_lsp;
int err;
assert(handle->socket == INVALID_SOCKET); assert(handle->socket == INVALID_SOCKET);
/* Set the socket to nonblocking mode */ /* Set the socket to nonblocking mode */
if (ioctlsocket(socket, FIONBIO, &yes) == SOCKET_ERROR) { if (ioctlsocket(socket, FIONBIO, &yes) == SOCKET_ERROR) {
uv__set_sys_error(loop, WSAGetLastError()); return WSAGetLastError();
return -1;
} }
/* Associate it with the I/O completion port. */ /* Associate it with the I/O completion port. */
@ -102,8 +99,7 @@ static int uv_tcp_set_socket(uv_loop_t* loop, uv_tcp_t* handle,
if (imported) { if (imported) {
handle->flags |= UV_HANDLE_EMULATE_IOCP; handle->flags |= UV_HANDLE_EMULATE_IOCP;
} else { } else {
uv__set_sys_error(loop, GetLastError()); return GetLastError();
return -1;
} }
} }
@ -120,20 +116,21 @@ static int uv_tcp_set_socket(uv_loop_t* loop, uv_tcp_t* handle,
FILE_SKIP_COMPLETION_PORT_ON_SUCCESS)) { FILE_SKIP_COMPLETION_PORT_ON_SUCCESS)) {
handle->flags |= UV_HANDLE_SYNC_BYPASS_IOCP; handle->flags |= UV_HANDLE_SYNC_BYPASS_IOCP;
} else if (GetLastError() != ERROR_INVALID_FUNCTION) { } else if (GetLastError() != ERROR_INVALID_FUNCTION) {
uv__set_sys_error(loop, GetLastError()); return GetLastError();
return -1;
} }
} }
if ((handle->flags & UV_HANDLE_TCP_NODELAY) && if (handle->flags & UV_HANDLE_TCP_NODELAY) {
uv__tcp_nodelay(handle, socket, 1)) { err = uv__tcp_nodelay(handle, socket, 1);
return -1; if (err)
return err;
} }
/* TODO: Use stored delay. */ /* TODO: Use stored delay. */
if ((handle->flags & UV_HANDLE_TCP_KEEPALIVE) && if (handle->flags & UV_HANDLE_TCP_KEEPALIVE) {
uv__tcp_keepalive(handle, socket, 1, 60)) { err = uv__tcp_keepalive(handle, socket, 1, 60);
return -1; if (err)
return err;
} }
handle->socket = socket; handle->socket = socket;
@ -164,7 +161,7 @@ int uv_tcp_init(uv_loop_t* loop, uv_tcp_t* handle) {
void uv_tcp_endgame(uv_loop_t* loop, uv_tcp_t* handle) { void uv_tcp_endgame(uv_loop_t* loop, uv_tcp_t* handle) {
int status; int err;
unsigned int i; unsigned int i;
uv_tcp_accept_t* req; uv_tcp_accept_t* req;
@ -174,18 +171,16 @@ void uv_tcp_endgame(uv_loop_t* loop, uv_tcp_t* handle) {
UNREGISTER_HANDLE_REQ(loop, handle, handle->shutdown_req); UNREGISTER_HANDLE_REQ(loop, handle, handle->shutdown_req);
err = 0;
if (handle->flags & UV__HANDLE_CLOSING) { if (handle->flags & UV__HANDLE_CLOSING) {
status = -1; err = ERROR_OPERATION_ABORTED;
uv__set_artificial_error(loop, UV_ECANCELED); } else if (shutdown(handle->socket, SD_SEND) == SOCKET_ERROR) {
} else if (shutdown(handle->socket, SD_SEND) != SOCKET_ERROR) { err = WSAGetLastError();
status = 0;
} else {
status = -1;
uv__set_sys_error(loop, WSAGetLastError());
} }
if (handle->shutdown_req->cb) { if (handle->shutdown_req->cb) {
handle->shutdown_req->cb(handle->shutdown_req, status); handle->shutdown_req->cb(handle->shutdown_req,
uv_translate_sys_error(err));
} }
handle->shutdown_req = NULL; handle->shutdown_req = NULL;
@ -249,20 +244,20 @@ static int uv__bind(uv_tcp_t* handle,
if (handle->socket == INVALID_SOCKET) { if (handle->socket == INVALID_SOCKET) {
SOCKET sock = socket(family, SOCK_STREAM, 0); SOCKET sock = socket(family, SOCK_STREAM, 0);
if (sock == INVALID_SOCKET) { if (sock == INVALID_SOCKET) {
uv__set_sys_error(handle->loop, WSAGetLastError()); return WSAGetLastError();
return -1;
} }
/* Make the socket non-inheritable */ /* Make the socket non-inheritable */
if (!SetHandleInformation((HANDLE) sock, HANDLE_FLAG_INHERIT, 0)) { if (!SetHandleInformation((HANDLE) sock, HANDLE_FLAG_INHERIT, 0)) {
uv__set_sys_error(handle->loop, GetLastError()); err = GetLastError();
closesocket(sock); closesocket(sock);
return -1; return err;
} }
if (uv_tcp_set_socket(handle->loop, handle, sock, family, 0) < 0) { err = uv_tcp_set_socket(handle->loop, handle, sock, family, 0);
if (err) {
closesocket(sock); closesocket(sock);
return -1; return err;
} }
} }
@ -275,8 +270,7 @@ static int uv__bind(uv_tcp_t* handle,
handle->bind_error = err; handle->bind_error = err;
handle->flags |= UV_HANDLE_BIND_ERROR; handle->flags |= UV_HANDLE_BIND_ERROR;
} else { } else {
uv__set_sys_error(handle->loop, err); return err;
return -1;
} }
} }
@ -287,18 +281,14 @@ static int uv__bind(uv_tcp_t* handle,
int uv__tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr) { int uv__tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr) {
return uv__bind(handle, return uv_translate_sys_error(
AF_INET, uv__bind(handle, AF_INET, (struct sockaddr*) &addr, sizeof(addr)));
(struct sockaddr*)&addr,
sizeof(struct sockaddr_in));
} }
int uv__tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr) { int uv__tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr) {
return uv__bind(handle, return uv_translate_sys_error(
AF_INET6, uv__bind(handle, AF_INET6, (struct sockaddr*) &addr, sizeof(addr)));
(struct sockaddr*)&addr,
sizeof(struct sockaddr_in6));
} }
@ -499,6 +489,7 @@ int uv_tcp_listen(uv_tcp_t* handle, int backlog, uv_connection_cb cb) {
uv_loop_t* loop = handle->loop; uv_loop_t* loop = handle->loop;
unsigned int i, simultaneous_accepts; unsigned int i, simultaneous_accepts;
uv_tcp_accept_t* req; uv_tcp_accept_t* req;
int err;
assert(backlog > 0); assert(backlog > 0);
@ -507,30 +498,28 @@ int uv_tcp_listen(uv_tcp_t* handle, int backlog, uv_connection_cb cb) {
} }
if (handle->flags & UV_HANDLE_READING) { if (handle->flags & UV_HANDLE_READING) {
uv__set_artificial_error(loop, UV_EISCONN); return WSAEISCONN;
return -1;
} }
if (handle->flags & UV_HANDLE_BIND_ERROR) { if (handle->flags & UV_HANDLE_BIND_ERROR) {
uv__set_sys_error(loop, handle->bind_error); return handle->bind_error;
return -1;
} }
if (!(handle->flags & UV_HANDLE_BOUND) && if (!(handle->flags & UV_HANDLE_BOUND)) {
uv_tcp_bind(handle, uv_addr_ip4_any_) < 0) err = uv_tcp_bind(handle, uv_addr_ip4_any_);
return -1; if (err)
return err;
}
if (!handle->func_acceptex) { if (!handle->func_acceptex) {
if(!uv_get_acceptex_function(handle->socket, &handle->func_acceptex)) { if (!uv_get_acceptex_function(handle->socket, &handle->func_acceptex)) {
uv__set_sys_error(loop, WSAEAFNOSUPPORT); return WSAEAFNOSUPPORT;
return -1;
} }
} }
if (!(handle->flags & UV_HANDLE_SHARED_TCP_SOCKET) && if (!(handle->flags & UV_HANDLE_SHARED_TCP_SOCKET) &&
listen(handle->socket, backlog) == SOCKET_ERROR) { listen(handle->socket, backlog) == SOCKET_ERROR) {
uv__set_sys_error(loop, WSAGetLastError()); return WSAGetLastError();
return -1;
} }
handle->flags |= UV_HANDLE_LISTENING; handle->flags |= UV_HANDLE_LISTENING;
@ -586,20 +575,18 @@ int uv_tcp_listen(uv_tcp_t* handle, int backlog, uv_connection_cb cb) {
int uv_tcp_accept(uv_tcp_t* server, uv_tcp_t* client) { int uv_tcp_accept(uv_tcp_t* server, uv_tcp_t* client) {
uv_loop_t* loop = server->loop; uv_loop_t* loop = server->loop;
int rv = 0; int err = 0;
int family; int family;
uv_tcp_accept_t* req = server->pending_accepts; uv_tcp_accept_t* req = server->pending_accepts;
if (!req) { if (!req) {
/* No valid connections found, so we error out. */ /* No valid connections found, so we error out. */
uv__set_sys_error(loop, WSAEWOULDBLOCK); return WSAEWOULDBLOCK;
return -1;
} }
if (req->accept_socket == INVALID_SOCKET) { if (req->accept_socket == INVALID_SOCKET) {
uv__set_sys_error(loop, WSAENOTCONN); return WSAENOTCONN;
return -1;
} }
if (server->flags & UV_HANDLE_IPV6) { if (server->flags & UV_HANDLE_IPV6) {
@ -608,13 +595,13 @@ int uv_tcp_accept(uv_tcp_t* server, uv_tcp_t* client) {
family = AF_INET; family = AF_INET;
} }
if (uv_tcp_set_socket(client->loop, err = uv_tcp_set_socket(client->loop,
client, client,
req->accept_socket, req->accept_socket,
family, family,
0) < 0) { 0);
if (err) {
closesocket(req->accept_socket); closesocket(req->accept_socket);
rv = -1;
} else { } else {
uv_connection_init((uv_stream_t*) client); uv_connection_init((uv_stream_t*) client);
/* AcceptEx() implicitly binds the accepted socket. */ /* AcceptEx() implicitly binds the accepted socket. */
@ -651,7 +638,7 @@ int uv_tcp_accept(uv_tcp_t* server, uv_tcp_t* client) {
loop->active_tcp_streams++; loop->active_tcp_streams++;
return rv; return err;
} }
@ -689,20 +676,21 @@ int uv__tcp_connect(uv_connect_t* req,
int addrsize = sizeof(struct sockaddr_in); int addrsize = sizeof(struct sockaddr_in);
BOOL success; BOOL success;
DWORD bytes; DWORD bytes;
int err;
if (handle->flags & UV_HANDLE_BIND_ERROR) { if (handle->flags & UV_HANDLE_BIND_ERROR) {
uv__set_sys_error(loop, handle->bind_error); return handle->bind_error;
return -1;
} }
if (!(handle->flags & UV_HANDLE_BOUND) && if (!(handle->flags & UV_HANDLE_BOUND)) {
uv_tcp_bind(handle, uv_addr_ip4_any_) < 0) err = uv_tcp_bind(handle, uv_addr_ip4_any_);
return -1; if (err)
return err;
}
if (!handle->func_connectex) { if (!handle->func_connectex) {
if(!uv_get_connectex_function(handle->socket, &handle->func_connectex)) { if (!uv_get_connectex_function(handle->socket, &handle->func_connectex)) {
uv__set_sys_error(loop, WSAEAFNOSUPPORT); return WSAEAFNOSUPPORT;
return -1;
} }
} }
@ -730,8 +718,7 @@ int uv__tcp_connect(uv_connect_t* req,
handle->reqs_pending++; handle->reqs_pending++;
REGISTER_HANDLE_REQ(loop, handle, req); REGISTER_HANDLE_REQ(loop, handle, req);
} else { } else {
uv__set_sys_error(loop, WSAGetLastError()); return WSAGetLastError();
return -1;
} }
return 0; return 0;
@ -746,20 +733,21 @@ int uv__tcp_connect6(uv_connect_t* req,
int addrsize = sizeof(struct sockaddr_in6); int addrsize = sizeof(struct sockaddr_in6);
BOOL success; BOOL success;
DWORD bytes; DWORD bytes;
int err;
if (handle->flags & UV_HANDLE_BIND_ERROR) { if (handle->flags & UV_HANDLE_BIND_ERROR) {
uv__set_sys_error(loop, handle->bind_error); return handle->bind_error;
return -1;
} }
if (!(handle->flags & UV_HANDLE_BOUND) && if (!(handle->flags & UV_HANDLE_BOUND)) {
uv_tcp_bind6(handle, uv_addr_ip6_any_) < 0) err = uv_tcp_bind6(handle, uv_addr_ip6_any_);
return -1; if (err)
return err;
}
if (!handle->func_connectex) { if (!handle->func_connectex) {
if(!uv_get_connectex_function(handle->socket, &handle->func_connectex)) { if (!uv_get_connectex_function(handle->socket, &handle->func_connectex)) {
uv__set_sys_error(loop, WSAEAFNOSUPPORT); return WSAEAFNOSUPPORT;
return -1;
} }
} }
@ -785,8 +773,7 @@ int uv__tcp_connect6(uv_connect_t* req,
handle->reqs_pending++; handle->reqs_pending++;
REGISTER_HANDLE_REQ(loop, handle, req); REGISTER_HANDLE_REQ(loop, handle, req);
} else { } else {
uv__set_sys_error(loop, WSAGetLastError()); return WSAGetLastError();
return -1;
} }
return 0; return 0;
@ -799,19 +786,16 @@ int uv_tcp_getsockname(uv_tcp_t* handle, struct sockaddr* name,
int result; int result;
if (!(handle->flags & UV_HANDLE_BOUND)) { if (!(handle->flags & UV_HANDLE_BOUND)) {
uv__set_sys_error(loop, WSAEINVAL); return UV_EINVAL;
return -1;
} }
if (handle->flags & UV_HANDLE_BIND_ERROR) { if (handle->flags & UV_HANDLE_BIND_ERROR) {
uv__set_sys_error(loop, handle->bind_error); return uv_translate_sys_error(handle->bind_error);
return -1;
} }
result = getsockname(handle->socket, name, namelen); result = getsockname(handle->socket, name, namelen);
if (result != 0) { if (result != 0) {
uv__set_sys_error(loop, WSAGetLastError()); return uv_translate_sys_error(WSAGetLastError());
return -1;
} }
return 0; return 0;
@ -824,19 +808,16 @@ int uv_tcp_getpeername(uv_tcp_t* handle, struct sockaddr* name,
int result; int result;
if (!(handle->flags & UV_HANDLE_BOUND)) { if (!(handle->flags & UV_HANDLE_BOUND)) {
uv__set_sys_error(loop, WSAEINVAL); return UV_EINVAL;
return -1;
} }
if (handle->flags & UV_HANDLE_BIND_ERROR) { if (handle->flags & UV_HANDLE_BIND_ERROR) {
uv__set_sys_error(loop, handle->bind_error); return uv_translate_sys_error(handle->bind_error);
return -1;
} }
result = getpeername(handle->socket, name, namelen); result = getpeername(handle->socket, name, namelen);
if (result != 0) { if (result != 0) {
uv__set_sys_error(loop, WSAGetLastError()); return uv_translate_sys_error(WSAGetLastError());
return -1;
} }
return 0; return 0;
@ -896,8 +877,7 @@ int uv_tcp_write(uv_loop_t* loop, uv_write_t* req, uv_tcp_t* handle,
} }
} else { } else {
/* Send failed due to an error. */ /* Send failed due to an error. */
uv__set_sys_error(loop, WSAGetLastError()); return WSAGetLastError();
return -1;
} }
return 0; return 0;
@ -928,12 +908,12 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,
/* /*
* Turn WSAECONNABORTED into UV_ECONNRESET to be consistent with Unix. * Turn WSAECONNABORTED into UV_ECONNRESET to be consistent with Unix.
*/ */
uv__set_error(loop, UV_ECONNRESET, err); err = WSAECONNRESET;
} else {
uv__set_sys_error(loop, err);
} }
handle->read_cb((uv_stream_t*)handle, -1, buf); handle->read_cb((uv_stream_t*)handle,
uv_translate_sys_error(err),
buf);
} }
} else { } else {
if (!(handle->flags & UV_HANDLE_ZERO_READ)) { if (!(handle->flags & UV_HANDLE_ZERO_READ)) {
@ -955,10 +935,9 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,
} }
handle->flags &= ~UV_HANDLE_READABLE; handle->flags &= ~UV_HANDLE_READABLE;
uv__set_error(loop, UV_EOF, ERROR_SUCCESS);
buf.base = 0; buf.base = 0;
buf.len = 0; buf.len = 0;
handle->read_cb((uv_stream_t*)handle, -1, handle->read_buffer); handle->read_cb((uv_stream_t*)handle, UV_EOF, handle->read_buffer);
goto done; goto done;
} }
} }
@ -987,15 +966,13 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,
handle->flags &= ~(UV_HANDLE_READING | UV_HANDLE_READABLE); handle->flags &= ~(UV_HANDLE_READING | UV_HANDLE_READABLE);
DECREASE_ACTIVE_COUNT(loop, handle); DECREASE_ACTIVE_COUNT(loop, handle);
uv__set_error(loop, UV_EOF, ERROR_SUCCESS); handle->read_cb((uv_stream_t*)handle, UV_EOF, buf);
handle->read_cb((uv_stream_t*)handle, -1, buf);
break; break;
} }
} else { } else {
err = WSAGetLastError(); err = WSAGetLastError();
if (err == WSAEWOULDBLOCK) { if (err == WSAEWOULDBLOCK) {
/* Read buffer was completely empty, report a 0-byte read. */ /* Read buffer was completely empty, report a 0-byte read. */
uv__set_sys_error(loop, WSAEWOULDBLOCK);
handle->read_cb((uv_stream_t*)handle, 0, buf); handle->read_cb((uv_stream_t*)handle, 0, buf);
} else { } else {
/* Ouch! serious error. */ /* Ouch! serious error. */
@ -1005,12 +982,12 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,
if (err == WSAECONNABORTED) { if (err == WSAECONNABORTED) {
/* Turn WSAECONNABORTED into UV_ECONNRESET to be consistent with */ /* Turn WSAECONNABORTED into UV_ECONNRESET to be consistent with */
/* Unix. */ /* Unix. */
uv__set_error(loop, UV_ECONNRESET, err); err = WSAECONNRESET;
} else {
uv__set_sys_error(loop, err);
} }
handle->read_cb((uv_stream_t*)handle, -1, buf); handle->read_cb((uv_stream_t*)handle,
uv_translate_sys_error(err),
buf);
} }
break; break;
} }
@ -1030,6 +1007,8 @@ done:
void uv_process_tcp_write_req(uv_loop_t* loop, uv_tcp_t* handle, void uv_process_tcp_write_req(uv_loop_t* loop, uv_tcp_t* handle,
uv_write_t* req) { uv_write_t* req) {
int err;
assert(handle->type == UV_TCP); assert(handle->type == UV_TCP);
assert(handle->write_queue_size >= req->queued_bytes); assert(handle->write_queue_size >= req->queued_bytes);
@ -1047,8 +1026,8 @@ void uv_process_tcp_write_req(uv_loop_t* loop, uv_tcp_t* handle,
} }
if (req->cb) { if (req->cb) {
uv__set_sys_error(loop, GET_REQ_SOCK_ERROR(req)); err = GET_REQ_SOCK_ERROR(req);
((uv_write_cb)req->cb)(req, loop->last_err.code == UV_OK ? 0 : -1); req->cb(req, uv_translate_sys_error(err));
} }
handle->write_reqs_pending--; handle->write_reqs_pending--;
@ -1064,6 +1043,7 @@ void uv_process_tcp_write_req(uv_loop_t* loop, uv_tcp_t* handle,
void uv_process_tcp_accept_req(uv_loop_t* loop, uv_tcp_t* handle, void uv_process_tcp_accept_req(uv_loop_t* loop, uv_tcp_t* handle,
uv_req_t* raw_req) { uv_req_t* raw_req) {
uv_tcp_accept_t* req = (uv_tcp_accept_t*) raw_req; uv_tcp_accept_t* req = (uv_tcp_accept_t*) raw_req;
int err;
assert(handle->type == UV_TCP); assert(handle->type == UV_TCP);
@ -1076,8 +1056,9 @@ void uv_process_tcp_accept_req(uv_loop_t* loop, uv_tcp_t* handle,
handle->flags &= ~UV_HANDLE_LISTENING; handle->flags &= ~UV_HANDLE_LISTENING;
DECREASE_ACTIVE_COUNT(loop, handle); DECREASE_ACTIVE_COUNT(loop, handle);
if (handle->connection_cb) { if (handle->connection_cb) {
uv__set_sys_error(loop, GET_REQ_SOCK_ERROR(req)); err = GET_REQ_SOCK_ERROR(req);
handle->connection_cb((uv_stream_t*)handle, -1); handle->connection_cb((uv_stream_t*)handle,
uv_translate_sys_error(err));
} }
} }
} else if (REQ_SUCCESS(req) && } else if (REQ_SUCCESS(req) &&
@ -1110,10 +1091,13 @@ void uv_process_tcp_accept_req(uv_loop_t* loop, uv_tcp_t* handle,
void uv_process_tcp_connect_req(uv_loop_t* loop, uv_tcp_t* handle, void uv_process_tcp_connect_req(uv_loop_t* loop, uv_tcp_t* handle,
uv_connect_t* req) { uv_connect_t* req) {
int err;
assert(handle->type == UV_TCP); assert(handle->type == UV_TCP);
UNREGISTER_HANDLE_REQ(loop, handle, req); UNREGISTER_HANDLE_REQ(loop, handle, req);
err = 0;
if (REQ_SUCCESS(req)) { if (REQ_SUCCESS(req)) {
if (setsockopt(handle->socket, if (setsockopt(handle->socket,
SOL_SOCKET, SOL_SOCKET,
@ -1123,15 +1107,13 @@ void uv_process_tcp_connect_req(uv_loop_t* loop, uv_tcp_t* handle,
uv_connection_init((uv_stream_t*)handle); uv_connection_init((uv_stream_t*)handle);
handle->flags |= UV_HANDLE_READABLE | UV_HANDLE_WRITABLE; handle->flags |= UV_HANDLE_READABLE | UV_HANDLE_WRITABLE;
loop->active_tcp_streams++; loop->active_tcp_streams++;
((uv_connect_cb)req->cb)(req, 0);
} else { } else {
uv__set_sys_error(loop, WSAGetLastError()); err = WSAGetLastError();
((uv_connect_cb)req->cb)(req, -1);
} }
} else { } else {
uv__set_sys_error(loop, GET_REQ_SOCK_ERROR(req)); err = GET_REQ_SOCK_ERROR(req);
((uv_connect_cb)req->cb)(req, -1);
} }
req->cb(req, uv_translate_sys_error(err));
DECREASE_PENDING_REQ_COUNT(handle); DECREASE_PENDING_REQ_COUNT(handle);
} }
@ -1139,6 +1121,8 @@ void uv_process_tcp_connect_req(uv_loop_t* loop, uv_tcp_t* handle,
int uv_tcp_import(uv_tcp_t* tcp, WSAPROTOCOL_INFOW* socket_protocol_info, int uv_tcp_import(uv_tcp_t* tcp, WSAPROTOCOL_INFOW* socket_protocol_info,
int tcp_connection) { int tcp_connection) {
int err;
SOCKET socket = WSASocketW(AF_INET, SOCKET socket = WSASocketW(AF_INET,
SOCK_STREAM, SOCK_STREAM,
IPPROTO_IP, IPPROTO_IP,
@ -1147,23 +1131,23 @@ int uv_tcp_import(uv_tcp_t* tcp, WSAPROTOCOL_INFOW* socket_protocol_info,
WSA_FLAG_OVERLAPPED); WSA_FLAG_OVERLAPPED);
if (socket == INVALID_SOCKET) { if (socket == INVALID_SOCKET) {
uv__set_sys_error(tcp->loop, WSAGetLastError()); return WSAGetLastError();
return -1;
} }
if (!SetHandleInformation((HANDLE) socket, HANDLE_FLAG_INHERIT, 0)) { if (!SetHandleInformation((HANDLE) socket, HANDLE_FLAG_INHERIT, 0)) {
uv__set_sys_error(tcp->loop, GetLastError()); err = GetLastError();
closesocket(socket); closesocket(socket);
return -1; return err;
} }
if (uv_tcp_set_socket(tcp->loop, err = uv_tcp_set_socket(tcp->loop,
tcp, tcp,
socket, socket,
socket_protocol_info->iAddressFamily, socket_protocol_info->iAddressFamily,
1) < 0) { 1);
if (err) {
closesocket(socket); closesocket(socket);
return -1; return err;
} }
if (tcp_connection) { if (tcp_connection) {
@ -1180,9 +1164,12 @@ int uv_tcp_import(uv_tcp_t* tcp, WSAPROTOCOL_INFOW* socket_protocol_info,
int uv_tcp_nodelay(uv_tcp_t* handle, int enable) { int uv_tcp_nodelay(uv_tcp_t* handle, int enable) {
if (handle->socket != INVALID_SOCKET && int err;
uv__tcp_nodelay(handle, handle->socket, enable)) {
return -1; if (handle->socket != INVALID_SOCKET) {
err = uv__tcp_nodelay(handle, handle->socket, enable);
if (err)
return err;
} }
if (enable) { if (enable) {
@ -1196,9 +1183,12 @@ int uv_tcp_nodelay(uv_tcp_t* handle, int enable) {
int uv_tcp_keepalive(uv_tcp_t* handle, int enable, unsigned int delay) { int uv_tcp_keepalive(uv_tcp_t* handle, int enable, unsigned int delay) {
if (handle->socket != INVALID_SOCKET && int err;
uv__tcp_keepalive(handle, handle->socket, enable, delay)) {
return -1; if (handle->socket != INVALID_SOCKET) {
err = uv__tcp_keepalive(handle, handle->socket, enable, delay);
if (err)
return err;
} }
if (enable) { if (enable) {
@ -1225,19 +1215,16 @@ int uv_tcp_duplicate_socket(uv_tcp_t* handle, int pid,
if (!(handle->flags & UV_HANDLE_LISTENING)) { if (!(handle->flags & UV_HANDLE_LISTENING)) {
if (!(handle->flags & UV_HANDLE_BOUND)) { if (!(handle->flags & UV_HANDLE_BOUND)) {
uv__set_artificial_error(handle->loop, UV_EINVAL); return ERROR_INVALID_PARAMETER;
return -1;
} }
if (listen(handle->socket, SOMAXCONN) == SOCKET_ERROR) { if (listen(handle->socket, SOMAXCONN) == SOCKET_ERROR) {
uv__set_sys_error(handle->loop, WSAGetLastError()); return WSAGetLastError();
return -1;
} }
} }
} }
if (WSADuplicateSocketW(handle->socket, pid, protocol_info)) { if (WSADuplicateSocketW(handle->socket, pid, protocol_info)) {
uv__set_sys_error(handle->loop, WSAGetLastError()); return WSAGetLastError();
return -1;
} }
handle->flags |= UV_HANDLE_SHARED_TCP_SOCKET; handle->flags |= UV_HANDLE_SHARED_TCP_SOCKET;
@ -1248,8 +1235,7 @@ int uv_tcp_duplicate_socket(uv_tcp_t* handle, int pid,
int uv_tcp_simultaneous_accepts(uv_tcp_t* handle, int enable) { int uv_tcp_simultaneous_accepts(uv_tcp_t* handle, int enable) {
if (handle->flags & UV_HANDLE_CONNECTION) { if (handle->flags & UV_HANDLE_CONNECTION) {
uv__set_artificial_error(handle->loop, UV_EINVAL); return UV_EINVAL;
return -1;
} }
/* Check if we're already in the desired mode. */ /* Check if we're already in the desired mode. */
@ -1260,8 +1246,7 @@ int uv_tcp_simultaneous_accepts(uv_tcp_t* handle, int enable) {
/* Don't allow switching from single pending accept to many. */ /* Don't allow switching from single pending accept to many. */
if (enable) { if (enable) {
uv__set_artificial_error(handle->loop, UV_ENOTSUP); return UV_ENOTSUP;
return -1;
} }
/* Check if we're in a middle of changing the number of pending accepts. */ /* Check if we're in a middle of changing the number of pending accepts. */
@ -1309,7 +1294,7 @@ static int uv_tcp_try_cancel_io(uv_tcp_t* tcp) {
assert(socket != 0 && socket != INVALID_SOCKET); assert(socket != 0 && socket != INVALID_SOCKET);
if (!CancelIo((HANDLE) socket)) { if (!CancelIo((HANDLE) socket)) {
return -1; return GetLastError();
} }
/* It worked. */ /* It worked. */
@ -1392,6 +1377,7 @@ void uv_tcp_close(uv_loop_t* loop, uv_tcp_t* tcp) {
int uv_tcp_open(uv_tcp_t* handle, uv_os_sock_t sock) { int uv_tcp_open(uv_tcp_t* handle, uv_os_sock_t sock) {
WSAPROTOCOL_INFOW protocol_info; WSAPROTOCOL_INFOW protocol_info;
int opt_len; int opt_len;
int err;
/* Detect the address family of the socket. */ /* Detect the address family of the socket. */
opt_len = (int) sizeof protocol_info; opt_len = (int) sizeof protocol_info;
@ -1400,22 +1386,21 @@ int uv_tcp_open(uv_tcp_t* handle, uv_os_sock_t sock) {
SO_PROTOCOL_INFOW, SO_PROTOCOL_INFOW,
(char*) &protocol_info, (char*) &protocol_info,
&opt_len) == SOCKET_ERROR) { &opt_len) == SOCKET_ERROR) {
uv__set_sys_error(handle->loop, GetLastError()); return uv_translate_sys_error(GetLastError());
return -1;
} }
/* Make the socket non-inheritable */ /* Make the socket non-inheritable */
if (!SetHandleInformation((HANDLE) sock, HANDLE_FLAG_INHERIT, 0)) { if (!SetHandleInformation((HANDLE) sock, HANDLE_FLAG_INHERIT, 0)) {
uv__set_sys_error(handle->loop, GetLastError()); return uv_translate_sys_error(GetLastError());
return -1;
} }
if (uv_tcp_set_socket(handle->loop, err = uv_tcp_set_socket(handle->loop,
handle, handle,
sock, sock,
protocol_info.iAddressFamily, protocol_info.iAddressFamily,
1) < 0) { 1);
return -1; if (err) {
return uv_translate_sys_error(err);
} }
return 0; return 0;

74
deps/uv/src/win/thread.c

@ -119,7 +119,7 @@ void uv_once(uv_once_t* guard, void (*callback)(void)) {
int uv_thread_join(uv_thread_t *tid) { int uv_thread_join(uv_thread_t *tid) {
if (WaitForSingleObject(*tid, INFINITE)) if (WaitForSingleObject(*tid, INFINITE))
return -1; return uv_translate_sys_error(GetLastError());
else { else {
CloseHandle(*tid); CloseHandle(*tid);
*tid = 0; *tid = 0;
@ -148,7 +148,7 @@ int uv_mutex_trylock(uv_mutex_t* mutex) {
if (TryEnterCriticalSection(mutex)) if (TryEnterCriticalSection(mutex))
return 0; return 0;
else else
return -1; return UV_EAGAIN;
} }
@ -225,7 +225,10 @@ void uv_rwlock_wrunlock(uv_rwlock_t* rwlock) {
int uv_sem_init(uv_sem_t* sem, unsigned int value) { int uv_sem_init(uv_sem_t* sem, unsigned int value) {
*sem = CreateSemaphore(NULL, value, INT_MAX, NULL); *sem = CreateSemaphore(NULL, value, INT_MAX, NULL);
return *sem ? 0 : -1; if (*sem == NULL)
return uv_translate_sys_error(GetLastError());
else
return 0;
} }
@ -254,7 +257,7 @@ int uv_sem_trywait(uv_sem_t* sem) {
return 0; return 0;
if (r == WAIT_TIMEOUT) if (r == WAIT_TIMEOUT)
return -1; return UV_EAGAIN;
abort(); abort();
return -1; /* Satisfy the compiler. */ return -1; /* Satisfy the compiler. */
@ -281,7 +284,7 @@ inline static int uv__rwlock_srwlock_tryrdlock(uv_rwlock_t* rwlock) {
if (pTryAcquireSRWLockShared(&rwlock->srwlock_)) if (pTryAcquireSRWLockShared(&rwlock->srwlock_))
return 0; return 0;
else else
return -1; return UV_EBUSY; /* TODO(bnoordhuis) EAGAIN when owned by this thread. */
} }
@ -299,7 +302,7 @@ inline static int uv__rwlock_srwlock_trywrlock(uv_rwlock_t* rwlock) {
if (pTryAcquireSRWLockExclusive(&rwlock->srwlock_)) if (pTryAcquireSRWLockExclusive(&rwlock->srwlock_))
return 0; return 0;
else else
return -1; return UV_EBUSY; /* TODO(bnoordhuis) EAGAIN when owned by this thread. */
} }
@ -309,12 +312,16 @@ inline static void uv__rwlock_srwlock_wrunlock(uv_rwlock_t* rwlock) {
inline static int uv__rwlock_fallback_init(uv_rwlock_t* rwlock) { inline static int uv__rwlock_fallback_init(uv_rwlock_t* rwlock) {
if (uv_mutex_init(&rwlock->fallback_.read_mutex_)) int err;
return -1;
err = uv_mutex_init(&rwlock->fallback_.read_mutex_);
if (err)
return err;
if (uv_mutex_init(&rwlock->fallback_.write_mutex_)) { err = uv_mutex_init(&rwlock->fallback_.write_mutex_);
if (err) {
uv_mutex_destroy(&rwlock->fallback_.read_mutex_); uv_mutex_destroy(&rwlock->fallback_.read_mutex_);
return -1; return err;
} }
rwlock->fallback_.num_readers_ = 0; rwlock->fallback_.num_readers_ = 0;
@ -340,25 +347,23 @@ inline static void uv__rwlock_fallback_rdlock(uv_rwlock_t* rwlock) {
inline static int uv__rwlock_fallback_tryrdlock(uv_rwlock_t* rwlock) { inline static int uv__rwlock_fallback_tryrdlock(uv_rwlock_t* rwlock) {
int ret; int err;
ret = -1; err = uv_mutex_trylock(&rwlock->fallback_.read_mutex_);
if (err)
if (uv_mutex_trylock(&rwlock->fallback_.read_mutex_))
goto out; goto out;
err = 0;
if (rwlock->fallback_.num_readers_ == 0) if (rwlock->fallback_.num_readers_ == 0)
ret = uv_mutex_trylock(&rwlock->fallback_.write_mutex_); err = uv_mutex_trylock(&rwlock->fallback_.write_mutex_);
else
ret = 0;
if (ret == 0) if (err == 0)
rwlock->fallback_.num_readers_++; rwlock->fallback_.num_readers_++;
uv_mutex_unlock(&rwlock->fallback_.read_mutex_); uv_mutex_unlock(&rwlock->fallback_.read_mutex_);
out: out:
return ret; return err;
} }
@ -396,6 +401,8 @@ inline static void uv__rwlock_fallback_wrunlock(uv_rwlock_t* rwlock) {
*/ */
inline static int uv_cond_fallback_init(uv_cond_t* cond) { inline static int uv_cond_fallback_init(uv_cond_t* cond) {
int err;
/* Initialize the count to 0. */ /* Initialize the count to 0. */
cond->fallback.waiters_count = 0; cond->fallback.waiters_count = 0;
@ -406,16 +413,20 @@ inline static int uv_cond_fallback_init(uv_cond_t* cond) {
FALSE, /* auto-reset event */ FALSE, /* auto-reset event */
FALSE, /* non-signaled initially */ FALSE, /* non-signaled initially */
NULL); /* unnamed */ NULL); /* unnamed */
if (!cond->fallback.signal_event) if (!cond->fallback.signal_event) {
err = GetLastError();
goto error2; goto error2;
}
/* Create a manual-reset event. */ /* Create a manual-reset event. */
cond->fallback.broadcast_event = CreateEvent(NULL, /* no security */ cond->fallback.broadcast_event = CreateEvent(NULL, /* no security */
TRUE, /* manual-reset */ TRUE, /* manual-reset */
FALSE, /* non-signaled */ FALSE, /* non-signaled */
NULL); /* unnamed */ NULL); /* unnamed */
if (!cond->fallback.broadcast_event) if (!cond->fallback.broadcast_event) {
err = GetLastError();
goto error; goto error;
}
return 0; return 0;
@ -423,7 +434,7 @@ error:
CloseHandle(cond->fallback.signal_event); CloseHandle(cond->fallback.signal_event);
error2: error2:
DeleteCriticalSection(&cond->fallback.waiters_count_lock); DeleteCriticalSection(&cond->fallback.waiters_count_lock);
return -1; return uv_translate_sys_error(err);
} }
@ -560,7 +571,7 @@ inline int uv_cond_wait_helper(uv_cond_t* cond, uv_mutex_t* mutex,
return 0; return 0;
if (result == WAIT_TIMEOUT) if (result == WAIT_TIMEOUT)
return -1; return UV_ETIMEDOUT;
abort(); abort();
return -1; /* Satisfy the compiler. */ return -1; /* Satisfy the compiler. */
@ -599,7 +610,7 @@ inline static int uv_cond_condvar_timedwait(uv_cond_t* cond,
return 0; return 0;
if (GetLastError() != ERROR_TIMEOUT) if (GetLastError() != ERROR_TIMEOUT)
abort(); abort();
return -1; return UV_ETIMEDOUT;
} }
@ -613,16 +624,21 @@ int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex,
int uv_barrier_init(uv_barrier_t* barrier, unsigned int count) { int uv_barrier_init(uv_barrier_t* barrier, unsigned int count) {
int err;
barrier->n = count; barrier->n = count;
barrier->count = 0; barrier->count = 0;
if (uv_mutex_init(&barrier->mutex)) err = uv_mutex_init(&barrier->mutex);
return -1; if (err)
return err;
if (uv_sem_init(&barrier->turnstile1, 0)) err = uv_sem_init(&barrier->turnstile1, 0);
if (err)
goto error2; goto error2;
if (uv_sem_init(&barrier->turnstile2, 1)) err = uv_sem_init(&barrier->turnstile2, 1);
if (err)
goto error; goto error;
return 0; return 0;
@ -631,7 +647,7 @@ error:
uv_sem_destroy(&barrier->turnstile1); uv_sem_destroy(&barrier->turnstile1);
error2: error2:
uv_mutex_destroy(&barrier->mutex); uv_mutex_destroy(&barrier->mutex);
return -1; return err;
} }

7
deps/uv/src/win/threadpool.c

@ -56,13 +56,12 @@ static DWORD WINAPI uv_work_thread_proc(void* parameter) {
int uv_queue_work(uv_loop_t* loop, uv_work_t* req, uv_work_cb work_cb, int uv_queue_work(uv_loop_t* loop, uv_work_t* req, uv_work_cb work_cb,
uv_after_work_cb after_work_cb) { uv_after_work_cb after_work_cb) {
if (work_cb == NULL) if (work_cb == NULL)
return uv__set_artificial_error(loop, UV_EINVAL); return UV_EINVAL;
uv_work_req_init(loop, req, work_cb, after_work_cb); uv_work_req_init(loop, req, work_cb, after_work_cb);
if (!QueueUserWorkItem(&uv_work_thread_proc, req, WT_EXECUTELONGFUNCTION)) { if (!QueueUserWorkItem(&uv_work_thread_proc, req, WT_EXECUTELONGFUNCTION)) {
uv__set_sys_error(loop, GetLastError()); return uv_translate_sys_error(GetLastError());
return -1;
} }
uv__req_register(loop, req); uv__req_register(loop, req);
@ -71,7 +70,7 @@ int uv_queue_work(uv_loop_t* loop, uv_work_t* req, uv_work_cb work_cb,
int uv_cancel(uv_req_t* req) { int uv_cancel(uv_req_t* req) {
return -1; return UV_ENOSYS;
} }

3
deps/uv/src/win/timer.c

@ -157,8 +157,7 @@ int uv_timer_again(uv_timer_t* handle) {
/* If timer_cb is NULL that means that the timer was never started. */ /* If timer_cb is NULL that means that the timer was never started. */
if (!handle->timer_cb) { if (!handle->timer_cb) {
uv__set_sys_error(loop, ERROR_INVALID_DATA); return UV_EINVAL;
return -1;
} }
if (handle->flags & UV_HANDLE_ACTIVE) { if (handle->flags & UV_HANDLE_ACTIVE) {

75
deps/uv/src/win/tty.c

@ -24,7 +24,7 @@
#include <string.h> #include <string.h>
#if defined(_MSC_VER) && _MSC_VER < 1600 #if defined(_MSC_VER) && _MSC_VER < 1600
# include "uv-private/stdint-msvc2008.h" # include "stdint-msvc2008.h"
#else #else
# include <stdint.h> # include <stdint.h>
#endif #endif
@ -101,15 +101,13 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, uv_file fd, int readable) {
handle = (HANDLE) _get_osfhandle(fd); handle = (HANDLE) _get_osfhandle(fd);
if (handle == INVALID_HANDLE_VALUE) { if (handle == INVALID_HANDLE_VALUE) {
uv__set_artificial_error(loop, UV_EBADF); return UV_EBADF;
return -1;
} }
if (!readable) { if (!readable) {
/* Obtain the screen buffer info with the output handle. */ /* Obtain the screen buffer info with the output handle. */
if (!GetConsoleScreenBufferInfo(handle, &screen_buffer_info)) { if (!GetConsoleScreenBufferInfo(handle, &screen_buffer_info)) {
uv__set_sys_error(loop, GetLastError()); return uv_translate_sys_error(GetLastError());
return -1;
} }
/* Obtain the the tty_output_lock because the virtual window state is */ /* Obtain the the tty_output_lock because the virtual window state is */
@ -170,10 +168,10 @@ int uv_tty_set_mode(uv_tty_t* tty, int mode) {
unsigned char was_reading; unsigned char was_reading;
uv_alloc_cb alloc_cb; uv_alloc_cb alloc_cb;
uv_read_cb read_cb; uv_read_cb read_cb;
int err;
if (!(tty->flags & UV_HANDLE_TTY_READABLE)) { if (!(tty->flags & UV_HANDLE_TTY_READABLE)) {
uv__set_artificial_error(tty->loop, UV_EINVAL); return UV_EINVAL;
return -1;
} }
if (!!mode == !!(tty->flags & UV_HANDLE_TTY_RAW)) { if (!!mode == !!(tty->flags & UV_HANDLE_TTY_RAW)) {
@ -189,8 +187,7 @@ int uv_tty_set_mode(uv_tty_t* tty, int mode) {
} }
if (!SetConsoleMode(tty->handle, flags)) { if (!SetConsoleMode(tty->handle, flags)) {
uv__set_sys_error(tty->loop, GetLastError()); return uv_translate_sys_error(GetLastError());
return -1;
} }
/* If currently reading, stop, and restart reading. */ /* If currently reading, stop, and restart reading. */
@ -199,8 +196,11 @@ int uv_tty_set_mode(uv_tty_t* tty, int mode) {
alloc_cb = tty->alloc_cb; alloc_cb = tty->alloc_cb;
read_cb = tty->read_cb; read_cb = tty->read_cb;
if (was_reading && uv_tty_read_stop(tty) != 0) { if (was_reading) {
return -1; err = uv_tty_read_stop(tty);
if (err) {
return uv_translate_sys_error(err);
}
} }
} else { } else {
was_reading = 0; was_reading = 0;
@ -211,8 +211,11 @@ int uv_tty_set_mode(uv_tty_t* tty, int mode) {
tty->flags |= mode ? UV_HANDLE_TTY_RAW : 0; tty->flags |= mode ? UV_HANDLE_TTY_RAW : 0;
/* If we just stopped reading, restart. */ /* If we just stopped reading, restart. */
if (was_reading && uv_tty_read_start(tty, alloc_cb, read_cb) != 0) { if (was_reading) {
return -1; err = uv_tty_read_start(tty, alloc_cb, read_cb);
if (err) {
return uv_translate_sys_error(err);
}
} }
return 0; return 0;
@ -229,8 +232,7 @@ int uv_tty_get_winsize(uv_tty_t* tty, int* width, int* height) {
CONSOLE_SCREEN_BUFFER_INFO info; CONSOLE_SCREEN_BUFFER_INFO info;
if (!GetConsoleScreenBufferInfo(tty->handle, &info)) { if (!GetConsoleScreenBufferInfo(tty->handle, &info)) {
uv__set_sys_error(tty->loop, GetLastError()); return uv_translate_sys_error(GetLastError());
return -1;
} }
EnterCriticalSection(&uv_tty_output_lock); EnterCriticalSection(&uv_tty_output_lock);
@ -479,18 +481,20 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle,
/* An error occurred while waiting for the event. */ /* An error occurred while waiting for the event. */
if ((handle->flags & UV_HANDLE_READING)) { if ((handle->flags & UV_HANDLE_READING)) {
handle->flags &= ~UV_HANDLE_READING; handle->flags &= ~UV_HANDLE_READING;
uv__set_sys_error(loop, GET_REQ_ERROR(req)); handle->read_cb((uv_stream_t*)handle,
handle->read_cb((uv_stream_t*)handle, -1, uv_null_buf_); uv_translate_sys_error(GET_REQ_ERROR(req)),
uv_null_buf_);
} }
goto out; goto out;
} }
/* Fetch the number of events */ /* Fetch the number of events */
if (!GetNumberOfConsoleInputEvents(handle->handle, &records_left)) { if (!GetNumberOfConsoleInputEvents(handle->handle, &records_left)) {
uv__set_sys_error(loop, GetLastError());
handle->flags &= ~UV_HANDLE_READING; handle->flags &= ~UV_HANDLE_READING;
DECREASE_ACTIVE_COUNT(loop, handle); DECREASE_ACTIVE_COUNT(loop, handle);
handle->read_cb((uv_stream_t*)handle, -1, uv_null_buf_); handle->read_cb((uv_stream_t*)handle,
uv_translate_sys_error(GetLastError()),
uv_null_buf_);
goto out; goto out;
} }
@ -507,10 +511,11 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle,
&handle->last_input_record, &handle->last_input_record,
1, 1,
&records_read)) { &records_read)) {
uv__set_sys_error(loop, GetLastError());
handle->flags &= ~UV_HANDLE_READING; handle->flags &= ~UV_HANDLE_READING;
DECREASE_ACTIVE_COUNT(loop, handle); DECREASE_ACTIVE_COUNT(loop, handle);
handle->read_cb((uv_stream_t*) handle, -1, buf); handle->read_cb((uv_stream_t*) handle,
uv_translate_sys_error(GetLastError()),
buf);
goto out; goto out;
} }
records_left--; records_left--;
@ -626,10 +631,11 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle,
/* If the utf16 character(s) couldn't be converted something must */ /* If the utf16 character(s) couldn't be converted something must */
/* be wrong. */ /* be wrong. */
if (!char_len) { if (!char_len) {
uv__set_sys_error(loop, GetLastError());
handle->flags &= ~UV_HANDLE_READING; handle->flags &= ~UV_HANDLE_READING;
DECREASE_ACTIVE_COUNT(loop, handle); DECREASE_ACTIVE_COUNT(loop, handle);
handle->read_cb((uv_stream_t*) handle, -1, buf); handle->read_cb((uv_stream_t*) handle,
uv_translate_sys_error(GetLastError()),
buf);
goto out; goto out;
} }
@ -739,11 +745,11 @@ void uv_process_tty_read_line_req(uv_loop_t* loop, uv_tty_t* handle,
/* Real error */ /* Real error */
handle->flags &= ~UV_HANDLE_READING; handle->flags &= ~UV_HANDLE_READING;
DECREASE_ACTIVE_COUNT(loop, handle); DECREASE_ACTIVE_COUNT(loop, handle);
uv__set_sys_error(loop, GET_REQ_ERROR(req)); handle->read_cb((uv_stream_t*) handle,
handle->read_cb((uv_stream_t*) handle, -1, buf); uv_translate_sys_error(GET_REQ_ERROR(req)),
buf);
} else { } else {
/* The read was cancelled, or whatever we don't care */ /* The read was cancelled, or whatever we don't care */
uv__set_sys_error(loop, WSAEWOULDBLOCK); /* maps to UV_EAGAIN */
handle->read_cb((uv_stream_t*) handle, 0, buf); handle->read_cb((uv_stream_t*) handle, 0, buf);
} }
@ -751,9 +757,6 @@ void uv_process_tty_read_line_req(uv_loop_t* loop, uv_tty_t* handle,
/* Read successful */ /* Read successful */
/* TODO: read unicode, convert to utf-8 */ /* TODO: read unicode, convert to utf-8 */
DWORD bytes = req->overlapped.InternalHigh; DWORD bytes = req->overlapped.InternalHigh;
if (bytes == 0) {
uv__set_sys_error(loop, WSAEWOULDBLOCK); /* maps to UV_EAGAIN */
}
handle->read_cb((uv_stream_t*) handle, bytes, buf); handle->read_cb((uv_stream_t*) handle, bytes, buf);
} }
@ -788,8 +791,7 @@ int uv_tty_read_start(uv_tty_t* handle, uv_alloc_cb alloc_cb,
uv_loop_t* loop = handle->loop; uv_loop_t* loop = handle->loop;
if (!(handle->flags & UV_HANDLE_TTY_READABLE)) { if (!(handle->flags & UV_HANDLE_TTY_READABLE)) {
uv__set_artificial_error(handle->loop, UV_EINVAL); return ERROR_INVALID_PARAMETER;
return -1;
} }
handle->flags |= UV_HANDLE_READING; handle->flags |= UV_HANDLE_READING;
@ -831,8 +833,7 @@ int uv_tty_read_stop(uv_tty_t* handle) {
DWORD written; DWORD written;
memset(&record, 0, sizeof record); memset(&record, 0, sizeof record);
if (!WriteConsoleInputW(handle->handle, &record, 1, &written)) { if (!WriteConsoleInputW(handle->handle, &record, 1, &written)) {
uv__set_sys_error(loop, GetLastError()); return GetLastError();
return -1;
} }
} }
@ -1763,13 +1764,14 @@ int uv_tty_write(uv_loop_t* loop, uv_write_t* req, uv_tty_t* handle,
void uv_process_tty_write_req(uv_loop_t* loop, uv_tty_t* handle, void uv_process_tty_write_req(uv_loop_t* loop, uv_tty_t* handle,
uv_write_t* req) { uv_write_t* req) {
int err;
handle->write_queue_size -= req->queued_bytes; handle->write_queue_size -= req->queued_bytes;
UNREGISTER_HANDLE_REQ(loop, handle, req); UNREGISTER_HANDLE_REQ(loop, handle, req);
if (req->cb) { if (req->cb) {
uv__set_sys_error(loop, GET_REQ_ERROR(req)); err = GET_REQ_ERROR(req);
((uv_write_cb)req->cb)(req, loop->last_err.code == UV_OK ? 0 : -1); req->cb(req, uv_translate_sys_error(err));
} }
handle->write_reqs_pending--; handle->write_reqs_pending--;
@ -1806,8 +1808,7 @@ void uv_tty_endgame(uv_loop_t* loop, uv_tty_t* handle) {
/* TTY shutdown is really just a no-op */ /* TTY shutdown is really just a no-op */
if (handle->shutdown_req->cb) { if (handle->shutdown_req->cb) {
if (handle->flags & UV__HANDLE_CLOSING) { if (handle->flags & UV__HANDLE_CLOSING) {
uv__set_artificial_error(loop, UV_ECANCELED); handle->shutdown_req->cb(handle->shutdown_req, UV_ECANCELED);
handle->shutdown_req->cb(handle->shutdown_req, -1);
} else { } else {
handle->shutdown_req->cb(handle->shutdown_req, 0); handle->shutdown_req->cb(handle->shutdown_req, 0);
} }

187
deps/uv/src/win/udp.c

@ -42,14 +42,12 @@ int uv_udp_getsockname(uv_udp_t* handle, struct sockaddr* name,
int result; int result;
if (!(handle->flags & UV_HANDLE_BOUND)) { if (!(handle->flags & UV_HANDLE_BOUND)) {
uv__set_sys_error(loop, WSAEINVAL); return UV_EINVAL;
return -1;
} }
result = getsockname(handle->socket, name, namelen); result = getsockname(handle->socket, name, namelen);
if (result != 0) { if (result != 0) {
uv__set_sys_error(loop, WSAGetLastError()); return uv_translate_sys_error(WSAGetLastError());
return -1;
} }
return 0; return 0;
@ -70,20 +68,17 @@ static int uv_udp_set_socket(uv_loop_t* loop, uv_udp_t* handle, SOCKET socket,
SO_REUSEADDR, SO_REUSEADDR,
(char*) &yes, (char*) &yes,
sizeof yes) == SOCKET_ERROR) { sizeof yes) == SOCKET_ERROR) {
uv__set_sys_error(loop, WSAGetLastError()); return WSAGetLastError();
return -1;
} }
/* Set the socket to nonblocking mode */ /* Set the socket to nonblocking mode */
if (ioctlsocket(socket, FIONBIO, &yes) == SOCKET_ERROR) { if (ioctlsocket(socket, FIONBIO, &yes) == SOCKET_ERROR) {
uv__set_sys_error(loop, WSAGetLastError()); return WSAGetLastError();
return -1;
} }
/* Make the socket non-inheritable */ /* Make the socket non-inheritable */
if (!SetHandleInformation((HANDLE)socket, HANDLE_FLAG_INHERIT, 0)) { if (!SetHandleInformation((HANDLE)socket, HANDLE_FLAG_INHERIT, 0)) {
uv__set_sys_error(loop, GetLastError()); return GetLastError();
return -1;
} }
/* Associate it with the I/O completion port. */ /* Associate it with the I/O completion port. */
@ -92,8 +87,7 @@ static int uv_udp_set_socket(uv_loop_t* loop, uv_udp_t* handle, SOCKET socket,
loop->iocp, loop->iocp,
(ULONG_PTR)socket, (ULONG_PTR)socket,
0) == NULL) { 0) == NULL) {
uv__set_sys_error(loop, GetLastError()); return GetLastError();
return -1;
} }
if (pSetFileCompletionNotificationModes) { if (pSetFileCompletionNotificationModes) {
@ -108,8 +102,7 @@ static int uv_udp_set_socket(uv_loop_t* loop, uv_udp_t* handle, SOCKET socket,
SO_PROTOCOL_INFOW, SO_PROTOCOL_INFOW,
(char*) &info, (char*) &info,
&opt_len) == SOCKET_ERROR) { &opt_len) == SOCKET_ERROR) {
uv__set_sys_error(loop, GetLastError()); return GetLastError();
return -1;
} }
if (info.ProtocolChain.ChainLen == 1) { if (info.ProtocolChain.ChainLen == 1) {
@ -120,8 +113,7 @@ static int uv_udp_set_socket(uv_loop_t* loop, uv_udp_t* handle, SOCKET socket,
handle->func_wsarecv = uv_wsarecv_workaround; handle->func_wsarecv = uv_wsarecv_workaround;
handle->func_wsarecvfrom = uv_wsarecvfrom_workaround; handle->func_wsarecvfrom = uv_wsarecvfrom_workaround;
} else if (GetLastError() != ERROR_INVALID_FUNCTION) { } else if (GetLastError() != ERROR_INVALID_FUNCTION) {
uv__set_sys_error(loop, GetLastError()); return GetLastError();
return -1;
} }
} }
} }
@ -182,24 +174,24 @@ static int uv__bind(uv_udp_t* handle,
int addrsize, int addrsize,
unsigned int flags) { unsigned int flags) {
int r; int r;
int err;
DWORD no = 0; DWORD no = 0;
if ((flags & UV_UDP_IPV6ONLY) && family != AF_INET6) { if ((flags & UV_UDP_IPV6ONLY) && family != AF_INET6) {
/* UV_UDP_IPV6ONLY is supported only for IPV6 sockets */ /* UV_UDP_IPV6ONLY is supported only for IPV6 sockets */
uv__set_artificial_error(handle->loop, UV_EINVAL); return ERROR_INVALID_PARAMETER;
return -1;
} }
if (handle->socket == INVALID_SOCKET) { if (handle->socket == INVALID_SOCKET) {
SOCKET sock = socket(family, SOCK_DGRAM, 0); SOCKET sock = socket(family, SOCK_DGRAM, 0);
if (sock == INVALID_SOCKET) { if (sock == INVALID_SOCKET) {
uv__set_sys_error(handle->loop, WSAGetLastError()); return WSAGetLastError();
return -1;
} }
if (uv_udp_set_socket(handle->loop, handle, sock, family) < 0) { err = uv_udp_set_socket(handle->loop, handle, sock, family);
if (err) {
closesocket(sock); closesocket(sock);
return -1; return err;
} }
if (family == AF_INET6) if (family == AF_INET6)
@ -222,8 +214,7 @@ static int uv__bind(uv_udp_t* handle,
r = bind(handle->socket, addr, addrsize); r = bind(handle->socket, addr, addrsize);
if (r == SOCKET_ERROR) { if (r == SOCKET_ERROR) {
uv__set_sys_error(handle->loop, WSAGetLastError()); return WSAGetLastError();
return -1;
} }
handle->flags |= UV_HANDLE_BOUND; handle->flags |= UV_HANDLE_BOUND;
@ -232,23 +223,33 @@ static int uv__bind(uv_udp_t* handle,
} }
int uv__udp_bind(uv_udp_t* handle, struct sockaddr_in addr, int uv__udp_bind(uv_udp_t* handle,
unsigned int flags) { struct sockaddr_in addr,
return uv__bind(handle, unsigned int flags) {
AF_INET, int err;
(struct sockaddr*) &addr,
sizeof(struct sockaddr_in), err = uv__bind(handle,
flags); AF_INET,
(struct sockaddr*) &addr,
sizeof(addr),
flags);
return uv_translate_sys_error(err);
} }
int uv__udp_bind6(uv_udp_t* handle, struct sockaddr_in6 addr, int uv__udp_bind6(uv_udp_t* handle,
unsigned int flags) { struct sockaddr_in6 addr,
return uv__bind(handle, unsigned int flags) {
AF_INET6, int err;
(struct sockaddr*) &addr,
sizeof(struct sockaddr_in6), err = uv__bind(handle,
flags); AF_INET6,
(struct sockaddr*) &addr,
sizeof(addr),
flags);
return uv_translate_sys_error(err);
} }
@ -344,15 +345,16 @@ static void uv_udp_queue_recv(uv_loop_t* loop, uv_udp_t* handle) {
int uv__udp_recv_start(uv_udp_t* handle, uv_alloc_cb alloc_cb, int uv__udp_recv_start(uv_udp_t* handle, uv_alloc_cb alloc_cb,
uv_udp_recv_cb recv_cb) { uv_udp_recv_cb recv_cb) {
uv_loop_t* loop = handle->loop; uv_loop_t* loop = handle->loop;
int err;
if (handle->flags & UV_HANDLE_READING) { if (handle->flags & UV_HANDLE_READING) {
uv__set_sys_error(loop, WSAEALREADY); return WSAEALREADY;
return -1;
} }
if (!(handle->flags & UV_HANDLE_BOUND) && if (!(handle->flags & UV_HANDLE_BOUND)) {
uv_udp_bind(handle, uv_addr_ip4_any_, 0) < 0) { err = uv_udp_bind(handle, uv_addr_ip4_any_, 0);
return -1; if (err)
return err;
} }
handle->flags |= UV_HANDLE_READING; handle->flags |= UV_HANDLE_READING;
@ -416,8 +418,7 @@ static int uv__send(uv_udp_send_t* req, uv_udp_t* handle, uv_buf_t bufs[],
REGISTER_HANDLE_REQ(loop, handle, req); REGISTER_HANDLE_REQ(loop, handle, req);
} else { } else {
/* Send failed due to an error. */ /* Send failed due to an error. */
uv__set_sys_error(loop, WSAGetLastError()); return WSAGetLastError();
return -1;
} }
return 0; return 0;
@ -426,10 +427,12 @@ static int uv__send(uv_udp_send_t* req, uv_udp_t* handle, uv_buf_t bufs[],
int uv__udp_send(uv_udp_send_t* req, uv_udp_t* handle, uv_buf_t bufs[], int uv__udp_send(uv_udp_send_t* req, uv_udp_t* handle, uv_buf_t bufs[],
int bufcnt, struct sockaddr_in addr, uv_udp_send_cb cb) { int bufcnt, struct sockaddr_in addr, uv_udp_send_cb cb) {
int err;
if (!(handle->flags & UV_HANDLE_BOUND) && if (!(handle->flags & UV_HANDLE_BOUND)) {
uv_udp_bind(handle, uv_addr_ip4_any_, 0) < 0) { err = uv_udp_bind(handle, uv_addr_ip4_any_, 0);
return -1; if (err)
return err;
} }
return uv__send(req, return uv__send(req,
@ -444,10 +447,12 @@ int uv__udp_send(uv_udp_send_t* req, uv_udp_t* handle, uv_buf_t bufs[],
int uv__udp_send6(uv_udp_send_t* req, uv_udp_t* handle, uv_buf_t bufs[], int uv__udp_send6(uv_udp_send_t* req, uv_udp_t* handle, uv_buf_t bufs[],
int bufcnt, struct sockaddr_in6 addr, uv_udp_send_cb cb) { int bufcnt, struct sockaddr_in6 addr, uv_udp_send_cb cb) {
int err;
if (!(handle->flags & UV_HANDLE_BOUND) && if (!(handle->flags & UV_HANDLE_BOUND)) {
uv_udp_bind6(handle, uv_addr_ip6_any_, 0) < 0) { err = uv_udp_bind6(handle, uv_addr_ip6_any_, 0);
return -1; if (err)
return err;
} }
return uv__send(req, return uv__send(req,
@ -486,11 +491,10 @@ void uv_process_udp_recv_req(uv_loop_t* loop, uv_udp_t* handle,
/* A real error occurred. Report the error to the user only if we're */ /* A real error occurred. Report the error to the user only if we're */
/* currently reading. */ /* currently reading. */
if (handle->flags & UV_HANDLE_READING) { if (handle->flags & UV_HANDLE_READING) {
uv__set_sys_error(loop, err);
uv_udp_recv_stop(handle); uv_udp_recv_stop(handle);
buf = (handle->flags & UV_HANDLE_ZERO_READ) ? buf = (handle->flags & UV_HANDLE_ZERO_READ) ?
uv_buf_init(NULL, 0) : handle->recv_buffer; uv_buf_init(NULL, 0) : handle->recv_buffer;
handle->recv_cb(handle, -1, buf, NULL, 0); handle->recv_cb(handle, uv_translate_sys_error(err), buf, NULL, 0);
} }
goto done; goto done;
} }
@ -542,14 +546,12 @@ void uv_process_udp_recv_req(uv_loop_t* loop, uv_udp_t* handle,
UV_UDP_PARTIAL); UV_UDP_PARTIAL);
} if (err == WSAEWOULDBLOCK) { } if (err == WSAEWOULDBLOCK) {
/* Kernel buffer empty */ /* Kernel buffer empty */
uv__set_sys_error(loop, WSAEWOULDBLOCK);
handle->recv_cb(handle, 0, buf, NULL, 0); handle->recv_cb(handle, 0, buf, NULL, 0);
} else if (err != WSAECONNRESET && err != WSAENETRESET) { } else if (err != WSAECONNRESET && err != WSAENETRESET) {
/* Serious error. WSAECONNRESET/WSANETRESET is ignored because this */ /* Serious error. WSAECONNRESET/WSANETRESET is ignored because this */
/* just indicates that a previous sendto operation failed. */ /* just indicates that a previous sendto operation failed. */
uv_udp_recv_stop(handle); uv_udp_recv_stop(handle);
uv__set_sys_error(loop, err); handle->recv_cb(handle, uv_translate_sys_error(err), buf, NULL, 0);
handle->recv_cb(handle, -1, buf, NULL, 0);
} }
} }
} }
@ -567,17 +569,18 @@ done:
void uv_process_udp_send_req(uv_loop_t* loop, uv_udp_t* handle, void uv_process_udp_send_req(uv_loop_t* loop, uv_udp_t* handle,
uv_udp_send_t* req) { uv_udp_send_t* req) {
int err;
assert(handle->type == UV_UDP); assert(handle->type == UV_UDP);
UNREGISTER_HANDLE_REQ(loop, handle, req); UNREGISTER_HANDLE_REQ(loop, handle, req);
if (req->cb) { if (req->cb) {
if (REQ_SUCCESS(req)) { err = 0;
req->cb(req, 0); if (!REQ_SUCCESS(req)) {
} else { err = GET_REQ_SOCK_ERROR(req);
uv__set_sys_error(loop, GET_REQ_SOCK_ERROR(req));
req->cb(req, -1);
} }
req->cb(req, uv_translate_sys_error(err));
} }
DECREASE_PENDING_REQ_COUNT(handle); DECREASE_PENDING_REQ_COUNT(handle);
@ -586,18 +589,19 @@ void uv_process_udp_send_req(uv_loop_t* loop, uv_udp_t* handle,
int uv_udp_set_membership(uv_udp_t* handle, const char* multicast_addr, int uv_udp_set_membership(uv_udp_t* handle, const char* multicast_addr,
const char* interface_addr, uv_membership membership) { const char* interface_addr, uv_membership membership) {
int err;
int optname; int optname;
struct ip_mreq mreq; struct ip_mreq mreq;
/* If the socket is unbound, bind to inaddr_any. */ /* If the socket is unbound, bind to inaddr_any. */
if (!(handle->flags & UV_HANDLE_BOUND) && if (!(handle->flags & UV_HANDLE_BOUND)) {
uv_udp_bind(handle, uv_addr_ip4_any_, 0) < 0) { err = uv__udp_bind(handle, uv_addr_ip4_any_, 0);
return -1; if (err)
return uv_translate_sys_error(err);
} }
if (handle->flags & UV_HANDLE_IPV6) { if (handle->flags & UV_HANDLE_IPV6) {
uv__set_artificial_error(handle->loop, UV_ENOSYS); return UV_ENOSYS;
return -1;
} }
memset(&mreq, 0, sizeof mreq); memset(&mreq, 0, sizeof mreq);
@ -618,7 +622,7 @@ int uv_udp_set_membership(uv_udp_t* handle, const char* multicast_addr,
optname = IP_DROP_MEMBERSHIP; optname = IP_DROP_MEMBERSHIP;
break; break;
default: default:
return uv__set_artificial_error(handle->loop, UV_EINVAL); return UV_EINVAL;
} }
if (setsockopt(handle->socket, if (setsockopt(handle->socket,
@ -626,8 +630,7 @@ int uv_udp_set_membership(uv_udp_t* handle, const char* multicast_addr,
optname, optname,
(char*) &mreq, (char*) &mreq,
sizeof mreq) == SOCKET_ERROR) { sizeof mreq) == SOCKET_ERROR) {
uv__set_sys_error(handle->loop, WSAGetLastError()); return uv_translate_sys_error(WSAGetLastError());
return -1;
} }
return 0; return 0;
@ -636,11 +639,13 @@ int uv_udp_set_membership(uv_udp_t* handle, const char* multicast_addr,
int uv_udp_set_broadcast(uv_udp_t* handle, int value) { int uv_udp_set_broadcast(uv_udp_t* handle, int value) {
BOOL optval = (BOOL) value; BOOL optval = (BOOL) value;
int err;
/* If the socket is unbound, bind to inaddr_any. */ /* If the socket is unbound, bind to inaddr_any. */
if (!(handle->flags & UV_HANDLE_BOUND) && if (!(handle->flags & UV_HANDLE_BOUND)) {
uv_udp_bind(handle, uv_addr_ip4_any_, 0) < 0) { err = uv__udp_bind(handle, uv_addr_ip4_any_, 0);
return -1; if (err)
return uv_translate_sys_error(err);
} }
if (setsockopt(handle->socket, if (setsockopt(handle->socket,
@ -648,9 +653,9 @@ int uv_udp_set_broadcast(uv_udp_t* handle, int value) {
SO_BROADCAST, SO_BROADCAST,
(char*) &optval, (char*) &optval,
sizeof optval)) { sizeof optval)) {
uv__set_sys_error(handle->loop, WSAGetLastError()); return uv_translate_sys_error(WSAGetLastError());
return -1;
} }
return 0; return 0;
} }
@ -658,6 +663,7 @@ int uv_udp_set_broadcast(uv_udp_t* handle, int value) {
int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock) { int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock) {
WSAPROTOCOL_INFOW protocol_info; WSAPROTOCOL_INFOW protocol_info;
int opt_len; int opt_len;
int err;
/* Detect the address family of the socket. */ /* Detect the address family of the socket. */
opt_len = (int) sizeof protocol_info; opt_len = (int) sizeof protocol_info;
@ -666,34 +672,31 @@ int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock) {
SO_PROTOCOL_INFOW, SO_PROTOCOL_INFOW,
(char*) &protocol_info, (char*) &protocol_info,
&opt_len) == SOCKET_ERROR) { &opt_len) == SOCKET_ERROR) {
uv__set_sys_error(handle->loop, GetLastError()); return uv_translate_sys_error(GetLastError());
return -1;
}
if (uv_udp_set_socket(handle->loop,
handle,
sock,
protocol_info.iAddressFamily) < 0) {
return -1;
} }
return 0; err = uv_udp_set_socket(handle->loop,
handle,
sock,
protocol_info.iAddressFamily);
return uv_translate_sys_error(err);
} }
#define SOCKOPT_SETTER(name, option4, option6, validate) \ #define SOCKOPT_SETTER(name, option4, option6, validate) \
int uv_udp_set_##name(uv_udp_t* handle, int value) { \ int uv_udp_set_##name(uv_udp_t* handle, int value) { \
DWORD optval = (DWORD) value; \ DWORD optval = (DWORD) value; \
int err; \
\ \
if (!(validate(value))) { \ if (!(validate(value))) { \
uv__set_artificial_error(handle->loop, UV_EINVAL); \ return UV_EINVAL; \
return -1; \
} \ } \
\ \
/* If the socket is unbound, bind to inaddr_any. */ \ /* If the socket is unbound, bind to inaddr_any. */ \
if (!(handle->flags & UV_HANDLE_BOUND) && \ if (!(handle->flags & UV_HANDLE_BOUND)) { \
uv_udp_bind(handle, uv_addr_ip4_any_, 0) < 0) { \ err = uv__udp_bind(handle, uv_addr_ip4_any_, 0); \
return -1; \ if (err) \
return uv_translate_sys_error(err); \
} \ } \
\ \
if (!(handle->flags & UV_HANDLE_IPV6)) { \ if (!(handle->flags & UV_HANDLE_IPV6)) { \
@ -703,8 +706,7 @@ int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock) {
option4, \ option4, \
(char*) &optval, \ (char*) &optval, \
sizeof optval)) { \ sizeof optval)) { \
uv__set_sys_error(handle->loop, WSAGetLastError()); \ return uv_translate_sys_error(WSAGetLastError()); \
return -1; \
} \ } \
} else { \ } else { \
/* Set IPv6 socket option */ \ /* Set IPv6 socket option */ \
@ -713,8 +715,7 @@ int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock) {
option6, \ option6, \
(char*) &optval, \ (char*) &optval, \
sizeof optval)) { \ sizeof optval)) { \
uv__set_sys_error(handle->loop, WSAGetLastError()); \ return uv_translate_sys_error(WSAGetLastError()); \
return -1; \
} \ } \
} \ } \
return 0; \ return 0; \

125
deps/uv/src/win/util.c

@ -102,9 +102,10 @@ int uv_utf8_to_utf16(const char* utf8Buffer, WCHAR* utf16Buffer,
int uv_exepath(char* buffer, size_t* size_ptr) { int uv_exepath(char* buffer, size_t* size_ptr) {
int utf8_len, utf16_buffer_len, utf16_len; int utf8_len, utf16_buffer_len, utf16_len;
WCHAR* utf16_buffer; WCHAR* utf16_buffer;
int err;
if (buffer == NULL || size_ptr == NULL || *size_ptr == 0) { if (buffer == NULL || size_ptr == NULL || *size_ptr == 0) {
return -1; return UV_EINVAL;
} }
if (*size_ptr > 32768) { if (*size_ptr > 32768) {
@ -116,12 +117,13 @@ int uv_exepath(char* buffer, size_t* size_ptr) {
utf16_buffer = (WCHAR*) malloc(sizeof(WCHAR) * utf16_buffer_len); utf16_buffer = (WCHAR*) malloc(sizeof(WCHAR) * utf16_buffer_len);
if (!utf16_buffer) { if (!utf16_buffer) {
return -1; return UV_ENOMEM;
} }
/* Get the path as UTF-16. */ /* Get the path as UTF-16. */
utf16_len = GetModuleFileNameW(NULL, utf16_buffer, utf16_buffer_len); utf16_len = GetModuleFileNameW(NULL, utf16_buffer, utf16_buffer_len);
if (utf16_len <= 0) { if (utf16_len <= 0) {
err = GetLastError();
goto error; goto error;
} }
@ -138,6 +140,7 @@ int uv_exepath(char* buffer, size_t* size_ptr) {
NULL, NULL,
NULL); NULL);
if (utf8_len == 0) { if (utf8_len == 0) {
err = GetLastError();
goto error; goto error;
} }
@ -150,26 +153,26 @@ int uv_exepath(char* buffer, size_t* size_ptr) {
error: error:
free(utf16_buffer); free(utf16_buffer);
return -1; return uv_translate_sys_error(err);
} }
uv_err_t uv_cwd(char* buffer, size_t size) { int uv_cwd(char* buffer, size_t size) {
DWORD utf16_len; DWORD utf16_len;
WCHAR utf16_buffer[MAX_PATH]; WCHAR utf16_buffer[MAX_PATH];
int r; int r;
if (buffer == NULL || size == 0) { if (buffer == NULL || size == 0) {
return uv__new_artificial_error(UV_EINVAL); return UV_EINVAL;
} }
utf16_len = GetCurrentDirectoryW(MAX_PATH, utf16_buffer); utf16_len = GetCurrentDirectoryW(MAX_PATH, utf16_buffer);
if (utf16_len == 0) { if (utf16_len == 0) {
return uv__new_sys_error(GetLastError()); return uv_translate_sys_error(GetLastError());
} else if (utf16_len > MAX_PATH) { } else if (utf16_len > MAX_PATH) {
/* This should be impossible; however the CRT has a code path to deal */ /* This should be impossible; however the CRT has a code path to deal */
/* with this scenario, so I added a check anyway. */ /* with this scenario, so I added a check anyway. */
return uv__new_artificial_error(UV_EIO); return UV_EIO;
} }
/* utf16_len contains the length, *not* including the terminating null. */ /* utf16_len contains the length, *not* including the terminating null. */
@ -193,20 +196,20 @@ uv_err_t uv_cwd(char* buffer, size_t size) {
NULL, NULL,
NULL); NULL);
if (r == 0) { if (r == 0) {
return uv__new_sys_error(GetLastError()); return uv_translate_sys_error(GetLastError());
} }
return uv_ok_; return 0;
} }
uv_err_t uv_chdir(const char* dir) { int uv_chdir(const char* dir) {
WCHAR utf16_buffer[MAX_PATH]; WCHAR utf16_buffer[MAX_PATH];
size_t utf16_len; size_t utf16_len;
WCHAR drive_letter, env_var[4]; WCHAR drive_letter, env_var[4];
if (dir == NULL) { if (dir == NULL) {
return uv__new_artificial_error(UV_EINVAL); return UV_EINVAL;
} }
if (MultiByteToWideChar(CP_UTF8, if (MultiByteToWideChar(CP_UTF8,
@ -220,14 +223,14 @@ uv_err_t uv_chdir(const char* dir) {
/* including terminating null. If it doesn't fit, the path name must be */ /* including terminating null. If it doesn't fit, the path name must be */
/* too long. */ /* too long. */
if (error == ERROR_INSUFFICIENT_BUFFER) { if (error == ERROR_INSUFFICIENT_BUFFER) {
return uv__new_artificial_error(UV_ENAMETOOLONG); return UV_ENAMETOOLONG;
} else { } else {
return uv__new_sys_error(error); return uv_translate_sys_error(error);
} }
} }
if (!SetCurrentDirectoryW(utf16_buffer)) { if (!SetCurrentDirectoryW(utf16_buffer)) {
return uv__new_sys_error(GetLastError()); return uv_translate_sys_error(GetLastError());
} }
/* Windows stores the drive-local path in an "hidden" environment variable, */ /* Windows stores the drive-local path in an "hidden" environment variable, */
@ -235,9 +238,9 @@ uv_err_t uv_chdir(const char* dir) {
/* update this, so we'll have to do it. */ /* update this, so we'll have to do it. */
utf16_len = GetCurrentDirectoryW(MAX_PATH, utf16_buffer); utf16_len = GetCurrentDirectoryW(MAX_PATH, utf16_buffer);
if (utf16_len == 0) { if (utf16_len == 0) {
return uv__new_sys_error(GetLastError()); return uv_translate_sys_error(GetLastError());
} else if (utf16_len > MAX_PATH) { } else if (utf16_len > MAX_PATH) {
return uv__new_artificial_error(UV_EIO); return UV_EIO;
} }
/* The returned directory should not have a trailing slash, unless it */ /* The returned directory should not have a trailing slash, unless it */
@ -270,11 +273,11 @@ uv_err_t uv_chdir(const char* dir) {
env_var[3] = L'\0'; env_var[3] = L'\0';
if (!SetEnvironmentVariableW(env_var, utf16_buffer)) { if (!SetEnvironmentVariableW(env_var, utf16_buffer)) {
return uv__new_sys_error(GetLastError()); return uv_translate_sys_error(GetLastError());
} }
} }
return uv_ok_; return 0;
} }
@ -338,8 +341,8 @@ char** uv_setup_args(int argc, char** argv) {
} }
uv_err_t uv_set_process_title(const char* title) { int uv_set_process_title(const char* title) {
uv_err_t err; int err;
int length; int length;
WCHAR* title_w = NULL; WCHAR* title_w = NULL;
@ -348,7 +351,7 @@ uv_err_t uv_set_process_title(const char* title) {
/* Find out how big the buffer for the wide-char title must be */ /* Find out how big the buffer for the wide-char title must be */
length = uv_utf8_to_utf16(title, NULL, 0); length = uv_utf8_to_utf16(title, NULL, 0);
if (!length) { if (!length) {
err = uv__new_sys_error(GetLastError()); err = GetLastError();
goto done; goto done;
} }
@ -360,7 +363,7 @@ uv_err_t uv_set_process_title(const char* title) {
length = uv_utf8_to_utf16(title, title_w, length); length = uv_utf8_to_utf16(title, title_w, length);
if (!length) { if (!length) {
err = uv__new_sys_error(GetLastError()); err = GetLastError();
goto done; goto done;
}; };
@ -370,7 +373,7 @@ uv_err_t uv_set_process_title(const char* title) {
} }
if (!SetConsoleTitleW(title_w)) { if (!SetConsoleTitleW(title_w)) {
err = uv__new_sys_error(GetLastError()); err = GetLastError();
goto done; goto done;
} }
@ -379,11 +382,11 @@ uv_err_t uv_set_process_title(const char* title) {
process_title = strdup(title); process_title = strdup(title);
LeaveCriticalSection(&process_title_lock); LeaveCriticalSection(&process_title_lock);
err = uv_ok_; err = 0;
done: done:
free(title_w); free(title_w);
return err; return uv_translate_sys_error(err);
} }
@ -417,7 +420,7 @@ static int uv__get_process_title() {
} }
uv_err_t uv_get_process_title(char* buffer, size_t size) { int uv_get_process_title(char* buffer, size_t size) {
uv__once_init(); uv__once_init();
EnterCriticalSection(&process_title_lock); EnterCriticalSection(&process_title_lock);
@ -426,14 +429,14 @@ uv_err_t uv_get_process_title(char* buffer, size_t size) {
* we must query it with getConsoleTitleW * we must query it with getConsoleTitleW
*/ */
if (!process_title && uv__get_process_title() == -1) { if (!process_title && uv__get_process_title() == -1) {
return uv__new_sys_error(GetLastError()); return uv_translate_sys_error(GetLastError());
} }
assert(process_title); assert(process_title);
strncpy(buffer, process_title, size); strncpy(buffer, process_title, size);
LeaveCriticalSection(&process_title_lock); LeaveCriticalSection(&process_title_lock);
return uv_ok_; return 0;
} }
@ -462,23 +465,23 @@ uint64_t uv_hrtime(void) {
} }
uv_err_t uv_resident_set_memory(size_t* rss) { int uv_resident_set_memory(size_t* rss) {
HANDLE current_process; HANDLE current_process;
PROCESS_MEMORY_COUNTERS pmc; PROCESS_MEMORY_COUNTERS pmc;
current_process = GetCurrentProcess(); current_process = GetCurrentProcess();
if (!GetProcessMemoryInfo(current_process, &pmc, sizeof(pmc))) { if (!GetProcessMemoryInfo(current_process, &pmc, sizeof(pmc))) {
return uv__new_sys_error(GetLastError()); return uv_translate_sys_error(GetLastError());
} }
*rss = pmc.WorkingSetSize; *rss = pmc.WorkingSetSize;
return uv_ok_; return 0;
} }
uv_err_t uv_uptime(double* uptime) { int uv_uptime(double* uptime) {
BYTE stack_buffer[4096]; BYTE stack_buffer[4096];
BYTE* malloced_buffer = NULL; BYTE* malloced_buffer = NULL;
BYTE* buffer = (BYTE*) stack_buffer; BYTE* buffer = (BYTE*) stack_buffer;
@ -505,7 +508,7 @@ uv_err_t uv_uptime(double* uptime) {
break; break;
} else if (result != ERROR_MORE_DATA) { } else if (result != ERROR_MORE_DATA) {
*uptime = 0; *uptime = 0;
return uv__new_sys_error(result); return uv_translate_sys_error(result);
} }
free(malloced_buffer); free(malloced_buffer);
@ -519,7 +522,7 @@ uv_err_t uv_uptime(double* uptime) {
buffer = malloced_buffer = (BYTE*) malloc(buffer_size); buffer = malloced_buffer = (BYTE*) malloc(buffer_size);
if (malloced_buffer == NULL) { if (malloced_buffer == NULL) {
*uptime = 0; *uptime = 0;
return uv__new_artificial_error(UV_ENOMEM); return UV_ENOMEM;
} }
} }
@ -559,7 +562,7 @@ uv_err_t uv_uptime(double* uptime) {
*uptime = (double) (object_type->PerfTime.QuadPart - value) / *uptime = (double) (object_type->PerfTime.QuadPart - value) /
(double) object_type->PerfFreq.QuadPart; (double) object_type->PerfFreq.QuadPart;
free(malloced_buffer); free(malloced_buffer);
return uv_ok_; return 0;
} }
} }
@ -570,16 +573,16 @@ uv_err_t uv_uptime(double* uptime) {
/* If we get here, the uptime value was not found. */ /* If we get here, the uptime value was not found. */
free(malloced_buffer); free(malloced_buffer);
*uptime = 0; *uptime = 0;
return uv__new_artificial_error(UV_ENOSYS); return UV_ENOSYS;
internalError: internalError:
free(malloced_buffer); free(malloced_buffer);
*uptime = 0; *uptime = 0;
return uv__new_artificial_error(UV_EIO); return UV_EIO;
} }
uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos_ptr, int* cpu_count_ptr) { int uv_cpu_info(uv_cpu_info_t** cpu_infos_ptr, int* cpu_count_ptr) {
uv_cpu_info_t* cpu_infos; uv_cpu_info_t* cpu_infos;
SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* sppi; SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* sppi;
DWORD sppi_size; DWORD sppi_size;
@ -587,7 +590,7 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos_ptr, int* cpu_count_ptr) {
DWORD cpu_count, r, i; DWORD cpu_count, r, i;
NTSTATUS status; NTSTATUS status;
ULONG result_size; ULONG result_size;
uv_err_t err; int err;
uv_cpu_info_t* cpu_info; uv_cpu_info_t* cpu_info;
cpu_infos = NULL; cpu_infos = NULL;
@ -601,14 +604,14 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos_ptr, int* cpu_count_ptr) {
cpu_infos = calloc(cpu_count, sizeof *cpu_infos); cpu_infos = calloc(cpu_count, sizeof *cpu_infos);
if (cpu_infos == NULL) { if (cpu_infos == NULL) {
err = uv__new_artificial_error(UV_ENOMEM); err = ERROR_OUTOFMEMORY;
goto error; goto error;
} }
sppi_size = cpu_count * sizeof(*sppi); sppi_size = cpu_count * sizeof(*sppi);
sppi = malloc(sppi_size); sppi = malloc(sppi_size);
if (sppi == NULL) { if (sppi == NULL) {
err = uv__new_artificial_error(UV_ENOMEM); err = ERROR_OUTOFMEMORY;
goto error; goto error;
} }
@ -617,7 +620,7 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos_ptr, int* cpu_count_ptr) {
sppi_size, sppi_size,
&result_size); &result_size);
if (!NT_SUCCESS(status)) { if (!NT_SUCCESS(status)) {
err = uv__new_sys_error(pRtlNtStatusToDosError(status)); err = pRtlNtStatusToDosError(status);
goto error; goto error;
} }
@ -645,7 +648,7 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos_ptr, int* cpu_count_ptr) {
KEY_QUERY_VALUE, KEY_QUERY_VALUE,
&processor_key); &processor_key);
if (r != ERROR_SUCCESS) { if (r != ERROR_SUCCESS) {
err = uv__new_sys_error(GetLastError()); err = GetLastError();
goto error; goto error;
} }
@ -655,7 +658,7 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos_ptr, int* cpu_count_ptr) {
NULL, NULL,
(BYTE*) &cpu_speed, (BYTE*) &cpu_speed,
&cpu_speed_size) != ERROR_SUCCESS) { &cpu_speed_size) != ERROR_SUCCESS) {
err = uv__new_sys_error(GetLastError()); err = GetLastError();
RegCloseKey(processor_key); RegCloseKey(processor_key);
goto error; goto error;
} }
@ -666,7 +669,7 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos_ptr, int* cpu_count_ptr) {
NULL, NULL,
(BYTE*) &cpu_brand, (BYTE*) &cpu_brand,
&cpu_brand_size) != ERROR_SUCCESS) { &cpu_brand_size) != ERROR_SUCCESS) {
err = uv__new_sys_error(GetLastError()); err = GetLastError();
RegCloseKey(processor_key); RegCloseKey(processor_key);
goto error; goto error;
} }
@ -692,7 +695,7 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos_ptr, int* cpu_count_ptr) {
NULL, NULL,
NULL); NULL);
if (len == 0) { if (len == 0) {
err = uv__new_sys_error(GetLastError()); err = GetLastError();
goto error; goto error;
} }
@ -701,7 +704,7 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos_ptr, int* cpu_count_ptr) {
/* Allocate 1 extra byte for the null terminator. */ /* Allocate 1 extra byte for the null terminator. */
cpu_info->model = malloc(len + 1); cpu_info->model = malloc(len + 1);
if (cpu_info->model == NULL) { if (cpu_info->model == NULL) {
err = uv__new_artificial_error(UV_ENOMEM); err = ERROR_OUTOFMEMORY;
goto error; goto error;
} }
@ -713,7 +716,7 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos_ptr, int* cpu_count_ptr) {
len, len,
NULL, NULL,
NULL) == 0) { NULL) == 0) {
err = uv__new_sys_error(GetLastError()); err = GetLastError();
goto error; goto error;
} }
@ -726,7 +729,7 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos_ptr, int* cpu_count_ptr) {
*cpu_count_ptr = cpu_count; *cpu_count_ptr = cpu_count;
*cpu_infos_ptr = cpu_infos; *cpu_infos_ptr = cpu_infos;
return uv_ok_; return 0;
error: error:
/* This is safe because the cpu_infos array is zeroed on allocation. */ /* This is safe because the cpu_infos array is zeroed on allocation. */
@ -736,7 +739,7 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos_ptr, int* cpu_count_ptr) {
free(cpu_infos); free(cpu_infos);
free(sppi); free(sppi);
return err; return uv_translate_sys_error(err);
} }
@ -751,7 +754,7 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
} }
uv_err_t uv_interface_addresses(uv_interface_address_t** addresses_ptr, int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
int* count_ptr) { int* count_ptr) {
IP_ADAPTER_ADDRESSES* win_address_buf; IP_ADAPTER_ADDRESSES* win_address_buf;
ULONG win_address_buf_size; ULONG win_address_buf_size;
@ -792,7 +795,7 @@ uv_err_t uv_interface_addresses(uv_interface_address_t** addresses_ptr,
/* all adapters. */ /* all adapters. */
win_address_buf = malloc(win_address_buf_size); win_address_buf = malloc(win_address_buf_size);
if (win_address_buf == NULL) if (win_address_buf == NULL)
return uv__new_artificial_error(UV_ENOMEM); return UV_ENOMEM;
continue; continue;
@ -800,16 +803,16 @@ uv_err_t uv_interface_addresses(uv_interface_address_t** addresses_ptr,
/* No adapters were found. */ /* No adapters were found. */
uv_address_buf = malloc(1); uv_address_buf = malloc(1);
if (uv_address_buf == NULL) if (uv_address_buf == NULL)
return uv__new_artificial_error(UV_ENOMEM); return UV_ENOMEM;
*count_ptr = 0; *count_ptr = 0;
*addresses_ptr = uv_address_buf; *addresses_ptr = uv_address_buf;
return uv_ok_; return 0;
} }
case ERROR_ADDRESS_NOT_ASSOCIATED: case ERROR_ADDRESS_NOT_ASSOCIATED:
return uv__new_artificial_error(UV_EAGAIN); return UV_EAGAIN;
case ERROR_INVALID_PARAMETER: case ERROR_INVALID_PARAMETER:
/* MSDN says: /* MSDN says:
@ -820,13 +823,13 @@ uv_err_t uv_interface_addresses(uv_interface_address_t** addresses_ptr,
* Since the first two conditions are not met, it must be that the * Since the first two conditions are not met, it must be that the
* adapter data is too big. * adapter data is too big.
*/ */
return uv__new_artificial_error(UV_ENOBUFS); return UV_ENOBUFS;
default: default:
/* Other (unspecified) errors can happen, but we don't have any */ /* Other (unspecified) errors can happen, but we don't have any */
/* special meaning for them. */ /* special meaning for them. */
assert(r != ERROR_SUCCESS); assert(r != ERROR_SUCCESS);
return uv__new_sys_error(r); return uv_translate_sys_error(r);
} }
} }
@ -861,7 +864,7 @@ uv_err_t uv_interface_addresses(uv_interface_address_t** addresses_ptr,
FALSE); FALSE);
if (name_size <= 0) { if (name_size <= 0) {
free(win_address_buf); free(win_address_buf);
return uv__new_sys_error(GetLastError()); return uv_translate_sys_error(GetLastError());
} }
uv_address_buf_size += name_size; uv_address_buf_size += name_size;
@ -880,7 +883,7 @@ uv_err_t uv_interface_addresses(uv_interface_address_t** addresses_ptr,
uv_address_buf = malloc(uv_address_buf_size); uv_address_buf = malloc(uv_address_buf_size);
if (uv_address_buf == NULL) { if (uv_address_buf == NULL) {
free(win_address_buf); free(win_address_buf);
return uv__new_artificial_error(UV_ENOMEM); return UV_ENOMEM;
} }
/* Compute the start of the uv_interface_address_t array, and the place in */ /* Compute the start of the uv_interface_address_t array, and the place in */
@ -916,7 +919,7 @@ uv_err_t uv_interface_addresses(uv_interface_address_t** addresses_ptr,
if (name_size <= 0) { if (name_size <= 0) {
free(win_address_buf); free(win_address_buf);
free(uv_address_buf); free(uv_address_buf);
return uv__new_sys_error(GetLastError()); return uv_translate_sys_error(GetLastError());
} }
prefix = win_address->FirstPrefix; prefix = win_address->FirstPrefix;
@ -966,7 +969,7 @@ uv_err_t uv_interface_addresses(uv_interface_address_t** addresses_ptr,
*addresses_ptr = uv_address_buf; *addresses_ptr = uv_address_buf;
*count_ptr = count; *count_ptr = count;
return uv_ok_; return 0;
} }

3
deps/uv/test/benchmark-multi-accept.c

@ -302,8 +302,7 @@ static uv_buf_t sv_alloc_cb(uv_handle_t* handle, size_t suggested_size) {
static void sv_read_cb(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) { static void sv_read_cb(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) {
ASSERT(nread == -1); ASSERT(nread == UV_EOF);
ASSERT(uv_last_error(handle->loop).code == UV_EOF);
uv_close((uv_handle_t*) handle, (uv_close_cb) free); uv_close((uv_handle_t*) handle, (uv_close_cb) free);
} }

2
deps/uv/test/benchmark-ping-pongs.c

@ -130,7 +130,7 @@ static void pinger_read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) {
pinger = (pinger_t*)tcp->data; pinger = (pinger_t*)tcp->data;
if (nread < 0) { if (nread < 0) {
ASSERT(uv_last_error(loop).code == UV_EOF); ASSERT(nread == UV_EOF);
if (buf.base) { if (buf.base) {
buf_free(buf); buf_free(buf);

18
deps/uv/test/benchmark-pound.c

@ -92,7 +92,7 @@ static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) {
static void after_write(uv_write_t* req, int status) { static void after_write(uv_write_t* req, int status) {
if (status != 0) { if (status != 0) {
fprintf(stderr, "write error %s\n", uv_err_name(uv_last_error(loop))); fprintf(stderr, "write error %s\n", uv_err_name(status));
uv_close((uv_handle_t*)req->handle, close_cb); uv_close((uv_handle_t*)req->handle, close_cb);
conns_failed++; conns_failed++;
return; return;
@ -107,9 +107,7 @@ static void connect_cb(uv_connect_t* req, int status) {
if (status != 0) { if (status != 0) {
#if DEBUG #if DEBUG
fprintf(stderr, fprintf(stderr, "connect error %s\n", uv_err_name(status));
"connect error %s\n",
uv_err_name(uv_last_error(uv_default_loop())));
#endif #endif
uv_close((uv_handle_t*)req->handle, close_cb); uv_close((uv_handle_t*)req->handle, close_cb);
conns_failed++; conns_failed++;
@ -138,7 +136,6 @@ static void connect_cb(uv_connect_t* req, int status) {
static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) { static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) {
uv_err_t err = uv_last_error(loop);
ASSERT(stream != NULL); ASSERT(stream != NULL);
@ -148,13 +145,13 @@ static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) {
uv_close((uv_handle_t*)stream, close_cb); uv_close((uv_handle_t*)stream, close_cb);
if (nread == -1) { if (nread < 0) {
if (err.code == UV_EOF) { if (nread == UV_EOF) {
; ;
} else if (err.code == UV_ECONNRESET) { } else if (nread == UV_ECONNRESET) {
conns_failed++; conns_failed++;
} else { } else {
fprintf(stderr, "read error %s\n", uv_err_name(uv_last_error(loop))); fprintf(stderr, "read error %s\n", uv_err_name(nread));
ASSERT(0); ASSERT(0);
} }
} }
@ -206,8 +203,7 @@ static void tcp_make_connect(conn_rec* p) {
r = uv_tcp_connect(&((tcp_conn_rec*)p)->conn_req, (uv_tcp_t*)&p->stream, addr, connect_cb); r = uv_tcp_connect(&((tcp_conn_rec*)p)->conn_req, (uv_tcp_t*)&p->stream, addr, connect_cb);
if (r) { if (r) {
fprintf(stderr, "uv_tcp_connect error %s\n", fprintf(stderr, "uv_tcp_connect error %s\n", uv_err_name(r));
uv_err_name(uv_last_error(loop)));
ASSERT(0); ASSERT(0);
} }

2
deps/uv/test/benchmark-pump.c

@ -206,7 +206,7 @@ static void do_write(uv_stream_t* stream) {
static void connect_cb(uv_connect_t* req, int status) { static void connect_cb(uv_connect_t* req, int status) {
int i; int i;
if (status) LOG(uv_strerror(uv_last_error(loop))); if (status) LOG(uv_strerror(status));
ASSERT(status == 0); ASSERT(status == 0);
write_sockets++; write_sockets++;

4
deps/uv/test/benchmark-spawn.c

@ -87,13 +87,11 @@ static void pipe_close_cb(uv_handle_t* pipe) {
static void on_read(uv_stream_t* pipe, ssize_t nread, uv_buf_t buf) { static void on_read(uv_stream_t* pipe, ssize_t nread, uv_buf_t buf) {
uv_err_t err = uv_last_error(loop);
if (nread > 0) { if (nread > 0) {
ASSERT(pipe_open == 1); ASSERT(pipe_open == 1);
output_used += nread; output_used += nread;
} else if (nread < 0) { } else if (nread < 0) {
if (err.code == UV_EOF) { if (nread == UV_EOF) {
uv_close((uv_handle_t*)pipe, pipe_close_cb); uv_close((uv_handle_t*)pipe, pipe_close_cb);
} }
} }

7
deps/uv/test/benchmark-udp-pummel.c

@ -72,8 +72,7 @@ static void send_cb(uv_udp_send_t* req, int status) {
ASSERT(req != NULL); ASSERT(req != NULL);
if (status != 0) { if (status != 0) {
ASSERT(status == -1); ASSERT(status == UV_ECANCELED);
ASSERT(uv_last_error(req->handle->loop).code == UV_ECANCELED);
return; return;
} }
@ -112,8 +111,8 @@ static void recv_cb(uv_udp_t* handle,
if (nread == 0) if (nread == 0)
return; return;
if (nread == -1) { if (nread < 0) {
ASSERT(uv_last_error(handle->loop).code == UV_ECANCELED); ASSERT(nread == UV_ECANCELED);
return; return;
} }

2
deps/uv/test/blackhole-server.c

@ -73,7 +73,7 @@ static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) {
if (nread >= 0) if (nread >= 0)
return; return;
ASSERT(uv_last_error(stream->loop).code == UV_EOF); ASSERT(nread == UV_EOF);
conn = container_of(stream, conn_rec, handle); conn = container_of(stream, conn_rec, handle);

5
deps/uv/test/dns-server.c

@ -81,8 +81,7 @@ static void after_write(uv_write_t* req, int status) {
write_req_t* wr; write_req_t* wr;
if (status) { if (status) {
uv_err_t err = uv_last_error(loop); fprintf(stderr, "uv_write error: %s\n", uv_strerror(status));
fprintf(stderr, "uv_write error: %s\n", uv_strerror(err));
ASSERT(0); ASSERT(0);
} }
@ -229,7 +228,7 @@ static void after_read(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) {
if (nread < 0) { if (nread < 0) {
/* Error or EOF */ /* Error or EOF */
ASSERT (uv_last_error(loop).code == UV_EOF); ASSERT(nread == UV_EOF);
if (buf.base) { if (buf.base) {
free(buf.base); free(buf.base);

31
deps/uv/test/echo-server.c

@ -47,7 +47,6 @@ static void on_connection(uv_stream_t*, int status);
static void after_write(uv_write_t* req, int status) { static void after_write(uv_write_t* req, int status) {
write_req_t* wr; write_req_t* wr;
uv_err_t err;
/* Free the read/write buffer and the request */ /* Free the read/write buffer and the request */
wr = (write_req_t*) req; wr = (write_req_t*) req;
@ -57,13 +56,12 @@ static void after_write(uv_write_t* req, int status) {
if (status == 0) if (status == 0)
return; return;
err = uv_last_error(loop); fprintf(stderr, "uv_write error: %s\n", uv_strerror(status));
fprintf(stderr, "uv_write error: %s\n", uv_strerror(err));
if (err.code == UV_ECANCELED) if (status == UV_ECANCELED)
return; return;
ASSERT(err.code == UV_EPIPE); ASSERT(status == UV_EPIPE);
uv_close((uv_handle_t*)req->handle, on_close); uv_close((uv_handle_t*)req->handle, on_close);
} }
@ -81,7 +79,7 @@ static void after_read(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) {
if (nread < 0) { if (nread < 0) {
/* Error or EOF */ /* Error or EOF */
ASSERT (uv_last_error(loop).code == UV_EOF); ASSERT(nread == UV_EOF);
if (buf.base) { if (buf.base) {
free(buf.base); free(buf.base);
@ -142,8 +140,7 @@ static void on_connection(uv_stream_t* server, int status) {
int r; int r;
if (status != 0) { if (status != 0) {
fprintf(stderr, "Connect error %d\n", fprintf(stderr, "Connect error %s\n", uv_err_name(status));
uv_last_error(loop).code);
} }
ASSERT(status == 0); ASSERT(status == 0);
@ -235,8 +232,7 @@ static int tcp4_echo_start(int port) {
r = uv_listen((uv_stream_t*)&tcpServer, SOMAXCONN, on_connection); r = uv_listen((uv_stream_t*)&tcpServer, SOMAXCONN, on_connection);
if (r) { if (r) {
/* TODO: Error codes */ /* TODO: Error codes */
fprintf(stderr, "Listen error %s\n", fprintf(stderr, "Listen error %s\n", uv_err_name(r));
uv_err_name(uv_last_error(loop)));
return 1; return 1;
} }
@ -285,15 +281,13 @@ static int udp4_echo_start(int port) {
r = uv_udp_init(loop, &udpServer); r = uv_udp_init(loop, &udpServer);
if (r) { if (r) {
fprintf(stderr, "uv_udp_init: %s\n", fprintf(stderr, "uv_udp_init: %s\n", uv_strerror(r));
uv_strerror(uv_last_error(loop)));
return 1; return 1;
} }
r = uv_udp_recv_start(&udpServer, echo_alloc, on_recv); r = uv_udp_recv_start(&udpServer, echo_alloc, on_recv);
if (r) { if (r) {
fprintf(stderr, "uv_udp_recv_start: %s\n", fprintf(stderr, "uv_udp_recv_start: %s\n", uv_strerror(r));
uv_strerror(uv_last_error(loop)));
return 1; return 1;
} }
@ -317,22 +311,19 @@ static int pipe_echo_start(char* pipeName) {
r = uv_pipe_init(loop, &pipeServer, 0); r = uv_pipe_init(loop, &pipeServer, 0);
if (r) { if (r) {
fprintf(stderr, "uv_pipe_init: %s\n", fprintf(stderr, "uv_pipe_init: %s\n", uv_strerror(r));
uv_strerror(uv_last_error(loop)));
return 1; return 1;
} }
r = uv_pipe_bind(&pipeServer, pipeName); r = uv_pipe_bind(&pipeServer, pipeName);
if (r) { if (r) {
fprintf(stderr, "uv_pipe_bind: %s\n", fprintf(stderr, "uv_pipe_bind: %s\n", uv_strerror(r));
uv_strerror(uv_last_error(loop)));
return 1; return 1;
} }
r = uv_listen((uv_stream_t*)&pipeServer, SOMAXCONN, on_connection); r = uv_listen((uv_stream_t*)&pipeServer, SOMAXCONN, on_connection);
if (r) { if (r) {
fprintf(stderr, "uv_pipe_listen: %s\n", fprintf(stderr, "uv_pipe_listen: %s\n", uv_strerror(r));
uv_strerror(uv_last_error(loop)));
return 1; return 1;
} }

2
deps/uv/test/task.h

@ -27,7 +27,7 @@
#include <stdlib.h> #include <stdlib.h>
#if defined(_MSC_VER) && _MSC_VER < 1600 #if defined(_MSC_VER) && _MSC_VER < 1600
# include "uv-private/stdint-msvc2008.h" # include "stdint-msvc2008.h"
#else #else
# include <stdint.h> # include <stdint.h>
#endif #endif

5
deps/uv/test/test-callback-stack.c

@ -76,11 +76,10 @@ static void read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) {
free(buf.base); free(buf.base);
if (nread == 0) { if (nread == 0) {
ASSERT(uv_last_error(uv_default_loop()).code == UV_EAGAIN);
return; return;
} else if (nread == -1) { } else if (nread < 0) {
ASSERT(uv_last_error(uv_default_loop()).code == UV_EOF); ASSERT(nread == UV_EOF);
nested++; nested++;
uv_close((uv_handle_t*)tcp, close_cb); uv_close((uv_handle_t*)tcp, close_cb);

2
deps/uv/test/test-condvar.c

@ -112,7 +112,7 @@ TEST_IMPL(condvar_3) {
uv_mutex_lock(&wc.mutex); uv_mutex_lock(&wc.mutex);
r = uv_cond_timedwait(&wc.cond, &wc.mutex, (uint64_t)(50 * 1e6)); r = uv_cond_timedwait(&wc.cond, &wc.mutex, (uint64_t)(50 * 1e6));
ASSERT(r == -1); ASSERT(r == UV_ETIMEDOUT);
uv_mutex_unlock(&wc.mutex); uv_mutex_unlock(&wc.mutex);
ASSERT(0 == uv_thread_join(&thread)); ASSERT(0 == uv_thread_join(&thread));

6
deps/uv/test/test-connection-fail.c

@ -68,8 +68,7 @@ static void timer_cb(uv_timer_t* handle, int status) {
static void on_connect_with_close(uv_connect_t *req, int status) { static void on_connect_with_close(uv_connect_t *req, int status) {
ASSERT((uv_stream_t*) &tcp == req->handle); ASSERT((uv_stream_t*) &tcp == req->handle);
ASSERT(status == -1); ASSERT(status == UV_ECONNREFUSED);
ASSERT(uv_last_error(uv_default_loop()).code == UV_ECONNREFUSED);
connect_cb_calls++; connect_cb_calls++;
ASSERT(close_cb_calls == 0); ASSERT(close_cb_calls == 0);
@ -78,8 +77,7 @@ static void on_connect_with_close(uv_connect_t *req, int status) {
static void on_connect_without_close(uv_connect_t *req, int status) { static void on_connect_without_close(uv_connect_t *req, int status) {
ASSERT(status == -1); ASSERT(status == UV_ECONNREFUSED);
ASSERT(uv_last_error(uv_default_loop()).code == UV_ECONNREFUSED);
connect_cb_calls++; connect_cb_calls++;
uv_timer_start(&timer, timer_cb, 100, 0); uv_timer_start(&timer, timer_cb, 100, 0);

8
deps/uv/test/test-cwd-and-chdir.c

@ -31,11 +31,11 @@ TEST_IMPL(cwd_and_chdir) {
char buffer_new[PATHMAX]; char buffer_new[PATHMAX];
size_t size; size_t size;
char* last_slash; char* last_slash;
uv_err_t err; int err;
size = sizeof(buffer_orig) / sizeof(buffer_orig[0]); size = sizeof(buffer_orig) / sizeof(buffer_orig[0]);
err = uv_cwd(buffer_orig, size); err = uv_cwd(buffer_orig, size);
ASSERT(err.code == UV_OK); ASSERT(err == 0);
/* Remove trailing slash unless at a root directory. */ /* Remove trailing slash unless at a root directory. */
#ifdef _WIN32 #ifdef _WIN32
@ -53,10 +53,10 @@ TEST_IMPL(cwd_and_chdir) {
#endif #endif
err = uv_chdir(buffer_orig); err = uv_chdir(buffer_orig);
ASSERT(err.code == UV_OK); ASSERT(err == 0);
err = uv_cwd(buffer_new, size); err = uv_cwd(buffer_new, size);
ASSERT(err.code == UV_OK); ASSERT(err == 0);
ASSERT(strcmp(buffer_orig, buffer_new) == 0); ASSERT(strcmp(buffer_orig, buffer_new) == 0);

6
deps/uv/test/test-delayed-accept.c

@ -124,13 +124,11 @@ static void read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) {
free(buf.base); free(buf.base);
} }
if (nread != -1) { if (nread >= 0) {
ASSERT(nread == 0); ASSERT(nread == 0);
ASSERT(uv_last_error(uv_default_loop()).code == UV_EAGAIN);
} else { } else {
ASSERT(tcp != NULL); ASSERT(tcp != NULL);
ASSERT(nread == -1); ASSERT(nread == UV_EOF);
ASSERT(uv_last_error(uv_default_loop()).code == UV_EOF);
uv_close((uv_handle_t*)tcp, close_cb); uv_close((uv_handle_t*)tcp, close_cb);
} }
} }

17
deps/uv/test/test-error.c

@ -34,26 +34,17 @@
* See https://github.com/joyent/libuv/issues/210 * See https://github.com/joyent/libuv/issues/210
*/ */
TEST_IMPL(error_message) { TEST_IMPL(error_message) {
uv_err_t e;
/* Cop out. Can't do proper checks on systems with /* Cop out. Can't do proper checks on systems with
* i18n-ized error messages... * i18n-ized error messages...
*/ */
e.code = 0, e.sys_errno_ = 0; if (strcmp(uv_strerror(0), "Success") != 0) {
if (strcmp(uv_strerror(e), "Success") != 0) {
printf("i18n error messages detected, skipping test.\n"); printf("i18n error messages detected, skipping test.\n");
return 0; return 0;
} }
e.code = UV_EINVAL, e.sys_errno_ = 0; ASSERT(strstr(uv_strerror(UV_EINVAL), "Success") == NULL);
ASSERT(strstr(uv_strerror(e), "Success") == NULL); ASSERT(strcmp(uv_strerror(1337), "Unknown error") == 0);
ASSERT(strcmp(uv_strerror(-1337), "Unknown error") == 0);
e.code = UV_UNKNOWN, e.sys_errno_ = 0;
ASSERT(strcmp(uv_strerror(e), "Unknown error") == 0);
e.code = 1337, e.sys_errno_ = 0;
ASSERT(strcmp(uv_strerror(e), "Unknown error") == 0);
return 0; return 0;
} }

28
deps/uv/test/test-fs-event.c

@ -46,7 +46,7 @@ static void create_dir(uv_loop_t* loop, const char* name) {
int r; int r;
uv_fs_t req; uv_fs_t req;
r = uv_fs_mkdir(loop, &req, name, 0755, NULL); r = uv_fs_mkdir(loop, &req, name, 0755, NULL);
ASSERT(r == 0 || uv_last_error(loop).code == UV_EEXIST); ASSERT(r == 0 || r == UV_EEXIST);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
} }
@ -57,7 +57,7 @@ static void create_file(uv_loop_t* loop, const char* name) {
r = uv_fs_open(loop, &req, name, O_WRONLY | O_CREAT, r = uv_fs_open(loop, &req, name, O_WRONLY | O_CREAT,
S_IWUSR | S_IRUSR, NULL); S_IWUSR | S_IRUSR, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
file = r; file = r;
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
r = uv_fs_close(loop, &req, file, NULL); r = uv_fs_close(loop, &req, file, NULL);
@ -71,16 +71,16 @@ static void touch_file(uv_loop_t* loop, const char* name) {
uv_fs_t req; uv_fs_t req;
r = uv_fs_open(loop, &req, name, O_RDWR, 0, NULL); r = uv_fs_open(loop, &req, name, O_RDWR, 0, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
file = r; file = r;
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
r = uv_fs_write(loop, &req, file, "foo", 4, -1, NULL); r = uv_fs_write(loop, &req, file, "foo", 4, -1, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
r = uv_fs_close(loop, &req, file, NULL); r = uv_fs_close(loop, &req, file, NULL);
ASSERT(r != -1); ASSERT(r == 0);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
} }
@ -188,11 +188,11 @@ TEST_IMPL(fs_event_watch_dir) {
create_dir(loop, "watch_dir"); create_dir(loop, "watch_dir");
r = uv_fs_event_init(loop, &fs_event, "watch_dir", fs_event_cb_dir, 0); r = uv_fs_event_init(loop, &fs_event, "watch_dir", fs_event_cb_dir, 0);
ASSERT(r != -1); ASSERT(r == 0);
r = uv_timer_init(loop, &timer); r = uv_timer_init(loop, &timer);
ASSERT(r != -1); ASSERT(r == 0);
r = uv_timer_start(&timer, timer_cb_dir, 100, 0); r = uv_timer_start(&timer, timer_cb_dir, 100, 0);
ASSERT(r != -1); ASSERT(r == 0);
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
@ -222,11 +222,11 @@ TEST_IMPL(fs_event_watch_file) {
create_file(loop, "watch_dir/file2"); create_file(loop, "watch_dir/file2");
r = uv_fs_event_init(loop, &fs_event, "watch_dir/file2", fs_event_cb_file, 0); r = uv_fs_event_init(loop, &fs_event, "watch_dir/file2", fs_event_cb_file, 0);
ASSERT(r != -1); ASSERT(r == 0);
r = uv_timer_init(loop, &timer); r = uv_timer_init(loop, &timer);
ASSERT(r != -1); ASSERT(r == 0);
r = uv_timer_start(&timer, timer_cb_file, 100, 100); r = uv_timer_start(&timer, timer_cb_file, 100, 100);
ASSERT(r != -1); ASSERT(r == 0);
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
@ -275,7 +275,7 @@ TEST_IMPL(fs_event_watch_file_current_dir) {
r = uv_fs_event_init(loop, &fs_event, "watch_file", r = uv_fs_event_init(loop, &fs_event, "watch_file",
fs_event_cb_file_current_dir, 0); fs_event_cb_file_current_dir, 0);
ASSERT(r != -1); ASSERT(r == 0);
r = uv_timer_init(loop, &timer); r = uv_timer_init(loop, &timer);
ASSERT(r == 0); ASSERT(r == 0);
@ -315,7 +315,7 @@ TEST_IMPL(fs_event_no_callback_after_close) {
"watch_dir/file1", "watch_dir/file1",
fs_event_cb_file, fs_event_cb_file,
0); 0);
ASSERT(r != -1); ASSERT(r == 0);
uv_close((uv_handle_t*)&fs_event, close_cb); uv_close((uv_handle_t*)&fs_event, close_cb);
touch_file(loop, "watch_dir/file1"); touch_file(loop, "watch_dir/file1");
@ -347,7 +347,7 @@ TEST_IMPL(fs_event_no_callback_on_close) {
"watch_dir/file1", "watch_dir/file1",
fs_event_cb_file, fs_event_cb_file,
0); 0);
ASSERT(r != -1); ASSERT(r == 0);
uv_close((uv_handle_t*)&fs_event, close_cb); uv_close((uv_handle_t*)&fs_event, close_cb);

6
deps/uv/test/test-fs-poll.c

@ -87,8 +87,7 @@ static void poll_cb(uv_fs_poll_t* handle,
switch (poll_cb_called++) { switch (poll_cb_called++) {
case 0: case 0:
ASSERT(status == -1); ASSERT(status == UV_ENOENT);
ASSERT(uv_last_error(loop).code == UV_ENOENT);
ASSERT(0 == memcmp(prev, &zero_statbuf, sizeof(zero_statbuf))); ASSERT(0 == memcmp(prev, &zero_statbuf, sizeof(zero_statbuf)));
ASSERT(0 == memcmp(curr, &zero_statbuf, sizeof(zero_statbuf))); ASSERT(0 == memcmp(curr, &zero_statbuf, sizeof(zero_statbuf)));
touch_file(FIXTURE); touch_file(FIXTURE);
@ -116,10 +115,9 @@ static void poll_cb(uv_fs_poll_t* handle,
break; break;
case 4: case 4:
ASSERT(status == -1); ASSERT(status == UV_ENOENT);
ASSERT(0 != memcmp(prev, &zero_statbuf, sizeof(zero_statbuf))); ASSERT(0 != memcmp(prev, &zero_statbuf, sizeof(zero_statbuf)));
ASSERT(0 == memcmp(curr, &zero_statbuf, sizeof(zero_statbuf))); ASSERT(0 == memcmp(curr, &zero_statbuf, sizeof(zero_statbuf)));
ASSERT(uv_last_error(loop).code == UV_ENOENT);
uv_close((uv_handle_t*)handle, close_cb); uv_close((uv_handle_t*)handle, close_cb);
break; break;

341
deps/uv/test/test-fs.c

@ -196,9 +196,13 @@ static void chown_root_cb(uv_fs_t* req) {
/* On windows, chown is a no-op and always succeeds. */ /* On windows, chown is a no-op and always succeeds. */
ASSERT(req->result == 0); ASSERT(req->result == 0);
#else #else
/* On unix, chown'ing the root directory is not allowed. */ /* On unix, chown'ing the root directory is not allowed -
ASSERT(req->result == -1); * unless you're root, of course.
ASSERT(req->errorno == UV_EPERM); */
if (geteuid() == 0)
ASSERT(req->result == 0);
else
ASSERT(req->result == UV_EPERM);
#endif #endif
chown_cb_count++; chown_cb_count++;
uv_fs_req_cleanup(req); uv_fs_req_cleanup(req);
@ -207,7 +211,7 @@ static void chown_root_cb(uv_fs_t* req) {
static void unlink_cb(uv_fs_t* req) { static void unlink_cb(uv_fs_t* req) {
ASSERT(req == &unlink_req); ASSERT(req == &unlink_req);
ASSERT(req->fs_type == UV_FS_UNLINK); ASSERT(req->fs_type == UV_FS_UNLINK);
ASSERT(req->result != -1); ASSERT(req->result == 0);
unlink_cb_count++; unlink_cb_count++;
uv_fs_req_cleanup(req); uv_fs_req_cleanup(req);
} }
@ -226,7 +230,7 @@ static void close_cb(uv_fs_t* req) {
int r; int r;
ASSERT(req == &close_req); ASSERT(req == &close_req);
ASSERT(req->fs_type == UV_FS_CLOSE); ASSERT(req->fs_type == UV_FS_CLOSE);
ASSERT(req->result != -1); ASSERT(req->result == 0);
close_cb_count++; close_cb_count++;
uv_fs_req_cleanup(req); uv_fs_req_cleanup(req);
if (close_cb_count == 3) { if (close_cb_count == 3) {
@ -240,7 +244,7 @@ static void ftruncate_cb(uv_fs_t* req) {
int r; int r;
ASSERT(req == &ftruncate_req); ASSERT(req == &ftruncate_req);
ASSERT(req->fs_type == UV_FS_FTRUNCATE); ASSERT(req->fs_type == UV_FS_FTRUNCATE);
ASSERT(req->result != -1); ASSERT(req->result == 0);
ftruncate_cb_count++; ftruncate_cb_count++;
uv_fs_req_cleanup(req); uv_fs_req_cleanup(req);
r = uv_fs_close(loop, &close_req, open_req1.result, close_cb); r = uv_fs_close(loop, &close_req, open_req1.result, close_cb);
@ -252,7 +256,7 @@ static void read_cb(uv_fs_t* req) {
int r; int r;
ASSERT(req == &read_req); ASSERT(req == &read_req);
ASSERT(req->fs_type == UV_FS_READ); ASSERT(req->fs_type == UV_FS_READ);
ASSERT(req->result != -1); ASSERT(req->result >= 0); /* FIXME(bnoordhuis) Check if requested size? */
read_cb_count++; read_cb_count++;
uv_fs_req_cleanup(req); uv_fs_req_cleanup(req);
if (read_cb_count == 1) { if (read_cb_count == 1) {
@ -272,8 +276,7 @@ static void open_cb(uv_fs_t* req) {
ASSERT(req == &open_req1); ASSERT(req == &open_req1);
ASSERT(req->fs_type == UV_FS_OPEN); ASSERT(req->fs_type == UV_FS_OPEN);
if (req->result < 0) { if (req->result < 0) {
/* TODO get error with uv_last_error() */ fprintf(stderr, "async open error: %d\n", (int) req->result);
fprintf(stderr, "async open error: %d\n", req->errorno);
ASSERT(0); ASSERT(0);
} }
open_cb_count++; open_cb_count++;
@ -290,8 +293,7 @@ static void open_cb(uv_fs_t* req) {
static void open_cb_simple(uv_fs_t* req) { static void open_cb_simple(uv_fs_t* req) {
ASSERT(req->fs_type == UV_FS_OPEN); ASSERT(req->fs_type == UV_FS_OPEN);
if (req->result < 0) { if (req->result < 0) {
/* TODO get error with uv_last_error() */ fprintf(stderr, "async open error: %d\n", (int) req->result);
fprintf(stderr, "async open error: %d\n", req->errorno);
ASSERT(0); ASSERT(0);
} }
open_cb_count++; open_cb_count++;
@ -304,7 +306,7 @@ static void fsync_cb(uv_fs_t* req) {
int r; int r;
ASSERT(req == &fsync_req); ASSERT(req == &fsync_req);
ASSERT(req->fs_type == UV_FS_FSYNC); ASSERT(req->fs_type == UV_FS_FSYNC);
ASSERT(req->result != -1); ASSERT(req->result == 0);
fsync_cb_count++; fsync_cb_count++;
uv_fs_req_cleanup(req); uv_fs_req_cleanup(req);
r = uv_fs_close(loop, &close_req, open_req1.result, close_cb); r = uv_fs_close(loop, &close_req, open_req1.result, close_cb);
@ -316,7 +318,7 @@ static void fdatasync_cb(uv_fs_t* req) {
int r; int r;
ASSERT(req == &fdatasync_req); ASSERT(req == &fdatasync_req);
ASSERT(req->fs_type == UV_FS_FDATASYNC); ASSERT(req->fs_type == UV_FS_FDATASYNC);
ASSERT(req->result != -1); ASSERT(req->result == 0);
fdatasync_cb_count++; fdatasync_cb_count++;
uv_fs_req_cleanup(req); uv_fs_req_cleanup(req);
r = uv_fs_fsync(loop, &fsync_req, open_req1.result, fsync_cb); r = uv_fs_fsync(loop, &fsync_req, open_req1.result, fsync_cb);
@ -328,7 +330,7 @@ static void write_cb(uv_fs_t* req) {
int r; int r;
ASSERT(req == &write_req); ASSERT(req == &write_req);
ASSERT(req->fs_type == UV_FS_WRITE); ASSERT(req->fs_type == UV_FS_WRITE);
ASSERT(req->result != -1); ASSERT(req->result >= 0); /* FIXME(bnoordhuis) Check if requested size? */
write_cb_count++; write_cb_count++;
uv_fs_req_cleanup(req); uv_fs_req_cleanup(req);
r = uv_fs_fdatasync(loop, &fdatasync_req, open_req1.result, fdatasync_cb); r = uv_fs_fdatasync(loop, &fdatasync_req, open_req1.result, fdatasync_cb);
@ -340,7 +342,7 @@ static void create_cb(uv_fs_t* req) {
int r; int r;
ASSERT(req == &open_req1); ASSERT(req == &open_req1);
ASSERT(req->fs_type == UV_FS_OPEN); ASSERT(req->fs_type == UV_FS_OPEN);
ASSERT(req->result != -1); ASSERT(req->result >= 0);
create_cb_count++; create_cb_count++;
uv_fs_req_cleanup(req); uv_fs_req_cleanup(req);
r = uv_fs_write(loop, &write_req, req->result, test_buf, sizeof(test_buf), r = uv_fs_write(loop, &write_req, req->result, test_buf, sizeof(test_buf),
@ -352,7 +354,7 @@ static void create_cb(uv_fs_t* req) {
static void rename_cb(uv_fs_t* req) { static void rename_cb(uv_fs_t* req) {
ASSERT(req == &rename_req); ASSERT(req == &rename_req);
ASSERT(req->fs_type == UV_FS_RENAME); ASSERT(req->fs_type == UV_FS_RENAME);
ASSERT(req->result != -1); ASSERT(req->result == 0);
rename_cb_count++; rename_cb_count++;
uv_fs_req_cleanup(req); uv_fs_req_cleanup(req);
} }
@ -361,7 +363,7 @@ static void rename_cb(uv_fs_t* req) {
static void mkdir_cb(uv_fs_t* req) { static void mkdir_cb(uv_fs_t* req) {
ASSERT(req == &mkdir_req); ASSERT(req == &mkdir_req);
ASSERT(req->fs_type == UV_FS_MKDIR); ASSERT(req->fs_type == UV_FS_MKDIR);
ASSERT(req->result != -1); ASSERT(req->result == 0);
mkdir_cb_count++; mkdir_cb_count++;
ASSERT(req->path); ASSERT(req->path);
ASSERT(memcmp(req->path, "test_dir\0", 9) == 0); ASSERT(memcmp(req->path, "test_dir\0", 9) == 0);
@ -372,7 +374,7 @@ static void mkdir_cb(uv_fs_t* req) {
static void rmdir_cb(uv_fs_t* req) { static void rmdir_cb(uv_fs_t* req) {
ASSERT(req == &rmdir_req); ASSERT(req == &rmdir_req);
ASSERT(req->fs_type == UV_FS_RMDIR); ASSERT(req->fs_type == UV_FS_RMDIR);
ASSERT(req->result != -1); ASSERT(req->result == 0);
rmdir_cb_count++; rmdir_cb_count++;
ASSERT(req->path); ASSERT(req->path);
ASSERT(memcmp(req->path, "test_dir\0", 9) == 0); ASSERT(memcmp(req->path, "test_dir\0", 9) == 0);
@ -408,9 +410,8 @@ static void empty_readdir_cb(uv_fs_t* req) {
static void file_readdir_cb(uv_fs_t* req) { static void file_readdir_cb(uv_fs_t* req) {
ASSERT(req == &readdir_req); ASSERT(req == &readdir_req);
ASSERT(req->fs_type == UV_FS_READDIR); ASSERT(req->fs_type == UV_FS_READDIR);
ASSERT(req->result == -1); ASSERT(req->result == UV_ENOTDIR);
ASSERT(req->ptr == NULL); ASSERT(req->ptr == NULL);
ASSERT(uv_last_error(req->loop).code == UV_ENOTDIR);
uv_fs_req_cleanup(req); uv_fs_req_cleanup(req);
readdir_cb_count++; readdir_cb_count++;
} }
@ -419,7 +420,7 @@ static void file_readdir_cb(uv_fs_t* req) {
static void stat_cb(uv_fs_t* req) { static void stat_cb(uv_fs_t* req) {
ASSERT(req == &stat_req); ASSERT(req == &stat_req);
ASSERT(req->fs_type == UV_FS_STAT || req->fs_type == UV_FS_LSTAT); ASSERT(req->fs_type == UV_FS_STAT || req->fs_type == UV_FS_LSTAT);
ASSERT(req->result != -1); ASSERT(req->result == 0);
ASSERT(req->ptr); ASSERT(req->ptr);
stat_cb_count++; stat_cb_count++;
uv_fs_req_cleanup(req); uv_fs_req_cleanup(req);
@ -438,24 +439,21 @@ static void sendfile_cb(uv_fs_t* req) {
static void open_noent_cb(uv_fs_t* req) { static void open_noent_cb(uv_fs_t* req) {
ASSERT(req->fs_type == UV_FS_OPEN); ASSERT(req->fs_type == UV_FS_OPEN);
ASSERT(req->errorno == UV_ENOENT); ASSERT(req->result == UV_ENOENT);
ASSERT(req->result == -1);
open_cb_count++; open_cb_count++;
uv_fs_req_cleanup(req); uv_fs_req_cleanup(req);
} }
static void open_nametoolong_cb(uv_fs_t* req) { static void open_nametoolong_cb(uv_fs_t* req) {
ASSERT(req->fs_type == UV_FS_OPEN); ASSERT(req->fs_type == UV_FS_OPEN);
ASSERT(req->errorno == UV_ENAMETOOLONG); ASSERT(req->result == UV_ENAMETOOLONG);
ASSERT(req->result == -1);
open_cb_count++; open_cb_count++;
uv_fs_req_cleanup(req); uv_fs_req_cleanup(req);
} }
static void open_loop_cb(uv_fs_t* req) { static void open_loop_cb(uv_fs_t* req) {
ASSERT(req->fs_type == UV_FS_OPEN); ASSERT(req->fs_type == UV_FS_OPEN);
ASSERT(req->errorno == UV_ELOOP); ASSERT(req->result == UV_ELOOP);
ASSERT(req->result == -1);
open_cb_count++; open_cb_count++;
uv_fs_req_cleanup(req); uv_fs_req_cleanup(req);
} }
@ -468,9 +466,8 @@ TEST_IMPL(fs_file_noent) {
loop = uv_default_loop(); loop = uv_default_loop();
r = uv_fs_open(loop, &req, "does_not_exist", O_RDONLY, 0, NULL); r = uv_fs_open(loop, &req, "does_not_exist", O_RDONLY, 0, NULL);
ASSERT(r == -1); ASSERT(r == UV_ENOENT);
ASSERT(req.result == -1); ASSERT(req.result == UV_ENOENT);
ASSERT(uv_last_error(loop).code == UV_ENOENT);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
r = uv_fs_open(loop, &req, "does_not_exist", O_RDONLY, 0, open_noent_cb); r = uv_fs_open(loop, &req, "does_not_exist", O_RDONLY, 0, open_noent_cb);
@ -497,9 +494,8 @@ TEST_IMPL(fs_file_nametoolong) {
name[TOO_LONG_NAME_LENGTH] = 0; name[TOO_LONG_NAME_LENGTH] = 0;
r = uv_fs_open(loop, &req, name, O_RDONLY, 0, NULL); r = uv_fs_open(loop, &req, name, O_RDONLY, 0, NULL);
ASSERT(r == -1); ASSERT(r == UV_ENAMETOOLONG);
ASSERT(req.result == -1); ASSERT(req.result == UV_ENAMETOOLONG);
ASSERT(uv_last_error(loop).code == UV_ENAMETOOLONG);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
r = uv_fs_open(loop, &req, name, O_RDONLY, 0, open_nametoolong_cb); r = uv_fs_open(loop, &req, name, O_RDONLY, 0, open_nametoolong_cb);
@ -524,9 +520,8 @@ TEST_IMPL(fs_file_loop) {
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
r = uv_fs_open(loop, &req, "test_symlink", O_RDONLY, 0, NULL); r = uv_fs_open(loop, &req, "test_symlink", O_RDONLY, 0, NULL);
ASSERT(r == -1); ASSERT(r == UV_ELOOP);
ASSERT(req.result == -1); ASSERT(req.result == UV_ELOOP);
ASSERT(uv_last_error(loop).code == UV_ELOOP);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
r = uv_fs_open(loop, &req, "test_symlink", O_RDONLY, 0, open_loop_cb); r = uv_fs_open(loop, &req, "test_symlink", O_RDONLY, 0, open_loop_cb);
@ -664,69 +659,69 @@ TEST_IMPL(fs_file_sync) {
r = uv_fs_open(loop, &open_req1, "test_file", O_WRONLY | O_CREAT, r = uv_fs_open(loop, &open_req1, "test_file", O_WRONLY | O_CREAT,
S_IWUSR | S_IRUSR, NULL); S_IWUSR | S_IRUSR, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(open_req1.result != -1); ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1); uv_fs_req_cleanup(&open_req1);
r = uv_fs_write(loop, &write_req, open_req1.result, test_buf, r = uv_fs_write(loop, &write_req, open_req1.result, test_buf,
sizeof(test_buf), -1, NULL); sizeof(test_buf), -1, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(write_req.result != -1); ASSERT(write_req.result >= 0);
uv_fs_req_cleanup(&write_req); uv_fs_req_cleanup(&write_req);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL); r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
ASSERT(r != -1); ASSERT(r == 0);
ASSERT(close_req.result != -1); ASSERT(close_req.result == 0);
uv_fs_req_cleanup(&close_req); uv_fs_req_cleanup(&close_req);
r = uv_fs_open(loop, &open_req1, "test_file", O_RDWR, 0, NULL); r = uv_fs_open(loop, &open_req1, "test_file", O_RDWR, 0, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(open_req1.result != -1); ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1); uv_fs_req_cleanup(&open_req1);
r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1, r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1,
NULL); NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(read_req.result != -1); ASSERT(read_req.result >= 0);
ASSERT(strcmp(buf, test_buf) == 0); ASSERT(strcmp(buf, test_buf) == 0);
uv_fs_req_cleanup(&read_req); uv_fs_req_cleanup(&read_req);
r = uv_fs_ftruncate(loop, &ftruncate_req, open_req1.result, 7, NULL); r = uv_fs_ftruncate(loop, &ftruncate_req, open_req1.result, 7, NULL);
ASSERT(r != -1); ASSERT(r == 0);
ASSERT(ftruncate_req.result != -1); ASSERT(ftruncate_req.result == 0);
uv_fs_req_cleanup(&ftruncate_req); uv_fs_req_cleanup(&ftruncate_req);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL); r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
ASSERT(r != -1); ASSERT(r == 0);
ASSERT(close_req.result != -1); ASSERT(close_req.result == 0);
uv_fs_req_cleanup(&close_req); uv_fs_req_cleanup(&close_req);
r = uv_fs_rename(loop, &rename_req, "test_file", "test_file2", NULL); r = uv_fs_rename(loop, &rename_req, "test_file", "test_file2", NULL);
ASSERT(r != -1); ASSERT(r == 0);
ASSERT(rename_req.result != -1); ASSERT(rename_req.result == 0);
uv_fs_req_cleanup(&rename_req); uv_fs_req_cleanup(&rename_req);
r = uv_fs_open(loop, &open_req1, "test_file2", O_RDONLY, 0, NULL); r = uv_fs_open(loop, &open_req1, "test_file2", O_RDONLY, 0, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(open_req1.result != -1); ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1); uv_fs_req_cleanup(&open_req1);
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1, r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1,
NULL); NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(read_req.result != -1); ASSERT(read_req.result >= 0);
ASSERT(strcmp(buf, "test-bu") == 0); ASSERT(strcmp(buf, "test-bu") == 0);
uv_fs_req_cleanup(&read_req); uv_fs_req_cleanup(&read_req);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL); r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
ASSERT(r != -1); ASSERT(r == 0);
ASSERT(close_req.result != -1); ASSERT(close_req.result == 0);
uv_fs_req_cleanup(&close_req); uv_fs_req_cleanup(&close_req);
r = uv_fs_unlink(loop, &unlink_req, "test_file2", NULL); r = uv_fs_unlink(loop, &unlink_req, "test_file2", NULL);
ASSERT(r != -1); ASSERT(r == 0);
ASSERT(unlink_req.result != -1); ASSERT(unlink_req.result == 0);
uv_fs_req_cleanup(&unlink_req); uv_fs_req_cleanup(&unlink_req);
/* Cleanup */ /* Cleanup */
@ -757,7 +752,7 @@ TEST_IMPL(fs_async_dir) {
/* Create 2 files synchronously. */ /* Create 2 files synchronously. */
r = uv_fs_open(loop, &open_req1, "test_dir/file1", O_WRONLY | O_CREAT, r = uv_fs_open(loop, &open_req1, "test_dir/file1", O_WRONLY | O_CREAT,
S_IWUSR | S_IRUSR, NULL); S_IWUSR | S_IRUSR, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
uv_fs_req_cleanup(&open_req1); uv_fs_req_cleanup(&open_req1);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL); r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
ASSERT(r == 0); ASSERT(r == 0);
@ -765,7 +760,7 @@ TEST_IMPL(fs_async_dir) {
r = uv_fs_open(loop, &open_req1, "test_dir/file2", O_WRONLY | O_CREAT, r = uv_fs_open(loop, &open_req1, "test_dir/file2", O_WRONLY | O_CREAT,
S_IWUSR | S_IRUSR, NULL); S_IWUSR | S_IRUSR, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
uv_fs_req_cleanup(&open_req1); uv_fs_req_cleanup(&open_req1);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL); r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
ASSERT(r == 0); ASSERT(r == 0);
@ -857,14 +852,14 @@ TEST_IMPL(fs_async_sendfile) {
/* Test starts here. */ /* Test starts here. */
r = uv_fs_open(loop, &open_req1, "test_file", O_RDWR, 0, NULL); r = uv_fs_open(loop, &open_req1, "test_file", O_RDWR, 0, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(open_req1.result != -1); ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1); uv_fs_req_cleanup(&open_req1);
r = uv_fs_open(loop, &open_req2, "test_file2", O_WRONLY | O_CREAT, r = uv_fs_open(loop, &open_req2, "test_file2", O_WRONLY | O_CREAT,
S_IWUSR | S_IRUSR, NULL); S_IWUSR | S_IRUSR, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(open_req2.result != -1); ASSERT(open_req2.result >= 0);
uv_fs_req_cleanup(&open_req2); uv_fs_req_cleanup(&open_req2);
r = uv_fs_sendfile(loop, &sendfile_req, open_req2.result, open_req1.result, r = uv_fs_sendfile(loop, &sendfile_req, open_req2.result, open_req1.result,
@ -910,8 +905,8 @@ TEST_IMPL(fs_fstat) {
r = uv_fs_open(loop, &req, "test_file", O_RDWR | O_CREAT, r = uv_fs_open(loop, &req, "test_file", O_RDWR | O_CREAT,
S_IWUSR | S_IRUSR, NULL); S_IWUSR | S_IRUSR, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(req.result != -1); ASSERT(req.result >= 0);
file = req.result; file = req.result;
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
@ -947,13 +942,29 @@ TEST_IMPL(fs_fstat) {
ASSERT(s->st_mtim.tv_nsec == t.st_mtimespec.tv_nsec); ASSERT(s->st_mtim.tv_nsec == t.st_mtimespec.tv_nsec);
ASSERT(s->st_ctim.tv_sec == t.st_ctimespec.tv_sec); ASSERT(s->st_ctim.tv_sec == t.st_ctimespec.tv_sec);
ASSERT(s->st_ctim.tv_nsec == t.st_ctimespec.tv_nsec); ASSERT(s->st_ctim.tv_nsec == t.st_ctimespec.tv_nsec);
#elif defined(_BSD_SOURCE) || defined(_SVID_SOURCE) || defined(_XOPEN_SOURCE) ASSERT(s->st_birthtim.tv_sec == t.st_birthtimespec.tv_sec);
ASSERT(s->st_birthtim.tv_nsec == t.st_birthtimespec.tv_nsec);
ASSERT(s->st_flags == t.st_flags);
ASSERT(s->st_gen == t.st_gen);
#elif defined(__sun) || \
defined(_BSD_SOURCE) || \
defined(_SVID_SOURCE) || \
defined(_XOPEN_SOURCE)
ASSERT(s->st_atim.tv_sec == t.st_atim.tv_sec); ASSERT(s->st_atim.tv_sec == t.st_atim.tv_sec);
ASSERT(s->st_atim.tv_nsec == t.st_atim.tv_nsec); ASSERT(s->st_atim.tv_nsec == t.st_atim.tv_nsec);
ASSERT(s->st_mtim.tv_sec == t.st_mtim.tv_sec); ASSERT(s->st_mtim.tv_sec == t.st_mtim.tv_sec);
ASSERT(s->st_mtim.tv_nsec == t.st_mtim.tv_nsec); ASSERT(s->st_mtim.tv_nsec == t.st_mtim.tv_nsec);
ASSERT(s->st_ctim.tv_sec == t.st_ctim.tv_sec); ASSERT(s->st_ctim.tv_sec == t.st_ctim.tv_sec);
ASSERT(s->st_ctim.tv_nsec == t.st_ctim.tv_nsec); ASSERT(s->st_ctim.tv_nsec == t.st_ctim.tv_nsec);
# if defined(__DragonFly__) || \
defined(__FreeBSD__) || \
defined(__OpenBSD__) || \
defined(__NetBSD__)
ASSERT(s->st_birthtim.tv_sec == t.st_birthtim.tv_sec);
ASSERT(s->st_birthtim.tv_nsec == t.st_birthtim.tv_nsec);
ASSERT(s->st_flags == t.st_flags);
ASSERT(s->st_gen == t.st_gen);
# endif
#else #else
ASSERT(s->st_atim.tv_sec == t.st_atime); ASSERT(s->st_atim.tv_sec == t.st_atime);
ASSERT(s->st_atim.tv_nsec == 0); ASSERT(s->st_atim.tv_nsec == 0);
@ -1004,8 +1015,8 @@ TEST_IMPL(fs_chmod) {
r = uv_fs_open(loop, &req, "test_file", O_RDWR | O_CREAT, r = uv_fs_open(loop, &req, "test_file", O_RDWR | O_CREAT,
S_IWUSR | S_IRUSR, NULL); S_IWUSR | S_IRUSR, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(req.result != -1); ASSERT(req.result >= 0);
file = req.result; file = req.result;
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
@ -1101,8 +1112,8 @@ TEST_IMPL(fs_chown) {
r = uv_fs_open(loop, &req, "test_file", O_RDWR | O_CREAT, r = uv_fs_open(loop, &req, "test_file", O_RDWR | O_CREAT,
S_IWUSR | S_IRUSR, NULL); S_IWUSR | S_IRUSR, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(req.result != -1); ASSERT(req.result >= 0);
file = req.result; file = req.result;
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
@ -1167,8 +1178,8 @@ TEST_IMPL(fs_link) {
r = uv_fs_open(loop, &req, "test_file", O_RDWR | O_CREAT, r = uv_fs_open(loop, &req, "test_file", O_RDWR | O_CREAT,
S_IWUSR | S_IRUSR, NULL); S_IWUSR | S_IRUSR, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(req.result != -1); ASSERT(req.result >= 0);
file = req.result; file = req.result;
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
@ -1186,15 +1197,15 @@ TEST_IMPL(fs_link) {
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
r = uv_fs_open(loop, &req, "test_file_link", O_RDWR, 0, NULL); r = uv_fs_open(loop, &req, "test_file_link", O_RDWR, 0, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(req.result != -1); ASSERT(req.result >= 0);
link = req.result; link = req.result;
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
r = uv_fs_read(loop, &req, link, buf, sizeof(buf), 0, NULL); r = uv_fs_read(loop, &req, link, buf, sizeof(buf), 0, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(req.result != -1); ASSERT(req.result >= 0);
ASSERT(strcmp(buf, test_buf) == 0); ASSERT(strcmp(buf, test_buf) == 0);
close(link); close(link);
@ -1206,15 +1217,15 @@ TEST_IMPL(fs_link) {
ASSERT(link_cb_count == 1); ASSERT(link_cb_count == 1);
r = uv_fs_open(loop, &req, "test_file_link2", O_RDWR, 0, NULL); r = uv_fs_open(loop, &req, "test_file_link2", O_RDWR, 0, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(req.result != -1); ASSERT(req.result >= 0);
link = req.result; link = req.result;
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
r = uv_fs_read(loop, &req, link, buf, sizeof(buf), 0, NULL); r = uv_fs_read(loop, &req, link, buf, sizeof(buf), 0, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(req.result != -1); ASSERT(req.result >= 0);
ASSERT(strcmp(buf, test_buf) == 0); ASSERT(strcmp(buf, test_buf) == 0);
close(link); close(link);
@ -1243,14 +1254,12 @@ TEST_IMPL(fs_readlink) {
ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT)); ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT));
ASSERT(dummy_cb_count == 1); ASSERT(dummy_cb_count == 1);
ASSERT(req.ptr == NULL); ASSERT(req.ptr == NULL);
ASSERT(req.result == -1); ASSERT(req.result == UV_ENOENT);
ASSERT(req.errorno == UV_ENOENT);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
ASSERT(-1 == uv_fs_readlink(loop, &req, "no_such_file", NULL)); ASSERT(UV_ENOENT == uv_fs_readlink(loop, &req, "no_such_file", NULL));
ASSERT(req.ptr == NULL); ASSERT(req.ptr == NULL);
ASSERT(req.result == -1); ASSERT(req.result == UV_ENOENT);
ASSERT(req.errorno == UV_ENOENT);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
MAKE_VALGRIND_HAPPY(); MAKE_VALGRIND_HAPPY();
@ -1275,8 +1284,8 @@ TEST_IMPL(fs_symlink) {
r = uv_fs_open(loop, &req, "test_file", O_RDWR | O_CREAT, r = uv_fs_open(loop, &req, "test_file", O_RDWR | O_CREAT,
S_IWUSR | S_IRUSR, NULL); S_IWUSR | S_IRUSR, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(req.result != -1); ASSERT(req.result >= 0);
file = req.result; file = req.result;
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
@ -1290,14 +1299,14 @@ TEST_IMPL(fs_symlink) {
/* sync symlink */ /* sync symlink */
r = uv_fs_symlink(loop, &req, "test_file", "test_file_symlink", 0, NULL); r = uv_fs_symlink(loop, &req, "test_file", "test_file_symlink", 0, NULL);
#ifdef _WIN32 #ifdef _WIN32
if (r == -1) { if (r < 0) {
if (uv_last_error(loop).code == UV_ENOTSUP) { if (r == UV_ENOTSUP) {
/* /*
* Windows doesn't support symlinks on older versions. * Windows doesn't support symlinks on older versions.
* We just pass the test and bail out early if we get ENOTSUP. * We just pass the test and bail out early if we get ENOTSUP.
*/ */
return 0; return 0;
} else if (uv_last_error(loop).code == UV_EPERM) { } else if (r == UV_EPERM) {
/* /*
* Creating a symlink is only allowed when running elevated. * Creating a symlink is only allowed when running elevated.
* We pass the test and bail out early if we get UV_EPERM. * We pass the test and bail out early if we get UV_EPERM.
@ -1311,25 +1320,25 @@ TEST_IMPL(fs_symlink) {
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
r = uv_fs_open(loop, &req, "test_file_symlink", O_RDWR, 0, NULL); r = uv_fs_open(loop, &req, "test_file_symlink", O_RDWR, 0, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(req.result != -1); ASSERT(req.result >= 0);
link = req.result; link = req.result;
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
r = uv_fs_read(loop, &req, link, buf, sizeof(buf), 0, NULL); r = uv_fs_read(loop, &req, link, buf, sizeof(buf), 0, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(req.result != -1); ASSERT(req.result >= 0);
ASSERT(strcmp(buf, test_buf) == 0); ASSERT(strcmp(buf, test_buf) == 0);
close(link); close(link);
r = uv_fs_symlink(loop, &req, "test_file_symlink", "test_file_symlink_symlink", 0, NULL); r = uv_fs_symlink(loop, &req, "test_file_symlink", "test_file_symlink_symlink", 0, NULL);
ASSERT(r != -1); ASSERT(r == 0);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
r = uv_fs_readlink(loop, &req, "test_file_symlink_symlink", NULL); r = uv_fs_readlink(loop, &req, "test_file_symlink_symlink", NULL);
ASSERT(r != -1); ASSERT(r == 0);
ASSERT(strcmp(req.ptr, "test_file_symlink") == 0); ASSERT(strcmp(req.ptr, "test_file_symlink") == 0);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
@ -1340,25 +1349,25 @@ TEST_IMPL(fs_symlink) {
ASSERT(symlink_cb_count == 1); ASSERT(symlink_cb_count == 1);
r = uv_fs_open(loop, &req, "test_file_symlink2", O_RDWR, 0, NULL); r = uv_fs_open(loop, &req, "test_file_symlink2", O_RDWR, 0, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(req.result != -1); ASSERT(req.result >= 0);
link = req.result; link = req.result;
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
r = uv_fs_read(loop, &req, link, buf, sizeof(buf), 0, NULL); r = uv_fs_read(loop, &req, link, buf, sizeof(buf), 0, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(req.result != -1); ASSERT(req.result >= 0);
ASSERT(strcmp(buf, test_buf) == 0); ASSERT(strcmp(buf, test_buf) == 0);
close(link); close(link);
r = uv_fs_symlink(loop, &req, "test_file_symlink2", "test_file_symlink2_symlink", 0, NULL); r = uv_fs_symlink(loop, &req, "test_file_symlink2", "test_file_symlink2_symlink", 0, NULL);
ASSERT(r != -1); ASSERT(r == 0);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
r = uv_fs_readlink(loop, &req, "test_file_symlink2_symlink", readlink_cb); r = uv_fs_readlink(loop, &req, "test_file_symlink2_symlink", readlink_cb);
ASSERT(r != -1); ASSERT(r == 0);
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
ASSERT(readlink_cb_count == 1); ASSERT(readlink_cb_count == 1);
@ -1440,7 +1449,7 @@ TEST_IMPL(fs_symlink_dir) {
r = uv_fs_open(loop, &open_req1, "test_dir/file1", O_WRONLY | O_CREAT, r = uv_fs_open(loop, &open_req1, "test_dir/file1", O_WRONLY | O_CREAT,
S_IWUSR | S_IRUSR, NULL); S_IWUSR | S_IRUSR, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
uv_fs_req_cleanup(&open_req1); uv_fs_req_cleanup(&open_req1);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL); r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
ASSERT(r == 0); ASSERT(r == 0);
@ -1448,7 +1457,7 @@ TEST_IMPL(fs_symlink_dir) {
r = uv_fs_open(loop, &open_req1, "test_dir/file2", O_WRONLY | O_CREAT, r = uv_fs_open(loop, &open_req1, "test_dir/file2", O_WRONLY | O_CREAT,
S_IWUSR | S_IRUSR, NULL); S_IWUSR | S_IRUSR, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
uv_fs_req_cleanup(&open_req1); uv_fs_req_cleanup(&open_req1);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL); r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
ASSERT(r == 0); ASSERT(r == 0);
@ -1469,7 +1478,7 @@ TEST_IMPL(fs_symlink_dir) {
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
r = uv_fs_readdir(loop, &readdir_req, "test_dir_symlink", 0, NULL); r = uv_fs_readdir(loop, &readdir_req, "test_dir_symlink", 0, NULL);
ASSERT(r == -1); ASSERT(r == UV_ENOENT);
uv_fs_req_cleanup(&readdir_req); uv_fs_req_cleanup(&readdir_req);
r = uv_fs_readdir(loop, &readdir_req, "test_dir", 0, NULL); r = uv_fs_readdir(loop, &readdir_req, "test_dir", 0, NULL);
@ -1505,8 +1514,8 @@ TEST_IMPL(fs_utime) {
unlink(path); unlink(path);
r = uv_fs_open(loop, &req, path, O_RDWR | O_CREAT, r = uv_fs_open(loop, &req, path, O_RDWR | O_CREAT,
S_IWUSR | S_IRUSR, NULL); S_IWUSR | S_IRUSR, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(req.result != -1); ASSERT(req.result >= 0);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
close(r); close(r);
@ -1590,16 +1599,16 @@ TEST_IMPL(fs_futime) {
unlink(path); unlink(path);
r = uv_fs_open(loop, &req, path, O_RDWR | O_CREAT, r = uv_fs_open(loop, &req, path, O_RDWR | O_CREAT,
S_IWUSR | S_IRUSR, NULL); S_IWUSR | S_IRUSR, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(req.result != -1); ASSERT(req.result >= 0);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
close(r); close(r);
atime = mtime = 400497753; /* 1982-09-10 11:22:33 */ atime = mtime = 400497753; /* 1982-09-10 11:22:33 */
r = uv_fs_open(loop, &req, path, O_RDWR, 0, NULL); r = uv_fs_open(loop, &req, path, O_RDWR, 0, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(req.result != -1); ASSERT(req.result >= 0);
file = req.result; /* FIXME probably not how it's supposed to be used */ file = req.result; /* FIXME probably not how it's supposed to be used */
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
@ -1642,9 +1651,8 @@ TEST_IMPL(fs_stat_missing_path) {
loop = uv_default_loop(); loop = uv_default_loop();
r = uv_fs_stat(loop, &req, "non_existent_file", NULL); r = uv_fs_stat(loop, &req, "non_existent_file", NULL);
ASSERT(r == -1); ASSERT(r == UV_ENOENT);
ASSERT(req.result == -1); ASSERT(req.result == UV_ENOENT);
ASSERT(uv_last_error(loop).code == UV_ENOENT);
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
MAKE_VALGRIND_HAPPY(); MAKE_VALGRIND_HAPPY();
@ -1692,8 +1700,7 @@ TEST_IMPL(fs_readdir_file) {
loop = uv_default_loop(); loop = uv_default_loop();
r = uv_fs_readdir(loop, &readdir_req, path, 0, NULL); r = uv_fs_readdir(loop, &readdir_req, path, 0, NULL);
ASSERT(r == -1); ASSERT(r == UV_ENOTDIR);
ASSERT(uv_last_error(loop).code == UV_ENOTDIR);
uv_fs_req_cleanup(&readdir_req); uv_fs_req_cleanup(&readdir_req);
r = uv_fs_readdir(loop, &readdir_req, path, 0, file_readdir_cb); r = uv_fs_readdir(loop, &readdir_req, path, 0, file_readdir_cb);
@ -1717,8 +1724,8 @@ TEST_IMPL(fs_open_dir) {
loop = uv_default_loop(); loop = uv_default_loop();
r = uv_fs_open(loop, &req, path, O_RDONLY, 0, NULL); r = uv_fs_open(loop, &req, path, O_RDONLY, 0, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(req.result != -1); ASSERT(req.result >= 0);
ASSERT(req.ptr == NULL); ASSERT(req.ptr == NULL);
file = r; file = r;
uv_fs_req_cleanup(&req); uv_fs_req_cleanup(&req);
@ -1748,40 +1755,40 @@ TEST_IMPL(fs_file_open_append) {
r = uv_fs_open(loop, &open_req1, "test_file", O_WRONLY | O_CREAT, r = uv_fs_open(loop, &open_req1, "test_file", O_WRONLY | O_CREAT,
S_IWUSR | S_IRUSR, NULL); S_IWUSR | S_IRUSR, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(open_req1.result != -1); ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1); uv_fs_req_cleanup(&open_req1);
r = uv_fs_write(loop, &write_req, open_req1.result, test_buf, r = uv_fs_write(loop, &write_req, open_req1.result, test_buf,
sizeof(test_buf), -1, NULL); sizeof(test_buf), -1, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(write_req.result != -1); ASSERT(write_req.result >= 0);
uv_fs_req_cleanup(&write_req); uv_fs_req_cleanup(&write_req);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL); r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
ASSERT(r != -1); ASSERT(r == 0);
ASSERT(close_req.result != -1); ASSERT(close_req.result == 0);
uv_fs_req_cleanup(&close_req); uv_fs_req_cleanup(&close_req);
r = uv_fs_open(loop, &open_req1, "test_file", O_RDWR | O_APPEND, 0, NULL); r = uv_fs_open(loop, &open_req1, "test_file", O_RDWR | O_APPEND, 0, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(open_req1.result != -1); ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1); uv_fs_req_cleanup(&open_req1);
r = uv_fs_write(loop, &write_req, open_req1.result, test_buf, r = uv_fs_write(loop, &write_req, open_req1.result, test_buf,
sizeof(test_buf), -1, NULL); sizeof(test_buf), -1, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(write_req.result != -1); ASSERT(write_req.result >= 0);
uv_fs_req_cleanup(&write_req); uv_fs_req_cleanup(&write_req);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL); r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
ASSERT(r != -1); ASSERT(r == 0);
ASSERT(close_req.result != -1); ASSERT(close_req.result == 0);
uv_fs_req_cleanup(&close_req); uv_fs_req_cleanup(&close_req);
r = uv_fs_open(loop, &open_req1, "test_file", O_RDONLY, S_IRUSR, NULL); r = uv_fs_open(loop, &open_req1, "test_file", O_RDONLY, S_IRUSR, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(open_req1.result != -1); ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1); uv_fs_req_cleanup(&open_req1);
r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1, r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1,
@ -1795,8 +1802,8 @@ TEST_IMPL(fs_file_open_append) {
uv_fs_req_cleanup(&read_req); uv_fs_req_cleanup(&read_req);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL); r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
ASSERT(r != -1); ASSERT(r == 0);
ASSERT(close_req.result != -1); ASSERT(close_req.result == 0);
uv_fs_req_cleanup(&close_req); uv_fs_req_cleanup(&close_req);
/* Cleanup */ /* Cleanup */
@ -1818,53 +1825,53 @@ TEST_IMPL(fs_rename_to_existing_file) {
r = uv_fs_open(loop, &open_req1, "test_file", O_WRONLY | O_CREAT, r = uv_fs_open(loop, &open_req1, "test_file", O_WRONLY | O_CREAT,
S_IWUSR | S_IRUSR, NULL); S_IWUSR | S_IRUSR, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(open_req1.result != -1); ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1); uv_fs_req_cleanup(&open_req1);
r = uv_fs_write(loop, &write_req, open_req1.result, test_buf, r = uv_fs_write(loop, &write_req, open_req1.result, test_buf,
sizeof(test_buf), -1, NULL); sizeof(test_buf), -1, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(write_req.result != -1); ASSERT(write_req.result >= 0);
uv_fs_req_cleanup(&write_req); uv_fs_req_cleanup(&write_req);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL); r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
ASSERT(r != -1); ASSERT(r == 0);
ASSERT(close_req.result != -1); ASSERT(close_req.result == 0);
uv_fs_req_cleanup(&close_req); uv_fs_req_cleanup(&close_req);
r = uv_fs_open(loop, &open_req1, "test_file2", O_WRONLY | O_CREAT, r = uv_fs_open(loop, &open_req1, "test_file2", O_WRONLY | O_CREAT,
S_IWUSR | S_IRUSR, NULL); S_IWUSR | S_IRUSR, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(open_req1.result != -1); ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1); uv_fs_req_cleanup(&open_req1);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL); r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
ASSERT(r != -1); ASSERT(r == 0);
ASSERT(close_req.result != -1); ASSERT(close_req.result == 0);
uv_fs_req_cleanup(&close_req); uv_fs_req_cleanup(&close_req);
r = uv_fs_rename(loop, &rename_req, "test_file", "test_file2", NULL); r = uv_fs_rename(loop, &rename_req, "test_file", "test_file2", NULL);
ASSERT(r != -1); ASSERT(r == 0);
ASSERT(rename_req.result != -1); ASSERT(rename_req.result == 0);
uv_fs_req_cleanup(&rename_req); uv_fs_req_cleanup(&rename_req);
r = uv_fs_open(loop, &open_req1, "test_file2", O_RDONLY, 0, NULL); r = uv_fs_open(loop, &open_req1, "test_file2", O_RDONLY, 0, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(open_req1.result != -1); ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1); uv_fs_req_cleanup(&open_req1);
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1, r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1,
NULL); NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(read_req.result != -1); ASSERT(read_req.result >= 0);
ASSERT(strcmp(buf, test_buf) == 0); ASSERT(strcmp(buf, test_buf) == 0);
uv_fs_req_cleanup(&read_req); uv_fs_req_cleanup(&read_req);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL); r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
ASSERT(r != -1); ASSERT(r == 0);
ASSERT(close_req.result != -1); ASSERT(close_req.result == 0);
uv_fs_req_cleanup(&close_req); uv_fs_req_cleanup(&close_req);
/* Cleanup */ /* Cleanup */
@ -1886,31 +1893,31 @@ TEST_IMPL(fs_read_file_eof) {
r = uv_fs_open(loop, &open_req1, "test_file", O_WRONLY | O_CREAT, r = uv_fs_open(loop, &open_req1, "test_file", O_WRONLY | O_CREAT,
S_IWUSR | S_IRUSR, NULL); S_IWUSR | S_IRUSR, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(open_req1.result != -1); ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1); uv_fs_req_cleanup(&open_req1);
r = uv_fs_write(loop, &write_req, open_req1.result, test_buf, r = uv_fs_write(loop, &write_req, open_req1.result, test_buf,
sizeof(test_buf), -1, NULL); sizeof(test_buf), -1, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(write_req.result != -1); ASSERT(write_req.result >= 0);
uv_fs_req_cleanup(&write_req); uv_fs_req_cleanup(&write_req);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL); r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
ASSERT(r != -1); ASSERT(r == 0);
ASSERT(close_req.result != -1); ASSERT(close_req.result == 0);
uv_fs_req_cleanup(&close_req); uv_fs_req_cleanup(&close_req);
r = uv_fs_open(loop, &open_req1, "test_file", O_RDONLY, 0, NULL); r = uv_fs_open(loop, &open_req1, "test_file", O_RDONLY, 0, NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(open_req1.result != -1); ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1); uv_fs_req_cleanup(&open_req1);
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1, r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1,
NULL); NULL);
ASSERT(r != -1); ASSERT(r >= 0);
ASSERT(read_req.result != -1); ASSERT(read_req.result >= 0);
ASSERT(strcmp(buf, test_buf) == 0); ASSERT(strcmp(buf, test_buf) == 0);
uv_fs_req_cleanup(&read_req); uv_fs_req_cleanup(&read_req);
@ -1921,8 +1928,8 @@ TEST_IMPL(fs_read_file_eof) {
uv_fs_req_cleanup(&read_req); uv_fs_req_cleanup(&read_req);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL); r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
ASSERT(r != -1); ASSERT(r == 0);
ASSERT(close_req.result != -1); ASSERT(close_req.result == 0);
uv_fs_req_cleanup(&close_req); uv_fs_req_cleanup(&close_req);
/* Cleanup */ /* Cleanup */

4
deps/uv/test/test-get-currentexe.c

@ -54,10 +54,10 @@ TEST_IMPL(get_currentexe) {
/* Negative tests */ /* Negative tests */
size = sizeof(buffer) / sizeof(buffer[0]); size = sizeof(buffer) / sizeof(buffer[0]);
r = uv_exepath(NULL, &size); r = uv_exepath(NULL, &size);
ASSERT(r == -1); ASSERT(r == UV_EINVAL);
r = uv_exepath(buffer, NULL); r = uv_exepath(buffer, NULL);
ASSERT(r == -1); ASSERT(r == UV_EINVAL);
return 0; return 0;
} }

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save