vgcore.*
.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.pc
+/libuv.so
+/ltmain.sh
+/missing
+/test-driver
+Makefile
+Makefile.in
# Generated by dtrace(1) when doing an in-tree build.
-/src/unix/uv-dtrace.h
+/include/uv-dtrace.h
/out/
/build/gyp
Wynn Wilkes <wynnw@movenetworks.com>
Linus MÃ¥rtensson <linus.martensson@sonymobile.com>
Andrei Sedoi <bsnote@gmail.com>
+Navaneeth Kedaram Nambiathan <navaneethkn@gmail.com>
-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:
+++ /dev/null
-# 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
--- /dev/null
+# 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, $@)
# libuv
-libuv is a new platform layer for Node. Its purpose is to abstract IOCP on
-Windows and epoll/kqueue/event ports/etc. on Unix systems. We intend to
+libuv is a platform layer for [node.js][]. Its purpose is to abstract IOCP
+on Windows and epoll/kqueue/event ports/etc. on Unix systems. We intend to
eventually contain all platform differences in this library.
-http://nodejs.org/
-
## Features
* Non-blocking TCP sockets
* ANSI escape code controlled TTY `uv_tty_t`
- * File system events Currently supports inotify, `ReadDirectoryChangesW`
- and kqueue. Event ports in the near future.
- `uv_fs_event_t`
+ * File system events using inotify, kqueue, event ports,
+ FSEvents and `ReadDirectoryChangesW`
* IPC and socket sharing between processes `uv_write2`
## Build Instructions
-For GCC (including MinGW) there are two methods building: via normal
-makefiles or via GYP. GYP is a meta-build system which can generate MSVS,
-Makefile, and XCode backends. It is best used for integration into other
-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:
+For GCC there are two methods building: via autotools or via [GYP][].
+GYP is a meta-build system which can generate MSVS, Makefile, and XCode
+backends. It is best used for integration into other projects.
- make builddir_name=/path/to/builddir
+To build with autotools:
-To build a shared object:
-
- make libuv.so # libuv.dylib on OS X
+ $ sh autogen.sh
+ $ ./configure
+ $ make
+ $ make check
+ $ make install
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
related files.
-Windows users can also build from cmd-line using msbuild. This is
-done by running vcbuild.bat from Visual Studio command prompt.
+Windows users can also build from the command line using msbuild.
+This is done by running vcbuild.bat from Visual Studio command prompt.
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
project tree manually:
- mkdir -p build
- svn co http://gyp.googlecode.com/svn/trunk build/gyp
+ $ mkdir -p build
+ $ git clone https://git.chromium.org/external/gyp.git build/gyp
-Or:
+Unix users run:
- mkdir -p build
- git clone https://git.chromium.org/external/gyp.git build/gyp
+ $ ./gyp_uv -f make
+ $ make -C out
-Unix users run
+Macintosh users run:
- ./gyp_uv -f make
- make -C out
+ $ ./gyp_uv -f xcode
+ $ xcodebuild -project uv.xcodeproj -configuration Release -target All
-Macintosh users run
+To build for android:
- ./gyp_uv -f xcode
- xcodebuild -project uv.xcodeproj -configuration Release -target All
+ $ source ./android-configure NDK_PATH gyp
+ $ make -C out
Note for UNIX users: compile your project with `-D_LARGEFILE_SOURCE` and
`-D_FILE_OFFSET_BITS=64`. GYP builds take care of that automatically.
include `uv.h`. GYP builds take care of that automatically. If you use
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
Microsoft Windows operating systems since Windows XP SP2. It can be built
[Visual Studio Express 2010][] or later if you do not have a full Visual
Studio license.
-Linux 2.6 using the GCC toolchain.
+Linux using the GCC toolchain.
MacOS using the GCC or XCode 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
--- /dev/null
+#!/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
+++ /dev/null
-# 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)
-Wno-do-while
-Wno-transparent-union
-Iinclude
--Iinclude/uv-private
-Isrc
"}
SOURCES="
-include/uv-private/tree.h
-include/uv-private/uv-unix.h
+include/tree.h
+include/uv-unix.h
include/uv.h
src/fs-poll.c
src/inet.c
src/unix/async.c
src/unix/core.c
src/unix/dl.c
-src/unix/error.c
src/unix/fs.c
src/unix/getaddrinfo.c
src/unix/internal.h
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-loop-handles.c
Darwin)
SPARSE_FLAGS="$SPARSE_FLAGS -D__APPLE__=1"
SOURCES="$SOURCES
- include/uv-private/uv-bsd.h
+ include/uv-bsd.h
src/unix/darwin.c
src/unix/kqueue.c
src/unix/fsevents.c"
DragonFly)
SPARSE_FLAGS="$SPARSE_FLAGS -D__DragonFly__=1"
SOURCES="$SOURCES
- include/uv-private/uv-bsd.h
+ include/uv-bsd.h
src/unix/kqueue.c
src/unix/freebsd.c"
;;
FreeBSD)
SPARSE_FLAGS="$SPARSE_FLAGS -D__FreeBSD__=1"
SOURCES="$SOURCES
- include/uv-private/uv-bsd.h
+ include/uv-bsd.h
src/unix/kqueue.c
src/unix/freebsd.c"
;;
Linux)
SPARSE_FLAGS="$SPARSE_FLAGS -D__linux__=1"
SOURCES="$SOURCES
- include/uv-private/uv-linux.h
+ include/uv-linux.h
src/unix/linux-inotify.c
src/unix/linux-core.c
src/unix/linux-syscalls.c
NetBSD)
SPARSE_FLAGS="$SPARSE_FLAGS -D__NetBSD__=1"
SOURCES="$SOURCES
- include/uv-private/uv-bsd.h
+ include/uv-bsd.h
src/unix/kqueue.c
src/unix/netbsd.c"
;;
OpenBSD)
SPARSE_FLAGS="$SPARSE_FLAGS -D__OpenBSD__=1"
SOURCES="$SOURCES
- include/uv-private/uv-bsd.h
+ include/uv-bsd.h
src/unix/kqueue.c
src/unix/openbsd.c"
;;
SunOS)
SPARSE_FLAGS="$SPARSE_FLAGS -D__sun=1"
SOURCES="$SOURCES
- include/uv-private/uv-sunos.h
+ include/uv-sunos.h
src/unix/sunos.c"
;;
esac
},
'xcode_settings': {
'GCC_OPTIMIZATION_LEVEL': '0',
+ 'OTHER_CFLAGS': [ '-Wno-strict-aliasing' ],
},
'conditions': [
['OS != "win"', {
+++ /dev/null
-# 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
+++ /dev/null
-# 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 $@
--- /dev/null
+# 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
#define UV_HAVE_KQUEUE 1
+#define UV_PLATFORM_HAS_IP6_LINK_LOCAL_ADDRESS
+
#endif /* UV_DARWIN_H */
--- /dev/null
+/* 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_ */
void* watchers[2]; \
int wd; \
+#define UV_PLATFORM_HAS_IP6_LINK_LOCAL_ADDRESS
+
#endif /* UV_LINUX_H */
#include <sys/stat.h>
#if defined(_MSC_VER) && _MSC_VER < 1600
-# include "uv-private/stdint-msvc2008.h"
+# include "stdint-msvc2008.h"
#else
# include <stdint.h>
#endif
UV_REQ_FIELDS \
} exit_req; \
BYTE* child_stdio_buffer; \
- uv_err_t spawn_error; \
+ int spawn_error; \
int exit_signal; \
HANDLE wait_handle; \
HANDLE process_handle; \
char* utf8Buffer, size_t utf8Size);
int uv_utf8_to_utf16(const char* utf8Buffer, WCHAR* utf16Buffer,
size_t utf16Size);
+
+#define UV_PLATFORM_HAS_IP6_LINK_LOCAL_ADDRESS
# define UV_EXTERN /* nothing */
#endif
+#include "uv-errno.h"
+
#if defined(_MSC_VER) && _MSC_VER < 1600
-# include "uv-private/stdint-msvc2008.h"
+# include "stdint-msvc2008.h"
#else
# include <stdint.h>
#endif
#if defined(__unix__) || defined(__POSIX__) || \
defined(__APPLE__) || defined(_AIX)
-# include "uv-private/uv-unix.h"
+# include "uv-unix.h"
#else
-# include "uv-private/uv-win.h"
+# include "uv-win.h"
#endif
/* Expand this list if necessary. */
#define UV_ERRNO_MAP(XX) \
- XX( -1, UNKNOWN, "unknown error") \
- XX( 0, OK, "success") \
- XX( 1, EOF, "end of file") \
- XX( 2, EADDRINFO, "getaddrinfo error") \
- XX( 3, EACCES, "permission denied") \
- XX( 4, EAGAIN, "resource temporarily unavailable") \
- XX( 5, EADDRINUSE, "address already in use") \
- XX( 6, EADDRNOTAVAIL, "address not available") \
- XX( 7, EAFNOSUPPORT, "address family not supported") \
- XX( 8, EALREADY, "connection already in progress") \
- XX( 9, EBADF, "bad file descriptor") \
- XX( 10, EBUSY, "resource busy or locked") \
- XX( 11, ECONNABORTED, "software caused connection abort") \
- XX( 12, ECONNREFUSED, "connection refused") \
- XX( 13, ECONNRESET, "connection reset by peer") \
- XX( 14, EDESTADDRREQ, "destination address required") \
- XX( 15, EFAULT, "bad address in system call argument") \
- XX( 16, EHOSTUNREACH, "host is unreachable") \
- XX( 17, EINTR, "interrupted system call") \
- XX( 18, EINVAL, "invalid argument") \
- XX( 19, EISCONN, "socket is already connected") \
- XX( 20, EMFILE, "too many open files") \
- XX( 21, EMSGSIZE, "message too long") \
- XX( 22, ENETDOWN, "network is down") \
- XX( 23, ENETUNREACH, "network is unreachable") \
- XX( 24, ENFILE, "file table overflow") \
- XX( 25, ENOBUFS, "no buffer space available") \
- XX( 26, ENOMEM, "not enough memory") \
- XX( 27, ENOTDIR, "not a directory") \
- XX( 28, EISDIR, "illegal operation on a directory") \
- XX( 29, ENONET, "machine is not on the network") \
- XX( 31, ENOTCONN, "socket is not connected") \
- XX( 32, ENOTSOCK, "socket operation on non-socket") \
- XX( 33, ENOTSUP, "operation not supported on socket") \
- XX( 34, ENOENT, "no such file or directory") \
- XX( 35, ENOSYS, "function not implemented") \
- XX( 36, EPIPE, "broken pipe") \
- XX( 37, EPROTO, "protocol error") \
- XX( 38, EPROTONOSUPPORT, "protocol not supported") \
- XX( 39, EPROTOTYPE, "protocol wrong type for socket") \
- XX( 40, ETIMEDOUT, "connection timed out") \
- XX( 41, ECHARSET, "invalid Unicode character") \
- XX( 42, EAIFAMNOSUPPORT, "address family for hostname not supported") \
- XX( 44, EAISERVICE, "servname not supported for ai_socktype") \
- XX( 45, EAISOCKTYPE, "ai_socktype not supported") \
- XX( 46, ESHUTDOWN, "cannot send after transport endpoint shutdown") \
- XX( 47, EEXIST, "file already exists") \
- XX( 48, ESRCH, "no such process") \
- XX( 49, ENAMETOOLONG, "name too long") \
- XX( 50, EPERM, "operation not permitted") \
- XX( 51, ELOOP, "too many symbolic links encountered") \
- XX( 52, EXDEV, "cross-device link not permitted") \
- XX( 53, ENOTEMPTY, "directory not empty") \
- XX( 54, ENOSPC, "no space left on device") \
- XX( 55, EIO, "i/o error") \
- XX( 56, EROFS, "read-only file system") \
- XX( 57, ENODEV, "no such device") \
- XX( 58, ESPIPE, "invalid seek") \
- XX( 59, ECANCELED, "operation canceled") \
-
-
-#define UV_ERRNO_GEN(val, name, s) UV_##name = val,
-typedef enum {
- UV_ERRNO_MAP(UV_ERRNO_GEN)
- UV_MAX_ERRORS
-} uv_err_code;
-#undef UV_ERRNO_GEN
+ XX(EACCES, "permission denied") \
+ XX(EADDRINUSE, "address already in use") \
+ XX(EADDRNOTAVAIL, "address not available") \
+ XX(EAFNOSUPPORT, "address family not supported") \
+ XX(EAGAIN, "resource temporarily unavailable") \
+ XX(EAI_ADDRFAMILY, "address family not supported") \
+ XX(EAI_AGAIN, "temporary failure") \
+ XX(EAI_BADFLAGS, "bad ai_flags value") \
+ XX(EAI_CANCELED, "request canceled") \
+ XX(EAI_FAIL, "permanent failure") \
+ XX(EAI_FAMILY, "ai_family not supported") \
+ XX(EAI_MEMORY, "out of memory") \
+ XX(EAI_NODATA, "no address") \
+ XX(EAI_NONAME, "unknown node or service") \
+ XX(EAI_SERVICE, "service not available for socket type") \
+ XX(EAI_SOCKTYPE, "socket type not supported") \
+ XX(EAI_SYSTEM, "system error") \
+ XX(EALREADY, "connection already in progress") \
+ XX(EBADF, "bad file descriptor") \
+ XX(EBUSY, "resource busy or locked") \
+ XX(ECANCELED, "operation canceled") \
+ XX(ECHARSET, "invalid Unicode character") \
+ XX(ECONNABORTED, "software caused connection abort") \
+ XX(ECONNREFUSED, "connection refused") \
+ XX(ECONNRESET, "connection reset by peer") \
+ XX(EDESTADDRREQ, "destination address required") \
+ XX(EEXIST, "file already exists") \
+ XX(EFAULT, "bad address in system call argument") \
+ XX(EHOSTUNREACH, "host is unreachable") \
+ XX(EINTR, "interrupted system call") \
+ XX(EINVAL, "invalid argument") \
+ XX(EIO, "i/o error") \
+ XX(EISCONN, "socket is already connected") \
+ XX(EISDIR, "illegal operation on a directory") \
+ XX(ELOOP, "too many symbolic links encountered") \
+ XX(EMFILE, "too many open files") \
+ XX(EMSGSIZE, "message too long") \
+ XX(ENAMETOOLONG, "name too long") \
+ XX(ENETDOWN, "network is down") \
+ XX(ENETUNREACH, "network is unreachable") \
+ XX(ENFILE, "file table overflow") \
+ XX(ENOBUFS, "no buffer space available") \
+ XX(ENODEV, "no such device") \
+ XX(ENOENT, "no such file or directory") \
+ XX(ENOMEM, "not enough memory") \
+ XX(ENONET, "machine is not on the network") \
+ XX(ENOSPC, "no space left on device") \
+ XX(ENOSYS, "function not implemented") \
+ XX(ENOTCONN, "socket is not connected") \
+ XX(ENOTDIR, "not a directory") \
+ XX(ENOTEMPTY, "directory not empty") \
+ XX(ENOTSOCK, "socket operation on non-socket") \
+ XX(ENOTSUP, "operation not supported on socket") \
+ XX(EPERM, "operation not permitted") \
+ XX(EPIPE, "broken pipe") \
+ XX(EPROTO, "protocol error") \
+ XX(EPROTONOSUPPORT, "protocol not supported") \
+ XX(EPROTOTYPE, "protocol wrong type for socket") \
+ XX(EROFS, "read-only file system") \
+ XX(ESHUTDOWN, "cannot send after transport endpoint shutdown") \
+ XX(ESPIPE, "invalid seek") \
+ XX(ESRCH, "no such process") \
+ XX(ETIMEDOUT, "connection timed out") \
+ XX(EXDEV, "cross-device link not permitted") \
+ XX(UNKNOWN, "unknown error") \
+ XX(EOF, "end of file") \
#define UV_HANDLE_TYPE_MAP(XX) \
XX(ASYNC, async) \
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 {
UV_UNKNOWN_HANDLE = 0,
#define XX(uc, lc) UV_##uc,
UV_HANDLE_TYPE_MAP(XX)
/* Handle types. */
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_stream_s uv_stream_t;
typedef struct uv_tcp_s uv_tcp_t;
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
- * or -1 on error.
- *
- * Error details can be obtained by calling uv_last_error(). UV_EOF indicates
- * that the stream has been closed.
+ * `nread` is > 0 if there is data available, 0 if libuv is done reading for
+ * now, or < 0 on error.
*
* The callee is responsible for closing the stream when an error happens.
* Trying to read from the stream again is undefined.
uint64_t st_size;
uint64_t st_blksize;
uint64_t st_blocks;
+ uint64_t st_flags;
+ uint64_t st_gen;
uv_timespec_t st_atim;
uv_timespec_t st_mtim;
uv_timespec_t st_ctim;
+ uv_timespec_t st_birthtim;
} uv_stat_t;
} 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.
- * On error the user should then call uv_last_error() to determine
- * the error code.
+ * Most functions return 0 on success or an error code < 0 on failure.
*/
-UV_EXTERN uv_err_t uv_last_error(uv_loop_t*);
-UV_EXTERN const char* uv_strerror(uv_err_t err);
-UV_EXTERN const char* uv_err_name(uv_err_t err);
+UV_EXTERN const char* uv_strerror(int err);
+UV_EXTERN const char* uv_err_name(int err);
#define UV_REQ_FIELDS \
* 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
- * have their callbacks called asynchronously with status=-1 and the error code
- * set to UV_ECANCELED.
+ * have their callbacks called asynchronously with status=UV_ECANCELED.
*/
UV_EXTERN void uv_close(uv_handle_t* handle, uv_close_cb close_cb);
/*
* Read data from an incoming stream. The callback will be made several
* times until there is no more data to read or uv_read_stop is called.
- * When we've reached EOF nread will be set to -1 and the error is set
- * 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 we've reached EOF nread will be set to UV_EOF.
+ *
+ * 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
* eof; it happens when libuv requested a buffer through the alloc callback
* but then decided that it didn't need that buffer.
* nread Number of bytes that have been received.
* 0 if there is no more data to read. You may
* 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.
* addr struct sockaddr_in or struct sockaddr_in6.
* Valid for the duration of the callback only.
* flags Unused.
*
* 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,
unsigned flags);
* flags Should be 0 or UV_UDP_IPV6ONLY.
*
* 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,
unsigned flags);
+
UV_EXTERN int uv_udp_getsockname(uv_udp_t* handle, struct sockaddr* name,
int* namelen);
* membership Should be UV_JOIN_GROUP or UV_LEAVE_GROUP
*
* 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,
const char* multicast_addr, const char* interface_addr,
* on 1 for on, 0 for off
*
* 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);
* ttl 1 through 255
*
* 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);
* on 1 for on, 0 for off
*
* 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);
* ttl 1 through 255
*
* 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);
* send_cb Callback to invoke when the data has been sent out.
*
* 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_buf_t bufs[], int bufcnt, struct sockaddr_in addr,
* send_cb Callback to invoke when the data has been sent out.
*
* 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_buf_t bufs[], int bufcnt, struct sockaddr_in6 addr,
* recv_cb Callback to invoke with received data.
*
* 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_udp_recv_cb recv_cb);
* handle UDP handle. Should have been initialized with `uv_udp_init`.
*
* 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);
* will be called with `status` set to 0, and the detected events set en the
* `events` field.
*
- * If an error happens while polling status may be set to -1 and the error
- * code can be retrieved with uv_last_error. The user should not close the
- * socket while uv_poll is active. If the user does that anyway, the callback
- * *may* be called reporting an error status, but this is not guaranteed.
+ * If an error happens while polling status, `status` < 0 and corresponds
+ * with one of the UV_E* error codes. The user should not close the socket
+ * while uv_poll is active. If the user does that anyway, the callback *may*
+ * 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.
* Doing so will update the events mask that is being watched for.
/*
* 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
- * sets the error to UV_EINVAL.
+ * as the timeout. If the timer has never been started before it returns
+ * UV_EINVAL.
*/
UV_EXTERN int uv_timer_again(uv_timer_t* handle);
* hints is a pointer to a struct addrinfo with additional address type
* 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
* lookup result, which is either:
*
- * a) status == 0, the res argument points to a valid struct addrinfo, or
- * b) status == -1, the res argument is NULL.
- *
- * On NXDOMAIN, the status code is -1 and uv_last_error() returns UV_ENOENT.
+ * a) err == 0, the res argument points to a valid struct addrinfo, or
+ * b) err < 0, the res argument is NULL. See the UV_EAI_* constants.
*
* Call uv_freeaddrinfo() to free the addrinfo structure.
*/
*/
UV_EXTERN void uv_freeaddrinfo(struct addrinfo* ai);
+
/* uv_spawn() options */
typedef enum {
UV_IGNORE = 0x00,
/* 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);
/*
/* Cancel a pending request. Fails if the request is executing or has finished
* 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
* currently supported.
*
* 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
- * status == -1 and uv_last_error(loop).code == UV_ECANCELED.
+ * status == UV_ECANCELED.
*
* 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 char** uv_setup_args(int argc, char** argv);
-UV_EXTERN uv_err_t uv_get_process_title(char* buffer, size_t size);
-UV_EXTERN uv_err_t uv_set_process_title(const char* title);
-UV_EXTERN uv_err_t uv_resident_set_memory(size_t* rss);
-UV_EXTERN uv_err_t uv_uptime(double* uptime);
+UV_EXTERN int uv_get_process_title(char* buffer, size_t size);
+UV_EXTERN int uv_set_process_title(const char* title);
+UV_EXTERN int uv_resident_set_memory(size_t* rss);
+UV_EXTERN int uv_uptime(double* uptime);
/*
* This allocates cpu_infos array, and sets count. The array
* 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);
/*
* This allocates addresses array, and sets count. The array
* 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);
UV_EXTERN void uv_free_interface_addresses(uv_interface_address_t* addresses,
int count);
ssize_t result;
void* ptr;
const char* path;
- uv_err_code errorno;
uv_stat_t statbuf; /* Stores the result of uv_fs_stat and uv_fs_fstat. */
UV_FS_PRIVATE_FIELDS
};
/*
* 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
* not called again until something changes (e.g. when the file is created
* or the error reason changes).
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 */
-/* 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. */
-UV_EXTERN uv_err_t 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_ntop(int af, const void* src, char* dst, size_t size);
+UV_EXTERN int uv_inet_pton(int af, const char* src, void* dst);
/* Gets the executable path */
UV_EXTERN int uv_exepath(char* buffer, size_t* size);
/* 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 */
-UV_EXTERN uv_err_t uv_chdir(const char* dir);
+UV_EXTERN int uv_chdir(const char* dir);
/* Gets memory info in bytes */
UV_EXTERN uint64_t uv_get_free_memory(void);
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).
*/
UV_EXTERN int uv_mutex_init(uv_mutex_t* handle);
*/
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.
- * 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:
* 1. callers should be prepared to deal with spurious wakeups.
struct uv_loop_s {
/* User data - use this for whatever. */
void* data;
- /* The last error */
- uv_err_t last_err;
/* Loop reference counting */
unsigned int active_handles;
void* handle_queue[2];
ctx = calloc(1, sizeof(*ctx) + len);
if (ctx == NULL)
- return uv__set_artificial_error(loop, UV_ENOMEM);
+ return UV_ENOMEM;
ctx->loop = loop;
ctx->poll_cb = cb;
}
if (req->result != 0) {
- if (ctx->busy_polling != -req->errorno) {
- uv__set_artificial_error(ctx->loop, req->errorno);
- ctx->poll_cb(ctx->parent_handle, -1, &ctx->statbuf, &zero_statbuf);
- ctx->busy_polling = -req->errorno;
+ if (ctx->busy_polling != req->result) {
+ ctx->poll_cb(ctx->parent_handle,
+ req->result,
+ &ctx->statbuf,
+ &zero_statbuf);
+ ctx->busy_polling = req->result;
}
goto out;
}
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
&& 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_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_mode == b->st_mode
&& a->st_uid == b->st_uid
&& a->st_gid == b->st_gid
&& 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;
}
#include <string.h>
#if defined(_MSC_VER) && _MSC_VER < 1600
-# include "uv-private/stdint-msvc2008.h"
+# include "stdint-msvc2008.h"
#else
# include <stdint.h>
#endif
#include "uv-common.h"
-static const uv_err_t uv_eafnosupport_ = { UV_EAFNOSUPPORT, 0 };
-static const uv_err_t uv_enospc_ = { UV_ENOSPC, 0 };
-static const uv_err_t uv_einval_ = { UV_EINVAL, 0 };
+static int inet_ntop4(const unsigned char *src, char *dst, size_t size);
+static int inet_ntop6(const unsigned char *src, char *dst, size_t size);
+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);
-
-uv_err_t uv_inet_ntop(int af, const void* src, char* dst, size_t size) {
+int uv_inet_ntop(int af, const void* src, char* dst, size_t size) {
switch (af) {
case AF_INET:
return (inet_ntop4(src, dst, size));
case AF_INET6:
return (inet_ntop6(src, dst, size));
default:
- return uv_eafnosupport_;
+ return UV_EAFNOSUPPORT;
}
/* 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";
char tmp[sizeof "255.255.255.255"];
int l;
l = _snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], src[3]);
#endif
if (l <= 0 || (size_t) l >= size) {
- return uv_enospc_;
+ return UV_ENOSPC;
}
strncpy(dst, tmp, size);
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
* to contain a value of the specified size. On some systems, like
if (i == 6 && best.base == 0 && (best.len == 6 ||
(best.len == 7 && words[7] != 0x0001) ||
(best.len == 5 && words[5] == 0xffff))) {
- uv_err_t err = inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp));
- if (err.code != UV_OK)
+ int err = inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp));
+ if (err)
return err;
tp += strlen(tp);
break;
* Check for overflow, copy, and we're done.
*/
if ((size_t)(tp - tmp) > size) {
- return uv_enospc_;
+ return UV_ENOSPC;
}
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) {
case AF_INET:
return (inet_pton4(src, dst));
case AF_INET6:
return (inet_pton6(src, dst));
default:
- return uv_eafnosupport_;
+ return UV_EAFNOSUPPORT;
}
/* 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";
int saw_digit, octets, ch;
unsigned char tmp[sizeof(struct in_addr)], *tp;
unsigned int nw = *tp * 10 + (pch - digits);
if (saw_digit && *tp == 0)
- return uv_einval_;
+ return UV_EINVAL;
if (nw > 255)
- return uv_einval_;
+ return UV_EINVAL;
*tp = nw;
if (!saw_digit) {
if (++octets > 4)
- return uv_einval_;
+ return UV_EINVAL;
saw_digit = 1;
}
} else if (ch == '.' && saw_digit) {
if (octets == 4)
- return uv_einval_;
+ return UV_EINVAL;
*++tp = 0;
saw_digit = 0;
} else
- return uv_einval_;
+ return UV_EINVAL;
}
if (octets < 4)
- return uv_einval_;
+ return UV_EINVAL;
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",
xdigits_u[] = "0123456789ABCDEF";
unsigned char tmp[sizeof(struct in6_addr)], *tp, *endp, *colonp;
/* Leading :: requires some special handling. */
if (*src == ':')
if (*++src != ':')
- return uv_einval_;
+ return UV_EINVAL;
curtok = src;
seen_xdigits = 0;
val = 0;
val <<= 4;
val |= (pch - xdigits);
if (++seen_xdigits > 4)
- return uv_einval_;
+ return UV_EINVAL;
continue;
}
if (ch == ':') {
curtok = src;
if (!seen_xdigits) {
if (colonp)
- return uv_einval_;
+ return UV_EINVAL;
colonp = tp;
continue;
} else if (*src == '\0') {
- return uv_einval_;
+ return UV_EINVAL;
}
if (tp + sizeof(uint16_t) > endp)
- return uv_einval_;
+ return UV_EINVAL;
*tp++ = (unsigned char) (val >> 8) & 0xff;
*tp++ = (unsigned char) val & 0xff;
seen_xdigits = 0;
continue;
}
if (ch == '.' && ((tp + sizeof(struct in_addr)) <= endp)) {
- uv_err_t err = inet_pton4(curtok, tp);
- if (err.code == 0) {
+ int err = inet_pton4(curtok, tp);
+ if (err == 0) {
tp += sizeof(struct in_addr);
seen_xdigits = 0;
break; /*%< '\\0' was seen by inet_pton4(). */
}
}
- return uv_einval_;
+ return UV_EINVAL;
}
if (seen_xdigits) {
if (tp + sizeof(uint16_t) > endp)
- return uv_einval_;
+ return UV_EINVAL;
*tp++ = (unsigned char) (val >> 8) & 0xff;
*tp++ = (unsigned char) val & 0xff;
}
int i;
if (tp == endp)
- return uv_einval_;
+ return UV_EINVAL;
for (i = 1; i <= n; i++) {
endp[- i] = colonp[n - i];
colonp[n - i] = 0;
tp = endp;
}
if (tp != endp)
- return uv_einval_;
+ return UV_EINVAL;
memcpy(dst, tmp, sizeof tmp);
- return uv_ok_;
+ return 0;
}
uv_fs_event_cb cb,
int flags) {
loop->counters.fs_event_init++;
- uv__set_sys_error(loop, ENOSYS);
- return -1;
+ return -ENOSYS;
}
}
-uv_err_t uv_set_process_title(const char* title) {
- return uv_ok_;
+int uv_set_process_title(const char* title) {
+ 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) {
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];
psinfo_t psinfo;
- uv_err_t err;
+ int err;
int fd;
(void) snprintf(pp, sizeof(pp), "/proc/%lu/psinfo", (unsigned long) getpid());
fd = open(pp, O_RDONLY);
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;
- else
- err = uv__new_sys_error(EINVAL);
-
+ err = 0;
+ }
close(fd);
return err;
}
-uv_err_t uv_uptime(double* uptime) {
+int uv_uptime(double* uptime) {
struct utmp *utmp_buf;
size_t entries = 0;
time_t boot_time;
endutent();
if (boot_time == 0)
- return uv__new_artificial_error(UV_ENOSYS);
+ return -ENOSYS;
*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;
perfstat_cpu_total_t ps_total;
perfstat_cpu_t* ps_cpus;
result = perfstat_cpu_total(NULL, &ps_total, sizeof(ps_total), 1);
if (result == -1) {
- return uv__new_artificial_error(UV_ENOSYS);
+ return -ENOSYS;
}
ncpus = result = perfstat_cpu(NULL, NULL, sizeof(perfstat_cpu_t), 0);
if (result == -1) {
- return uv__new_artificial_error(UV_ENOSYS);
+ return -ENOSYS;
}
ps_cpus = (perfstat_cpu_t*) malloc(ncpus * sizeof(perfstat_cpu_t));
if (!ps_cpus) {
- return uv__new_artificial_error(UV_ENOMEM);
+ return -ENOMEM;
}
strcpy(cpu_id.name, FIRST_CPU);
result = perfstat_cpu(&cpu_id, ps_cpus, sizeof(perfstat_cpu_t), ncpus);
if (result == -1) {
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));
if (!*cpu_infos) {
free(ps_cpus);
- return uv__new_artificial_error(UV_ENOMEM);
+ return -ENOMEM;
}
*count = ncpus;
}
free(ps_cpus);
- return uv_ok_;
+ return 0;
}
}
-uv_err_t uv_interface_addresses(uv_interface_address_t** addresses,
+int uv_interface_addresses(uv_interface_address_t** addresses,
int* count) {
uv_interface_address_t* address;
int sockfd, size = 1;
*count = 0;
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) {
close(sockfd);
- return uv__new_artificial_error(UV_ENOSYS);
+ return -ENOSYS;
}
ifc.ifc_req = (struct ifreq*)malloc(size);
ifc.ifc_len = size;
if (ioctl(sockfd, SIOCGIFCONF, &ifc) == -1) {
close(sockfd);
- return uv__new_artificial_error(UV_ENOSYS);
+ return -ENOSYS;
}
#define ADDR_SIZE(p) MAX((p).sa_len, sizeof(p))
malloc(*count * sizeof(uv_interface_address_t));
if (!(*addresses)) {
close(sockfd);
- return uv__new_artificial_error(UV_ENOMEM);
+ return -ENOMEM;
}
address = *addresses;
#undef ADDR_SIZE
close(sockfd);
- return uv_ok_;
+ return 0;
}
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))
- return uv__set_sys_error(loop, errno);
+ int err;
+
+ 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);
handle->async_cb = async_cb;
int uv__async_start(uv_loop_t* loop, struct uv__async* wa, uv__async_cb cb) {
int pipefd[2];
- int fd;
+ int err;
if (wa->io_watcher.fd != -1)
return 0;
- fd = uv__async_eventfd();
- if (fd >= 0) {
- pipefd[0] = fd;
+ err = uv__async_eventfd();
+ if (err >= 0) {
+ pipefd[0] = err;
pipefd[1] = -1;
}
- else if (fd != -ENOSYS)
- return -1;
- else if (uv__make_pipe(pipefd, UV__F_NONBLOCK))
- return -1;
+ else if (err == -ENOSYS)
+ err = uv__make_pipe(pipefd, UV__F_NONBLOCK);
+
+ if (err < 0)
+ return err;
uv__io_init(&wa->io_watcher, uv__async_io, pipefd[0]);
uv__io_start(loop, &wa->io_watcher, UV__POLLIN);
/* Open a socket in non-blocking close-on-exec mode, atomically if possible. */
int uv__socket(int domain, int type, int protocol) {
int sockfd;
+ int err;
#if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC)
sockfd = socket(domain, type | SOCK_NONBLOCK | SOCK_CLOEXEC, protocol);
-
if (sockfd != -1)
- goto out;
+ return sockfd;
if (errno != EINVAL)
- goto out;
+ return -errno;
#endif
sockfd = socket(domain, type, protocol);
-
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);
- sockfd = -1;
+ return err;
}
#if defined(SO_NOSIGPIPE)
}
#endif
-out:
return sockfd;
}
int uv__accept(int sockfd) {
int peerfd;
+ int err;
assert(sockfd >= 0);
NULL,
NULL,
UV__SOCK_NONBLOCK|UV__SOCK_CLOEXEC);
-
if (peerfd != -1)
- break;
+ return peerfd;
if (errno == EINTR)
continue;
if (errno != ENOSYS)
- break;
+ return -errno;
no_accept4 = 1;
skip:
#endif
peerfd = accept(sockfd, NULL, NULL);
-
if (peerfd == -1) {
if (errno == EINTR)
continue;
- else
- break;
+ return -errno;
}
- 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);
- peerfd = -1;
+ return err;
}
- break;
+ return peerfd;
}
-
- return peerfd;
}
r = ioctl(fd, FIONBIO, &set);
while (r == -1 && errno == EINTR);
- return r;
+ if (r)
+ return -errno;
+
+ return 0;
}
r = ioctl(fd, set ? FIOCLEX : FIONCLEX);
while (r == -1 && errno == EINTR);
- return r;
+ if (r)
+ return -errno;
+
+ return 0;
}
#else /* !(defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)) */
while (r == -1 && errno == EINTR);
if (r == -1)
- return -1;
+ return -errno;
/* Bail out now if already set/clear. */
if (!!(r & O_NONBLOCK) == !!set)
r = fcntl(fd, F_SETFL, flags);
while (r == -1 && errno == EINTR);
- return r;
+ if (r)
+ return -errno;
+
+ return 0;
}
while (r == -1 && errno == EINTR);
if (r == -1)
- return -1;
+ return -errno;
/* Bail out now if already set/clear. */
if (!!(r & FD_CLOEXEC) == !!set)
r = fcntl(fd, F_SETFD, flags);
while (r == -1 && errno == EINTR);
- return r;
+ if (r)
+ return -errno;
+
+ return 0;
}
#endif /* defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) */
* between the call to dup() and fcntl(FD_CLOEXEC).
*/
int uv__dup(int fd) {
+ int err;
+
fd = dup(fd);
if (fd == -1)
- return -1;
+ return -errno;
- if (uv__cloexec(fd, 1)) {
- SAVE_ERRNO(close(fd));
- return -1;
+ err = uv__cloexec(fd, 1);
+ if (err) {
+ close(fd);
+ return err;
}
return fd;
}
-uv_err_t uv_cwd(char* buffer, size_t size) {
- if (!buffer || !size) {
- return uv__new_artificial_error(UV_EINVAL);
- }
+int uv_cwd(char* buffer, size_t size) {
+ if (buffer == NULL)
+ return -EINVAL;
- if (getcwd(buffer, size)) {
- return uv_ok_;
- } else {
- return uv__new_sys_error(errno);
- }
+ if (size == 0)
+ return -EINVAL;
+
+ if (getcwd(buffer, size) == NULL)
+ return -errno;
+
+ return 0;
}
-uv_err_t uv_chdir(const char* dir) {
- if (chdir(dir) == 0) {
- return uv_ok_;
- } else {
- return uv__new_sys_error(errno);
- }
+int uv_chdir(const char* dir) {
+ if (chdir(dir))
+ return -errno;
+
+ return 0;
}
int uv__set_process_title(const char* title) {
#if TARGET_OS_IPHONE
- return -1;
+ return -ENOSYS;
#else
typedef CFTypeRef (*LSGetCurrentApplicationASNType)(void);
typedef OSStatus (*LSSetApplicationInformationItemType)(int,
CFBundleGetBundleWithIdentifier(CFSTR("com.apple.LaunchServices"));
if (launch_services_bundle == NULL)
- return -1;
+ return -ENOENT;
ls_get_current_application_asn = (LSGetCurrentApplicationASNType)
CFBundleGetFunctionPointerForName(launch_services_bundle,
CFSTR("_LSGetCurrentApplicationASN"));
if (ls_get_current_application_asn == NULL)
- return -1;
+ return -ENOENT;
ls_set_application_information_item = (LSSetApplicationInformationItemType)
CFBundleGetFunctionPointerForName(launch_services_bundle,
CFSTR("_LSSetApplicationInformationItem"));
if (ls_set_application_information_item == NULL)
- return -1;
+ return -ENOENT;
display_name_key = CFBundleGetDataPointerForName(launch_services_bundle,
CFSTR("_kLSDisplayNameKey"));
if (display_name_key == NULL || *display_name_key == NULL)
- return -1;
+ return -ENOENT;
/* Force the process manager to initialize. */
GetCurrentProcess(&psn);
*display_name_key,
display_name,
NULL);
+ if (err != noErr)
+ return -ENOENT;
- return (err == noErr) ? 0 : -1;
+ return 0;
#endif /* !TARGET_OS_IPHONE */
}
int r;
if (uv__kqueue_init(loop))
- return -1;
+ return -errno;
loop->cf_loop = NULL;
if ((r = uv_mutex_init(&loop->cf_mutex)))
char* path;
char* fullpath;
- if (!buffer || !size) {
- return -1;
- }
+ if (buffer == NULL || size == NULL)
+ return -EINVAL;
usize = *size;
result = _NSGetExecutablePath(buffer, &usize);
path = (char*)malloc(2 * PATH_MAX);
fullpath = realpath(buffer, path);
-
if (fullpath == NULL) {
- free(path);
- return -1;
+ SAVE_ERRNO(free(path));
+ return -errno;
}
strncpy(buffer, fullpath, *size);
if (host_statistics(mach_host_self(), HOST_VM_INFO,
(host_info_t)&info, &count) != KERN_SUCCESS) {
- return -1;
+ return -EINVAL; /* FIXME(bnoordhuis) Translate error. */
}
return (uint64_t) info.free_count * sysconf(_SC_PAGESIZE);
int which[] = {CTL_HW, HW_MEMSIZE};
size_t size = sizeof(info);
- if (sysctl(which, 2, &info, &size, NULL, 0) < 0) {
- return -1;
- }
+ if (sysctl(which, 2, &info, &size, NULL, 0))
+ return -errno;
return (uint64_t) info;
}
}
-uv_err_t uv_resident_set_memory(size_t* rss) {
+int uv_resident_set_memory(size_t* rss) {
mach_msg_type_number_t count;
task_basic_info_data_t info;
kern_return_t err;
assert(err == KERN_SUCCESS);
*rss = info.resident_size;
- return uv_ok_;
+ return 0;
}
-uv_err_t uv_uptime(double* uptime) {
+int uv_uptime(double* uptime) {
time_t now;
struct timeval info;
size_t size = sizeof(info);
static int which[] = {CTL_KERN, KERN_BOOTTIME};
- if (sysctl(which, 2, &info, &size, NULL, 0) < 0) {
- return uv__new_sys_error(errno);
- }
- now = time(NULL);
+ if (sysctl(which, 2, &info, &size, NULL, 0))
+ return -errno;
- *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),
multiplier = ((uint64_t)1000L / ticks);
char model[512];
uv_cpu_info_t* cpu_info;
size = sizeof(model);
- if (sysctlbyname("machdep.cpu.brand_string", &model, &size, NULL, 0) < 0 &&
- sysctlbyname("hw.model", &model, &size, NULL, 0) < 0) {
- return uv__new_sys_error(errno);
+ if (sysctlbyname("machdep.cpu.brand_string", &model, &size, NULL, 0) &&
+ sysctlbyname("hw.model", &model, &size, NULL, 0)) {
+ return -errno;
}
+
size = sizeof(cpuspeed);
- if (sysctlbyname("hw.cpufrequency", &cpuspeed, &size, NULL, 0) < 0) {
- return uv__new_sys_error(errno);
- }
+ if (sysctlbyname("hw.cpufrequency", &cpuspeed, &size, NULL, 0))
+ return -errno;
if (host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &numcpus,
(processor_info_array_t*)&info,
&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));
- if (!(*cpu_infos)) {
- return uv__new_artificial_error(UV_ENOMEM);
- }
+ *cpu_infos = malloc(numcpus * sizeof(**cpu_infos));
+ if (!(*cpu_infos))
+ return -ENOMEM; /* FIXME(bnoordhuis) Deallocate info? */
*count = numcpus;
}
vm_deallocate(mach_task_self(), (vm_address_t)info, msg_type);
- return uv_ok_;
+ return 0;
}
}
-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, *ent;
- char ip[INET6_ADDRSTRLEN];
uv_interface_address_t* address;
- if (getifaddrs(&addrs) != 0) {
- return uv__new_sys_error(errno);
- }
+ if (getifaddrs(&addrs))
+ return -errno;
*count = 0;
(*count)++;
}
- *addresses = (uv_interface_address_t*)
- malloc(*count * sizeof(uv_interface_address_t));
- if (!(*addresses)) {
- return uv__new_artificial_error(UV_ENOMEM);
- }
+ *addresses = malloc(*count * sizeof(**addresses));
+ if (!(*addresses))
+ return -ENOMEM;
address = *addresses;
for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
- bzero(&ip, sizeof (ip));
if (!(ent->ifa_flags & IFF_UP && ent->ifa_flags & IFF_RUNNING)) {
continue;
}
freeifaddrs(addrs);
- return uv_ok_;
+ return 0;
}
+++ /dev/null
-/* 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();
-}
int mib[4];
size_t cb;
- if (!buffer || !size) {
- return -1;
- }
+ if (buffer == NULL || size == NULL)
+ return -EINVAL;
#ifdef __DragonFly__
mib[0] = CTL_KERN;
#endif
cb = *size;
- if (sysctl(mib, 4, buffer, &cb, NULL, 0) < 0) {
- *size = 0;
- return -1;
- }
+ if (sysctl(mib, 4, buffer, &cb, NULL, 0))
+ return -errno;
*size = strlen(buffer);
return 0;
int freecount;
size_t size = sizeof(freecount);
- if(sysctlbyname("vm.stats.vm.v_free_count",
- &freecount, &size, NULL, 0) == -1){
- return -1;
- }
+ if (sysctlbyname("vm.stats.vm.v_free_count", &freecount, &size, NULL, 0))
+ return -errno;
+
return (uint64_t) freecount * sysconf(_SC_PAGESIZE);
}
size_t size = sizeof(info);
- if (sysctl(which, 2, &info, &size, NULL, 0) < 0) {
- return -1;
- }
+ if (sysctl(which, 2, &info, &size, NULL, 0))
+ return -errno;
return (uint64_t) info;
}
}
-uv_err_t uv_set_process_title(const char* title) {
+int uv_set_process_title(const char* title) {
int oid[4];
if (process_title) free(process_title);
process_title,
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) {
strncpy(buffer, process_title, size);
} else {
}
}
- 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;
struct kinfo_proc *kinfo = NULL;
pid_t pid;
kvm_close(kd);
- return uv_ok_;
+ return 0;
error:
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;
struct timeval info;
size_t size = sizeof(info);
static int which[] = {CTL_KERN, KERN_BOOTTIME};
- if (sysctl(which, 2, &info, &size, NULL, 0) < 0) {
- return uv__new_sys_error(errno);
- }
+ if (sysctl(which, 2, &info, &size, NULL, 0))
+ return -errno;
now = time(NULL);
*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),
multiplier = ((uint64_t)1000L / ticks), cpuspeed, maxcpus,
cur = 0;
#endif
size = sizeof(model);
- if (sysctlbyname("hw.model", &model, &size, NULL, 0) < 0) {
- return uv__new_sys_error(errno);
- }
+ if (sysctlbyname("hw.model", &model, &size, NULL, 0))
+ return -errno;
+
size = sizeof(numcpus);
- if (sysctlbyname("hw.ncpu", &numcpus, &size, NULL, 0) < 0) {
- return uv__new_sys_error(errno);
- }
+ if (sysctlbyname("hw.ncpu", &numcpus, &size, NULL, 0))
+ return -errno;
- *cpu_infos = (uv_cpu_info_t*)malloc(numcpus * sizeof(uv_cpu_info_t));
- if (!(*cpu_infos)) {
- return uv__new_artificial_error(UV_ENOMEM);
- }
+ *cpu_infos = malloc(numcpus * sizeof(**cpu_infos));
+ if (!(*cpu_infos))
+ return -ENOMEM;
*count = numcpus;
size = sizeof(cpuspeed);
- if (sysctlbyname("hw.clockrate", &cpuspeed, &size, NULL, 0) < 0) {
- free(*cpu_infos);
- return uv__new_sys_error(errno);
+ if (sysctlbyname("hw.clockrate", &cpuspeed, &size, NULL, 0)) {
+ SAVE_ERRNO(free(*cpu_infos));
+ return -errno;
}
/* kern.cp_times on FreeBSD i386 gives an array up to maxcpus instead of ncpu */
size = sizeof(maxcpus);
- if (sysctlbyname(maxcpus_key, &maxcpus, &size, NULL, 0) < 0) {
- free(*cpu_infos);
- return uv__new_sys_error(errno);
+ if (sysctlbyname(maxcpus_key, &maxcpus, &size, NULL, 0)) {
+ SAVE_ERRNO(free(*cpu_infos));
+ return -errno;
}
size = maxcpus * CPUSTATES * sizeof(long);
cp_times = malloc(size);
if (cp_times == NULL) {
free(*cpu_infos);
- return uv__new_sys_error(ENOMEM);
+ return -ENOMEM;
}
- if (sysctlbyname(cptimes_key, cp_times, &size, NULL, 0) < 0) {
- free(cp_times);
- free(*cpu_infos);
- return uv__new_sys_error(errno);
+ if (sysctlbyname(cptimes_key, cp_times, &size, NULL, 0)) {
+ SAVE_ERRNO(free(cp_times));
+ SAVE_ERRNO(free(*cpu_infos));
+ return -errno;
}
for (i = 0; i < numcpus; i++) {
}
free(cp_times);
- return uv_ok_;
+ return 0;
}
}
-uv_err_t uv_interface_addresses(uv_interface_address_t** addresses,
- int* count) {
+int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
/* TODO: implement */
*addresses = NULL;
*count = 0;
- return uv_ok_;
+ return 0;
}
* 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 "internal.h"
do { \
uv__req_init((loop), (req), UV_FS); \
(req)->fs_type = UV_FS_ ## type; \
- (req)->errorno = 0; \
(req)->result = 0; \
(req)->ptr = NULL; \
(req)->loop = loop; \
#define PATH \
do { \
- if (NULL == ((req)->path = strdup((path)))) \
- return uv__set_sys_error((loop), ENOMEM); \
+ (req)->path = strdup(path); \
+ if ((req)->path == NULL) \
+ return -ENOMEM; \
} \
while (0)
do { \
size_t path_len; \
size_t new_path_len; \
- \
path_len = strlen((path)) + 1; \
new_path_len = strlen((new_path)) + 1; \
- \
- if (NULL == ((req)->path = malloc(path_len + new_path_len))) \
- return uv__set_sys_error((loop), ENOMEM); \
- \
+ (req)->path = malloc(path_len + new_path_len); \
+ if ((req)->path == NULL) \
+ return -ENOMEM; \
(req)->new_path = (req)->path + path_len; \
memcpy((void*) (req)->path, (path), path_len); \
memcpy((void*) (req)->new_path, (new_path), new_path_len); \
dst->st_mtim.tv_nsec = src->st_mtimespec.tv_nsec;
dst->st_ctim.tv_sec = src->st_ctimespec.tv_sec;
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)
dst->st_atim.tv_sec = src->st_atim.tv_sec;
dst->st_atim.tv_nsec = src->st_atim.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_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
dst->st_atim.tv_sec = src->st_atime;
dst->st_atim.tv_nsec = 0;
dst->st_mtim.tv_nsec = 0;
dst->st_ctim.tv_sec = src->st_ctime;
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
}
}
while (r == -1 && errno == EINTR && retry_on_eintr);
- req->errorno = errno;
- req->result = r;
+ if (r == -1)
+ req->result = -errno;
+ else
+ req->result = r;
if (r == 0 && (req->fs_type == UV_FS_STAT ||
req->fs_type == UV_FS_FSTAT ||
req = container_of(w, uv_fs_t, work_req);
uv__req_unregister(req->loop, req);
- if (req->errorno != 0) {
- req->errorno = uv_translate_sys_error(req->errorno);
- uv__set_artificial_error(req->loop, req->errorno);
- }
-
- if (status == -UV_ECANCELED) {
- assert(req->errorno == 0);
- req->errorno = UV_ECANCELED;
- uv__set_artificial_error(req->loop, UV_ECANCELED);
+ if (status == -ECANCELED) {
+ assert(req->result == 0);
+ req->result = -ECANCELED;
}
if (req->cb != NULL)
*/
handle->cf_cb = malloc(sizeof(*handle->cf_cb));
if (handle->cf_cb == NULL)
- return uv__set_sys_error(handle->loop, ENOMEM);
+ return -ENOMEM;
handle->cf_cb->data = handle;
uv_async_init(handle->loop, handle->cf_cb, uv__fsevents_cb);
int uv__fsevents_close(uv_fs_event_t* handle) {
if (handle->cf_eventstream == NULL)
- return -1;
+ return -EINVAL;
/* Ensure that event stream was scheduled */
uv_sem_wait(&handle->cf_sem);
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->service,
- req->hints,
- &req->res);
+ req = container_of(w, uv_getaddrinfo_t, work_req);
+ err = getaddrinfo(req->hostname, req->service, req->hints, &req->res);
+ req->retcode = uv__getaddrinfo_translate_error(err);
}
static void uv__getaddrinfo_done(struct uv__work* w, int status) {
uv_getaddrinfo_t* req;
struct addrinfo *res;
- size_t hostlen;
req = container_of(w, uv_getaddrinfo_t, work_req);
uv__req_unregister(req->loop, req);
res = req->res;
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(). */
if (req->hints)
free(req->hints);
req->service = NULL;
req->hostname = NULL;
- if (status == -UV_ECANCELED) {
+ if (status == -ECANCELED) {
assert(req->retcode == 0);
- req->retcode = UV_ECANCELED;
- 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->retcode = UV_EAI_CANCELED;
}
- req->cb(req, -1, res);
+ req->cb(req, req->retcode, res);
}
char* buf;
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;
service_len = service ? strlen(service) + 1 : 0;
buf = malloc(hostname_len + service_len + hints_len);
if (buf == NULL)
- return uv__set_artificial_error(loop, UV_ENOMEM);
+ return -ENOMEM;
uv__req_init(loop, req, UV_GETADDRINFO);
req->loop = loop;
void uv__run_check(uv_loop_t* loop);
void uv__run_prepare(uv_loop_t* loop);
-/* error */
-uv_err_code uv_translate_sys_error(int sys_errno);
-
/* stream */
void uv__stream_init(uv_loop_t* loop, uv_stream_t* stream,
uv_handle_type type);
int uv__kqueue_init(uv_loop_t* loop) {
loop->backend_fd = kqueue();
-
if (loop->backend_fd == -1)
- return -1;
+ return -errno;
uv__cloexec(loop->backend_fd, 1);
int fd;
/* TODO open asynchronously - but how do we report back errors? */
- if ((fd = open(filename, O_RDONLY)) == -1) {
- uv__set_sys_error(loop, errno);
- return -1;
- }
+ fd = open(filename, O_RDONLY);
+ if (fd == -1)
+ return -errno;
uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT);
uv__handle_start(handle); /* FIXME shouldn't start automatically */
loop->inotify_watchers = NULL;
if (fd == -1)
- return -1;
+ return -errno;
return 0;
}
int uv_exepath(char* buffer, size_t* size) {
ssize_t n;
- if (!buffer || !size) {
- return -1;
- }
+ if (buffer == NULL || size == NULL)
+ return -EINVAL;
n = readlink("/proc/self/exe", buffer, *size - 1);
- if (n <= 0) return -1;
+ if (n == -1)
+ return -errno;
+
buffer[n] = '\0';
*size = n;
}
-uv_err_t uv_resident_set_memory(size_t* rss) {
+int uv_resident_set_memory(size_t* rss) {
char buf[1024];
const char* s;
ssize_t n;
while (fd == -1 && errno == EINTR);
if (fd == -1)
- return uv__new_sys_error(errno);
+ return -errno;
do
n = read(fd, buf, sizeof(buf) - 1);
SAVE_ERRNO(close(fd));
if (n == -1)
- return uv__new_sys_error(errno);
+ return -errno;
buf[n] = '\0';
s = strchr(buf, ' ');
goto err;
*rss = val * getpagesize();
- return uv_ok_;
+ return 0;
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;
struct timespec now;
int r;
}
if (r)
- return uv__new_sys_error(errno);
+ return -errno;
*uptime = now.tv_sec;
*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;
uv_cpu_info_t* ci;
+ int err;
*cpu_infos = NULL;
*count = 0;
ci = calloc(numcpus, sizeof(*ci));
if (ci == NULL)
- return uv__new_sys_error(ENOMEM);
+ return -ENOMEM;
- if (read_models(numcpus, ci)) {
- SAVE_ERRNO(uv_free_cpu_info(ci, numcpus));
- return uv__new_sys_error(errno);
- }
+ err = read_models(numcpus, ci);
+ if (err == 0)
+ err = read_times(numcpus, ci);
- if (read_times(numcpus, ci)) {
- SAVE_ERRNO(uv_free_cpu_info(ci, numcpus));
- return uv__new_sys_error(errno);
+ if (err) {
+ uv_free_cpu_info(ci, numcpus);
+ return err;
}
/* read_models() on x86 also reads the CPU speed from /proc/cpuinfo.
*cpu_infos = ci;
*count = numcpus;
- return uv_ok_;
+ return 0;
}
defined(__x86_64__)
fp = fopen("/proc/cpuinfo", "r");
if (fp == NULL)
- return -1;
+ return -errno;
while (fgets(buf, sizeof(buf), fp)) {
if (model_idx < numcpus) {
model = strndup(model, strlen(model) - 1); /* Strip newline. */
if (model == NULL) {
fclose(fp);
- return -1;
+ return -ENOMEM;
}
ci[model_idx++].model = model;
continue;
model = strndup(model, strlen(model) - 1); /* Strip newline. */
if (model == NULL) {
fclose(fp);
- return -1;
+ return -ENOMEM;
}
ci[model_idx++].model = model;
continue;
while (model_idx < numcpus) {
model = strndup(inferred_model, strlen(inferred_model));
if (model == NULL)
- return -1;
+ return -ENOMEM;
ci[model_idx++].model = model;
}
fp = fopen("/proc/stat", "r");
if (fp == NULL)
- return -1;
+ return -errno;
if (!fgets(buf, sizeof(buf), fp))
abort();
}
-uv_err_t uv_interface_addresses(uv_interface_address_t** addresses,
+int uv_interface_addresses(uv_interface_address_t** addresses,
int* count) {
#ifndef HAVE_IFADDRS_H
- return uv__new_artificial_error(UV_ENOSYS);
+ return -ENOSYS;
#else
struct ifaddrs *addrs, *ent;
char ip[INET6_ADDRSTRLEN];
uv_interface_address_t* address;
- if (getifaddrs(&addrs) != 0) {
- return uv__new_sys_error(errno);
- }
+ if (getifaddrs(&addrs))
+ return -errno;
*count = 0;
(*count)++;
}
- *addresses = (uv_interface_address_t*)
- malloc(*count * sizeof(uv_interface_address_t));
- if (!(*addresses)) {
- return uv__new_artificial_error(UV_ENOMEM);
- }
+ *addresses = malloc(*count * sizeof(**addresses));
+ if (!(*addresses))
+ return -ENOMEM;
address = *addresses;
freeifaddrs(addrs);
- return uv_ok_;
+ return 0;
#endif
}
static int new_inotify_fd(void) {
+ int err;
int fd;
fd = uv__inotify_init1(UV__IN_NONBLOCK | UV__IN_CLOEXEC);
if (fd != -1)
return fd;
+
if (errno != ENOSYS)
- return -1;
+ return -errno;
+
+ fd = uv__inotify_init();
+ if (fd == -1)
+ return -errno;
- if ((fd = uv__inotify_init()) == -1)
- return -1;
+ err = uv__cloexec(fd, 1);
+ if (err == 0)
+ err = uv__nonblock(fd, 1);
- if (uv__cloexec(fd, 1) || uv__nonblock(fd, 1)) {
- SAVE_ERRNO(close(fd));
- return -1;
+ if (err) {
+ close(fd);
+ return err;
}
return fd;
static int init_inotify(uv_loop_t* loop) {
+ int err;
+
if (loop->inotify_fd != -1)
return 0;
- loop->inotify_fd = new_inotify_fd();
- if (loop->inotify_fd == -1) {
- uv__set_sys_error(loop, errno);
- return -1;
- }
+ err = new_inotify_fd();
+ if (err < 0)
+ return err;
+ loop->inotify_fd = err;
uv__io_init(&loop->inotify_read_watcher, uv__inotify_read, loop->inotify_fd);
uv__io_start(loop, &loop->inotify_read_watcher, UV__POLLIN);
int flags) {
struct watcher_list* w;
int events;
+ int err;
int wd;
- if (init_inotify(loop)) return -1;
+ err = init_inotify(loop);
+ if (err)
+ return err;
events = UV__IN_ATTRIB
| UV__IN_CREATE
wd = uv__inotify_add_watch(loop->inotify_fd, path, events);
if (wd == -1)
- return uv__set_sys_error(loop, errno);
+ return -errno;
w = find_watcher(loop, wd);
if (w)
w = malloc(sizeof(*w) + strlen(path) + 1);
if (w == NULL)
- return uv__set_sys_error(loop, ENOMEM);
+ return -ENOMEM;
w->wd = wd;
w->path = strcpy((char*)(w + 1), path);
\
int uv_##name##_start(uv_##name##_t* handle, uv_##name##_cb cb) { \
if (uv__is_active(handle)) return 0; \
- if (cb == NULL) \
- return uv__set_artificial_error(handle->loop, UV_EINVAL); \
+ if (cb == NULL) return -EINVAL; \
QUEUE_INSERT_HEAD(&handle->loop->name##_handles, &handle->queue); \
handle->name##_cb = cb; \
uv__handle_start(handle); \
int uv__loop_init(uv_loop_t* loop, int default_loop) {
unsigned int i;
+ int err;
uv__signal_global_once_init();
loop->timer_counter = 0;
loop->stop_flag = 0;
- if (uv__platform_loop_init(loop, default_loop))
- return -1;
+ err = uv__platform_loop_init(loop, default_loop);
+ if (err)
+ return err;
uv_signal_init(loop, &loop->child_watcher);
uv__handle_unref(&loop->child_watcher);
size_t cb;
pid_t mypid;
- if (!buffer || !size) {
- return -1;
- }
+ if (buffer == NULL || size == NULL)
+ return -EINVAL;
mypid = getpid();
mib[0] = CTL_KERN;
mib[3] = KERN_PROC_ARGV;
cb = *size;
- if (sysctl(mib, 4, buffer, &cb, NULL, 0) == -1) {
- *size = 0;
- return -1;
- }
+ if (sysctl(mib, 4, buffer, &cb, NULL, 0))
+ return -errno;
*size = strlen(buffer);
return 0;
size_t size = sizeof(info);
int which[] = {CTL_VM, VM_UVMEXP};
- if (sysctl(which, 2, &info, &size, NULL, 0) == -1) {
- return -1;
- }
+ if (sysctl(which, 2, &info, &size, NULL, 0))
+ return -errno;
return (uint64_t) info.free * sysconf(_SC_PAGESIZE);
}
#endif
size_t size = sizeof(info);
- if (sysctl(which, 2, &info, &size, NULL, 0) == -1) {
- return -1;
- }
+ if (sysctl(which, 2, &info, &size, NULL, 0))
+ return -errno;
return (uint64_t) info;
}
}
-uv_err_t uv_set_process_title(const char* title) {
+int uv_set_process_title(const char* title) {
if (process_title) free(process_title);
process_title = strdup(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) {
strncpy(buffer, process_title, size);
} else {
}
}
- 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;
struct kinfo_proc2 *kinfo = NULL;
pid_t pid;
kvm_close(kd);
- return uv_ok_;
+ return 0;
error:
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;
struct timeval info;
size_t size = sizeof(info);
static int which[] = {CTL_KERN, KERN_BOOTTIME};
- if (sysctl(which, 2, &info, &size, NULL, 0) == -1) {
- return uv__new_sys_error(errno);
- }
+ if (sysctl(which, 2, &info, &size, NULL, 0))
+ return -errno;
now = time(NULL);
*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 multiplier = ((uint64_t)1000L / ticks);
unsigned int cur = 0;
int i;
size = sizeof(model);
- if (sysctlbyname("machdep.cpu_brand", &model, &size, NULL, 0) == -1 &&
- sysctlbyname("hw.model", &model, &size, NULL, 0) == -1) {
- return uv__new_sys_error(errno);
+ if (sysctlbyname("machdep.cpu_brand", &model, &size, NULL, 0) &&
+ sysctlbyname("hw.model", &model, &size, NULL, 0)) {
+ return -errno;
}
size = sizeof(numcpus);
- if (sysctlbyname("hw.ncpu", &numcpus, &size, NULL, 0) == -1) {
- return uv__new_sys_error(errno);
- }
+ if (sysctlbyname("hw.ncpu", &numcpus, &size, NULL, 0))
+ return -errno;
*count = numcpus;
/* Only i386 and amd64 have machdep.tsc_freq */
size = sizeof(cpuspeed);
- if (sysctlbyname("machdep.tsc_freq", &cpuspeed, &size, NULL, 0) == -1) {
+ if (sysctlbyname("machdep.tsc_freq", &cpuspeed, &size, NULL, 0))
cpuspeed = 0;
- }
size = numcpus * CPUSTATES * sizeof(*cp_times);
cp_times = malloc(size);
- if (cp_times == NULL) {
- return uv__new_artificial_error(UV_ENOMEM);
- }
- if (sysctlbyname("kern.cp_time", cp_times, &size, NULL, 0) == -1) {
- return uv__new_sys_error(errno);
- }
+ if (cp_times == NULL)
+ return -ENOMEM;
+
+ if (sysctlbyname("kern.cp_time", cp_times, &size, NULL, 0))
+ return -errno;
*cpu_infos = malloc(numcpus * sizeof(**cpu_infos));
if (!(*cpu_infos)) {
free(cp_times);
free(*cpu_infos);
- return uv__new_artificial_error(UV_ENOMEM);
+ return -ENOMEM;
}
for (i = 0; i < numcpus; i++) {
cur += CPUSTATES;
}
free(cp_times);
- return uv_ok_;
+ return 0;
}
+
void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
int i;
}
-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 *ent;
uv_interface_address_t* address;
- if (getifaddrs(&addrs) != 0) {
- return uv__new_sys_error(errno);
- }
+ if (getifaddrs(&addrs))
+ return -errno;
*count = 0;
*addresses = malloc(*count * sizeof(**addresses));
- if (!(*addresses)) {
- return uv__new_artificial_error(UV_ENOMEM);
- }
+ if (!(*addresses))
+ return -ENOMEM;
address = *addresses;
freeifaddrs(addrs);
- return uv_ok_;
+ return 0;
}
size_t argsbuf_size = 100U;
size_t exepath_size;
pid_t mypid;
- int status = -1;
+ int err;
+
+ if (buffer == NULL || size == NULL)
+ return -EINVAL;
- if (!buffer || !size) {
- goto out;
- }
mypid = getpid();
for (;;) {
- if ((argsbuf_tmp = realloc(argsbuf, argsbuf_size)) == NULL) {
+ err = -ENOMEM;
+ argsbuf_tmp = realloc(argsbuf, argsbuf_size);
+ if (argsbuf_tmp == NULL)
goto out;
- }
argsbuf = argsbuf_tmp;
mib[0] = CTL_KERN;
mib[1] = KERN_PROC_ARGS;
break;
}
if (errno != ENOMEM) {
+ err = -errno;
goto out;
}
argsbuf_size *= 2U;
}
if (argsbuf[0] == NULL) {
+ err = -EINVAL; /* FIXME(bnoordhuis) More appropriate error. */
goto out;
}
exepath_size = strlen(argsbuf[0]);
if (exepath_size >= *size) {
+ err = -EINVAL;
goto out;
}
memcpy(buffer, argsbuf[0], exepath_size + 1U);
*size = exepath_size;
- status = 0;
+ err = 0;
out:
free(argsbuf);
- return status;
+ return err;
}
size_t size = sizeof(info);
int which[] = {CTL_VM, VM_UVMEXP};
- if (sysctl(which, 2, &info, &size, NULL, 0) < 0) {
- return -1;
- }
+ if (sysctl(which, 2, &info, &size, NULL, 0))
+ return -errno;
return (uint64_t) info.free * sysconf(_SC_PAGESIZE);
}
int which[] = {CTL_HW, HW_PHYSMEM64};
size_t size = sizeof(info);
- if (sysctl(which, 2, &info, &size, NULL, 0) < 0) {
- return -1;
- }
+ if (sysctl(which, 2, &info, &size, NULL, 0))
+ return -errno;
return (uint64_t) info;
}
}
-uv_err_t uv_set_process_title(const char* title) {
+int uv_set_process_title(const char* title) {
if (process_title) free(process_title);
process_title = strdup(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) {
strncpy(buffer, process_title, size);
} else {
}
}
- 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;
struct kinfo_proc *kinfo = NULL;
pid_t pid;
kvm_close(kd);
- return uv_ok_;
+ return 0;
error:
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;
struct timeval info;
size_t size = sizeof(info);
static int which[] = {CTL_KERN, KERN_BOOTTIME};
- if (sysctl(which, 2, &info, &size, NULL, 0) < 0) {
- return uv__new_sys_error(errno);
- }
+ if (sysctl(which, 2, &info, &size, NULL, 0))
+ return -errno;
now = time(NULL);
*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),
multiplier = ((uint64_t)1000L / ticks), cpuspeed;
uint64_t info[CPUSTATES];
uv_cpu_info_t* cpu_info;
size = sizeof(model);
- if (sysctl(which, 2, &model, &size, NULL, 0) < 0) {
- return uv__new_sys_error(errno);
- }
+ if (sysctl(which, 2, &model, &size, NULL, 0))
+ return -errno;
+
which[1] = HW_NCPU;
size = sizeof(numcpus);
- if (sysctl(which, 2, &numcpus, &size, NULL, 0) < 0) {
- return uv__new_sys_error(errno);
- }
+ if (sysctl(which, 2, &numcpus, &size, NULL, 0))
+ return -errno;
- *cpu_infos = (uv_cpu_info_t*)malloc(numcpus * sizeof(uv_cpu_info_t));
- if (!(*cpu_infos)) {
- return uv__new_artificial_error(UV_ENOMEM);
- }
+ *cpu_infos = malloc(numcpus * sizeof(**cpu_infos));
+ if (!(*cpu_infos))
+ return -ENOMEM;
*count = numcpus;
which[1] = HW_CPUSPEED;
size = sizeof(cpuspeed);
- if (sysctl(which, 2, &cpuspeed, &size, NULL, 0) < 0) {
- free(*cpu_infos);
- return uv__new_sys_error(errno);
+ if (sysctl(which, 2, &cpuspeed, &size, NULL, 0)) {
+ SAVE_ERRNO(free(*cpu_infos));
+ return -errno;
}
size = sizeof(info);
for (i = 0; i < numcpus; i++) {
which[2] = i;
size = sizeof(info);
- if (sysctl(which, 3, &info, &size, NULL, 0) < 0) {
- free(*cpu_infos);
- return uv__new_sys_error(errno);
+ if (sysctl(which, 3, &info, &size, NULL, 0)) {
+ SAVE_ERRNO(free(*cpu_infos));
+ return -errno;
}
cpu_info = &(*cpu_infos)[i];
cpu_info->speed = cpuspeed;
}
- return uv_ok_;
+ return 0;
}
}
-uv_err_t uv_interface_addresses(uv_interface_address_t** addresses,
+int uv_interface_addresses(uv_interface_address_t** addresses,
int* count) {
/* TODO: implement */
*addresses = NULL;
*count = 0;
- return uv_ok_;
+ return 0;
}
struct sockaddr_un saddr;
const char* pipe_fname;
int sockfd;
- int status;
int bound;
+ int err;
pipe_fname = NULL;
sockfd = -1;
- status = -1;
bound = 0;
+ err = -EINVAL;
/* Already bound? */
- if (uv__stream_fd(handle) >= 0) {
- uv__set_artificial_error(handle->loop, UV_EINVAL);
- goto out;
- }
+ if (uv__stream_fd(handle) >= 0)
+ return -EINVAL;
/* Make a copy of the file name, it outlives this function's scope. */
- if ((pipe_fname = strdup(name)) == NULL) {
- uv__set_sys_error(handle->loop, ENOMEM);
+ pipe_fname = strdup(name);
+ if (pipe_fname == NULL) {
+ err = -ENOMEM;
goto out;
}
/* We've got a copy, don't touch the original any more. */
name = NULL;
- if ((sockfd = uv__socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
- uv__set_sys_error(handle->loop, errno);
+ err = uv__socket(AF_UNIX, SOCK_STREAM, 0);
+ if (err < 0)
goto out;
- }
+ sockfd = err;
memset(&saddr, 0, sizeof saddr);
uv_strlcpy(saddr.sun_path, pipe_fname, sizeof(saddr.sun_path));
saddr.sun_family = AF_UNIX;
if (bind(sockfd, (struct sockaddr*)&saddr, sizeof saddr)) {
+ err = -errno;
/* 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;
}
bound = 1;
/* Success. */
handle->pipe_fname = pipe_fname; /* Is a strdup'ed copy. */
handle->io_watcher.fd = sockfd;
- status = 0;
+ return 0;
out:
- /* Clean up on error. */
- if (status) {
- if (bound) {
- /* unlink() before close() to avoid races. */
- assert(pipe_fname != NULL);
- unlink(pipe_fname);
- }
- close(sockfd);
-
- free((void*)pipe_fname);
+ if (bound) {
+ /* unlink() before close() to avoid races. */
+ assert(pipe_fname != NULL);
+ unlink(pipe_fname);
}
-
- return status;
+ close(sockfd);
+ free((void*)pipe_fname);
+ return err;
}
int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) {
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))
- return uv__set_sys_error(handle->loop, errno);
+ return -errno;
handle->connection_cb = cb;
handle->io_watcher.cb = uv__pipe_accept;
int uv_pipe_open(uv_pipe_t* handle, uv_file fd) {
#if defined(__APPLE__)
- if (uv__stream_try_select((uv_stream_t*) handle, &fd))
- return -1;
+ int err;
+
+ err = uv__stream_try_select((uv_stream_t*) handle, &fd);
+ if (err)
+ return err;
#endif /* defined(__APPLE__) */
return uv__stream_open((uv_stream_t*)handle,
int r;
new_sock = (uv__stream_fd(handle) == -1);
- err = -1;
+ err = -EINVAL;
- if (new_sock)
- if ((handle->io_watcher.fd = uv__socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
+ if (new_sock) {
+ err = uv__socket(AF_UNIX, SOCK_STREAM, 0);
+ if (err < 0)
goto out;
+ handle->io_watcher.fd = err;
+ }
memset(&saddr, 0, sizeof saddr);
uv_strlcpy(saddr.sun_path, name, sizeof(saddr.sun_path));
}
while (r == -1 && errno == EINTR);
- if (r == -1)
- if (errno != EINPROGRESS)
- 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;
+ if (r == -1 && errno != EINPROGRESS) {
+ err = -errno;
+ goto out;
+ }
- uv__io_start(handle->loop, &handle->io_watcher, UV__POLLIN | UV__POLLOUT);
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:
- handle->delayed_error = err ? errno : 0; /* Passed to callback. */
+ handle->delayed_error = err;
handle->connect_req = req;
uv__req_init(handle->loop, req, UV_CONNECT);
QUEUE_INIT(&req->queue);
/* Force callback to run on next tick in case of error. */
- if (err != 0)
+ if (err)
uv__io_feed(handle->loop, &handle->io_watcher);
/* Mimic the Windows pipe implementation, always
sockfd = uv__accept(uv__stream_fd(pipe));
if (sockfd == -1) {
- if (errno != EAGAIN && errno != EWOULDBLOCK) {
- uv__set_sys_error(pipe->loop, errno);
- pipe->connection_cb((uv_stream_t*)pipe, -1);
- }
- } else {
- pipe->accepted_fd = sockfd;
- pipe->connection_cb((uv_stream_t*)pipe, 0);
- if (pipe->accepted_fd == sockfd) {
- /* The user hasn't called uv_accept() yet */
- uv__io_stop(pipe->loop, &pipe->io_watcher, UV__POLLIN);
- }
+ if (errno != EAGAIN && errno != EWOULDBLOCK)
+ pipe->connection_cb((uv_stream_t*)pipe, -errno);
+ return;
+ }
+
+ pipe->accepted_fd = sockfd;
+ pipe->connection_cb((uv_stream_t*)pipe, 0);
+ if (pipe->accepted_fd == sockfd) {
+ /* The user hasn't called uv_accept() yet */
+ uv__io_stop(pipe->loop, &pipe->io_watcher, UV__POLLIN);
}
}
if (events & UV__POLLERR) {
uv__io_stop(loop, w, UV__POLLIN | UV__POLLOUT);
uv__handle_stop(handle);
- uv__set_sys_error(handle->loop, EBADF);
- handle->poll_cb(handle, -1, 0);
+ handle->poll_cb(handle, -EBADF, 0);
return;
}
if (WIFSIGNALED(status))
term_signal = WTERMSIG(status);
- if (process->errorno) {
- uv__set_sys_error(process->loop, process->errorno);
- exit_status = -1; /* execve() failed */
- }
+ if (process->errorno)
+ exit_status = process->errorno; /* execve() failed */
process->exit_cb(process, exit_status, term_signal);
}
* Anything else is a genuine error.
*/
if (errno != EINVAL)
- return -1;
+ return -errno;
no_cloexec = 1;
#endif
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds))
- return -1;
+ return -errno;
uv__cloexec(fds[0], 1);
uv__cloexec(fds[1], 1);
return 0;
if (errno != ENOSYS)
- return -1;
+ return -errno;
no_pipe2 = 1;
#endif
if (pipe(fds))
- return -1;
+ return -errno;
uv__cloexec(fds[0], 1);
uv__cloexec(fds[1], 1);
case UV_CREATE_PIPE:
assert(container->data.stream != NULL);
- if (container->data.stream->type != UV_NAMED_PIPE) {
- errno = EINVAL;
- return -1;
- }
- return uv__make_socketpair(fds, 0);
+ if (container->data.stream->type != UV_NAMED_PIPE)
+ return -EINVAL;
+ else
+ return uv__make_socketpair(fds, 0);
case UV_INHERIT_FD:
case UV_INHERIT_STREAM:
else
fd = uv__stream_fd(container->data.stream);
- if (fd == -1) {
- errno = EINVAL;
- return -1;
- }
+ if (fd == -1)
+ return -EINVAL;
fds[1] = fd;
return 0;
default:
assert(0 && "Unexpected flags");
- return -1;
+ return -EINVAL;
}
}
use_fd = open("/dev/null", fd == 0 ? O_RDONLY : O_RDWR);
if (use_fd == -1) {
- uv__write_int(error_fd, errno);
+ uv__write_int(error_fd, -errno);
perror("failed to open stdio");
_exit(127);
}
}
if (options.cwd && chdir(options.cwd)) {
- uv__write_int(error_fd, errno);
+ uv__write_int(error_fd, -errno);
perror("chdir()");
_exit(127);
}
if ((options.flags & UV_PROCESS_SETGID) && setgid(options.gid)) {
- uv__write_int(error_fd, errno);
+ uv__write_int(error_fd, -errno);
perror("setgid()");
_exit(127);
}
if ((options.flags & UV_PROCESS_SETUID) && setuid(options.uid)) {
- uv__write_int(error_fd, errno);
+ uv__write_int(error_fd, -errno);
perror("setuid()");
_exit(127);
}
}
execvp(options.file, options.args);
- uv__write_int(error_fd, errno);
+ uv__write_int(error_fd, -errno);
perror("execvp()");
_exit(127);
}
QUEUE* q;
ssize_t r;
pid_t pid;
+ int err;
int i;
assert(options.file != NULL);
if (stdio_count < 3)
stdio_count = 3;
+ err = -ENOMEM;
pipes = malloc(stdio_count * sizeof(*pipes));
- if (pipes == NULL) {
- errno = ENOMEM;
+ if (pipes == NULL)
goto error;
- }
for (i = 0; i < stdio_count; i++) {
pipes[i][0] = -1;
pipes[i][1] = -1;
}
- for (i = 0; i < options.stdio_count; i++)
- if (uv__process_init_stdio(options.stdio + i, pipes[i]))
+ for (i = 0; i < options.stdio_count; i++) {
+ err = uv__process_init_stdio(options.stdio + i, pipes[i]);
+ if (err)
goto error;
+ }
/* This pipe is used by the parent to wait until
* the child has called `execve()`. We need this
* marked close-on-exec. Then, after the call to `fork()`,
* 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;
uv_signal_start(&loop->child_watcher, uv__chld, SIGCHLD);
pid = fork();
if (pid == -1) {
+ err = -errno;
close(signal_pipe[0]);
close(signal_pipe[1]);
goto error;
close(signal_pipe[0]);
for (i = 0; i < options.stdio_count; i++) {
- if (uv__process_open_stream(options.stdio + i, pipes[i], i == 0)) {
- while (i--) uv__process_close_stream(options.stdio + i);
- goto error;
- }
+ err = uv__process_open_stream(options.stdio + i, pipes[i], i == 0);
+ if (err == 0)
+ continue;
+
+ while (i--)
+ uv__process_close_stream(options.stdio + i);
+
+ goto error;
}
q = uv__process_queue(loop, pid);
return 0;
error:
- uv__set_sys_error(process->loop, errno);
-
for (i = 0; i < stdio_count; i++) {
close(pipes[i][0]);
close(pipes[i][1]);
}
free(pipes);
- return -1;
+ return err;
}
int uv_process_kill(uv_process_t* process, int signum) {
- int r = kill(process->pid, signum);
-
- if (r) {
- uv__set_sys_error(process->loop, errno);
- return -1;
- } else {
- return 0;
- }
+ return uv_kill(process->pid, signum);
}
-uv_err_t uv_kill(int pid, int signum) {
- int r = kill(pid, signum);
-
- if (r) {
- return uv__new_sys_error(errno);
- } else {
- return uv_ok_;
- }
+int uv_kill(int pid, int signum) {
+ if (kill(pid, signum))
+ return -errno;
+ else
+ return 0;
}
}
-uv_err_t uv_set_process_title(const char* title) {
+int uv_set_process_title(const char* title) {
if (process_title.len == 0)
- return uv_ok_;
+ return 0;
/* No need to terminate, byte after is always '\0'. */
strncpy(process_title.str, title, process_title.len);
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)
strncpy(buffer, process_title.str, size);
else if (size > 0)
buffer[0] = '\0';
- return uv_ok_;
+ return 0;
}
}
-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. */
struct sigaction sa;
/* XXX save old action so we can restore it later on? */
if (sigaction(signum, &sa, NULL))
- return uv__new_sys_error(errno);
+ return -errno;
- return uv_ok_;
+ return 0;
}
static int uv__signal_loop_once_init(uv_loop_t* loop) {
+ int err;
+
/* Return if already initialized. */
if (loop->signal_pipefd[0] != -1)
return 0;
- if (uv__make_pipe(loop->signal_pipefd, UV__F_NONBLOCK))
- return -1;
+ err = uv__make_pipe(loop->signal_pipefd, UV__F_NONBLOCK);
+ if (err)
+ return err;
uv__io_init(&loop->signal_io_watcher,
uv__signal_event,
int uv_signal_init(uv_loop_t* loop, uv_signal_t* handle) {
- if (uv__signal_loop_once_init(loop))
- return uv__set_sys_error(loop, errno);
+ int err;
+
+ err = uv__signal_loop_once_init(loop);
+ if (err)
+ return err;
uv__handle_init(loop, (uv_handle_t*) handle, UV_SIGNAL);
handle->signum = 0;
int uv_signal_start(uv_signal_t* handle, uv_signal_cb signal_cb, int signum) {
sigset_t saved_sigmask;
+ int err;
assert(!(handle->flags & (UV_CLOSING | UV_CLOSED)));
* signum is otherwise invalid then uv__signal_register will find out
* eventually.
*/
- if (signum == 0) {
- uv__set_artificial_error(handle->loop, UV_EINVAL);
- return -1;
- }
+ if (signum == 0)
+ return -EINVAL;
/* Short circuit: if the signal watcher is already watching {signum} don't
* go through the process of deregistering and registering the handler.
* any of the loops), it's time to try and register a handler for it here.
*/
if (uv__signal_first_handle(signum) == NULL) {
- uv_err_t err = uv__signal_register_handler(signum);
- if (err.code != UV_OK) {
+ err = uv__signal_register_handler(signum);
+ if (err) {
/* Registering the signal handler failed. Must be an invalid signal. */
- handle->loop->last_err = err;
uv__signal_unlock_and_unblock(&saved_sigmask);
- return -1;
+ return err;
}
}
/* Used by the accept() EMFILE party trick. */
static int uv__open_cloexec(const char* path, int flags) {
+ int err;
int fd;
#if defined(__linux__)
return fd;
if (errno != EINVAL)
- return -1;
+ return -errno;
/* O_CLOEXEC not supported. */
#endif
fd = open(path, flags);
- if (fd != -1)
- uv__cloexec(fd, 1);
+ if (fd == -1)
+ return -errno;
+
+ err = uv__cloexec(fd, 1);
+ if (err) {
+ close(fd);
+ return err;
+ }
return fd;
}
void uv__stream_init(uv_loop_t* loop,
uv_stream_t* stream,
uv_handle_type type) {
+ int err;
+
uv__handle_init(loop, (uv_handle_t*)stream, type);
stream->read_cb = NULL;
stream->read2_cb = NULL;
QUEUE_INIT(&stream->write_completed_queue);
stream->write_queue_size = 0;
- if (loop->emfile_fd == -1)
- loop->emfile_fd = uv__open_cloexec("/", O_RDONLY);
+ if (loop->emfile_fd == -1) {
+ err = uv__open_cloexec("/", O_RDONLY);
+ if (err >= 0)
+ loop->emfile_fd = err;
+ }
#if defined(__APPLE__)
stream->select = NULL;
struct timespec timeout;
uv__stream_select_t* s;
int fds[2];
+ int err;
int ret;
int kq;
kq = kqueue();
if (kq == -1) {
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);
SAVE_ERRNO(close(kq));
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)
return 0;
/* At this point we definitely know that this fd won't work with kqueue */
s = malloc(sizeof(*s));
if (s == NULL)
- return uv__set_artificial_error(stream->loop, UV_ENOMEM);
+ return -ENOMEM;
s->events = 0;
s->fd = *fd;
- if (uv_async_init(stream->loop, &s->async, uv__stream_osx_select_cb)) {
- SAVE_ERRNO(free(s));
- return uv__set_sys_error(stream->loop, errno);
+ err = uv_async_init(stream->loop, &s->async, uv__stream_osx_select_cb);
+ if (err) {
+ free(s);
+ return err;
}
s->async.flags |= UV__HANDLE_INTERNAL;
uv_sem_destroy(&s->close_sem);
fatal1:
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__) */
if (stream->type == UV_TCP) {
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. */
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;
if (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, -1);
+ stream->connect_req->cb(stream->connect_req, -ECANCELED);
stream->connect_req = NULL;
}
free(req->bufs);
req->bufs = NULL;
- if (req->cb) {
- uv__set_artificial_error(req->handle->loop, UV_ECANCELED);
- req->cb(req, -1);
- }
+ if (req->cb != NULL)
+ req->cb(req, -ECANCELED);
}
while (!QUEUE_EMPTY(&stream->write_completed_queue)) {
req->bufs = NULL;
}
- if (req->cb) {
- uv__set_sys_error(stream->loop, req->error);
- req->cb(req, req->error ? -1 : 0);
- }
+ if (req->cb)
+ req->cb(req, req->error);
}
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.
* A possible reason for leaving it unchanged is that it informs the
* callee that the handle has been destroyed.
*/
uv__req_unregister(stream->loop, stream->shutdown_req);
- uv__set_artificial_error(stream->loop, UV_ECANCELED);
- stream->shutdown_req->cb(stream->shutdown_req, -1);
+ stream->shutdown_req->cb(stream->shutdown_req, -ECANCELED);
stream->shutdown_req = NULL;
}
}
int fd;
if (loop->emfile_fd == -1)
- return -1;
+ return -EMFILE;
close(loop->emfile_fd);
continue;
SAVE_ERRNO(loop->emfile_fd = uv__open_cloexec("/", O_RDONLY));
- return errno;
+ return -errno;
}
}
void uv__server_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
uv_stream_t* stream;
int err;
- int fd;
stream = container_of(w, uv_stream_t, io_watcher);
assert(events == UV__POLLIN);
return;
#endif /* defined(UV_HAVE_KQUEUE) */
- fd = uv__accept(uv__stream_fd(stream));
- if (fd == -1) {
- if (errno == EAGAIN || errno == EWOULDBLOCK)
+ err = uv__accept(uv__stream_fd(stream));
+ if (err < 0) {
+ if (err == -EAGAIN || err == -EWOULDBLOCK)
return; /* Not an error. */
- if (errno == ECONNABORTED)
+ if (err == -ECONNABORTED)
continue; /* Ignore. Nothing we can do about that. */
- if (errno == EMFILE || errno == ENFILE) {
- SAVE_ERRNO(err = uv__emfile_trick(loop, uv__stream_fd(stream)));
- if (err == EAGAIN || err == EWOULDBLOCK)
+ if (err == -EMFILE || err == -ENFILE) {
+ err = uv__emfile_trick(loop, uv__stream_fd(stream));
+ if (err == -EAGAIN || err == -EWOULDBLOCK)
break;
}
- uv__set_sys_error(loop, errno);
- stream->connection_cb(stream, -1);
+ stream->connection_cb(stream, err);
continue;
}
UV_DEC_BACKLOG(w)
- stream->accepted_fd = fd;
+ stream->accepted_fd = err;
stream->connection_cb(stream, 0);
if (stream->accepted_fd != -1) {
int uv_accept(uv_stream_t* server, uv_stream_t* client) {
+ int err;
+
/* TODO document this */
assert(server->loop == client->loop);
if (server->accepted_fd == -1)
- return uv__set_sys_error(server->loop, EAGAIN);
+ return -EAGAIN;
switch (client->type) {
case UV_NAMED_PIPE:
case UV_TCP:
- if (uv__stream_open(client,
- server->accepted_fd,
- UV_STREAM_READABLE | UV_STREAM_WRITABLE)) {
+ err = uv__stream_open(client,
+ server->accepted_fd,
+ UV_STREAM_READABLE | UV_STREAM_WRITABLE);
+ if (err) {
/* TODO handle error */
close(server->accepted_fd);
server->accepted_fd = -1;
- return -1;
+ return err;
}
break;
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);
server->accepted_fd = -1;
- return -1;
+ return err;
}
break;
int uv_listen(uv_stream_t* stream, int backlog, uv_connection_cb cb) {
- int r;
+ int err;
+ err = -EINVAL;
switch (stream->type) {
- case UV_TCP:
- r = uv_tcp_listen((uv_tcp_t*)stream, backlog, cb);
- break;
+ case UV_TCP:
+ err = uv_tcp_listen((uv_tcp_t*)stream, backlog, cb);
+ break;
- case UV_NAMED_PIPE:
- r = uv_pipe_listen((uv_pipe_t*)stream, backlog, cb);
- break;
+ case UV_NAMED_PIPE:
+ err = uv_pipe_listen((uv_pipe_t*)stream, backlog, cb);
+ break;
- default:
- assert(0);
- return -1;
+ default:
+ assert(0);
}
- if (r == 0)
+ if (err == 0)
uv__handle_start(stream);
- return r;
+ return err;
}
static void uv__drain(uv_stream_t* stream) {
uv_shutdown_t* req;
- int status;
+ int err;
assert(QUEUE_EMPTY(&stream->write_queue));
uv__io_stop(stream->loop, &stream->io_watcher, UV__POLLOUT);
stream->flags &= ~UV_STREAM_SHUTTING;
uv__req_unregister(stream->loop, req);
- status = shutdown(uv__stream_fd(stream), SHUT_WR);
- if (status)
- uv__set_sys_error(stream->loop, errno);
- else
+ err = 0;
+ if (shutdown(uv__stream_fd(stream), SHUT_WR))
+ err = -errno;
+
+ if (err == 0)
stream->flags |= UV_STREAM_SHUT;
if (req->cb != NULL)
- req->cb(req, status);
+ req->cb(req, err);
}
}
if (n < 0) {
if (errno != EAGAIN && errno != EWOULDBLOCK) {
/* Error */
- req->error = errno;
+ req->error = -errno;
uv__write_req_finish(req);
uv__io_stop(stream->loop, &stream->io_watcher, UV__POLLOUT);
if (!uv__io_active(&stream->io_watcher, UV__POLLIN))
}
/* NOTE: call callback AFTER freeing the request data. */
- if (req->cb) {
- uv__set_sys_error(stream->loop, req->error);
- req->cb(req, req->error ? -1 : 0);
- }
+ if (req->cb)
+ req->cb(req, req->error);
}
assert(QUEUE_EMPTY(&stream->write_completed_queue));
uv__io_stop(stream->loop, &stream->io_watcher, UV__POLLIN);
if (!uv__io_active(&stream->io_watcher, UV__POLLOUT))
uv__handle_stop(stream);
- uv__set_artificial_error(stream->loop, UV_EOF);
- uv__stream_read_cb(stream, -1, buf, UV_UNKNOWN_HANDLE);
+ uv__stream_read_cb(stream, UV_EOF, buf, UV_UNKNOWN_HANDLE);
}
if (stream->flags & UV_STREAM_READING) {
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);
} else {
/* Error. User should call uv_close(). */
- uv__set_sys_error(stream->loop, errno);
- uv__stream_read_cb(stream, -1, buf, UV_UNKNOWN_HANDLE);
+ uv__stream_read_cb(stream, -errno, buf, UV_UNKNOWN_HANDLE);
assert(!uv__io_active(&stream->io_watcher, UV__POLLIN) &&
"stream->read_cb(status=-1) did not call uv_close()");
}
stream->flags & UV_STREAM_SHUT ||
stream->flags & UV_CLOSED ||
stream->flags & UV_CLOSING) {
- uv__set_artificial_error(stream->loop, UV_ENOTCONN);
- return -1;
+ return -ENOTCONN;
}
/* Initialize request */
SO_ERROR,
&error,
&errorsize);
+ error = -error;
}
- if (error == EINPROGRESS)
+ if (error == -EINPROGRESS)
return;
stream->connect_req = NULL;
uv__req_unregister(stream->loop, req);
uv__io_stop(stream->loop, &stream->io_watcher, UV__POLLOUT);
- if (req->cb) {
- uv__set_sys_error(stream->loop, error);
- req->cb(req, error ? -1 : 0);
- }
+ if (req->cb)
+ req->cb(req, error);
}
"uv_write (unix) does not yet support other types of streams");
if (uv__stream_fd(stream) < 0)
- return uv__set_artificial_error(stream->loop, UV_EBADF);
+ return -EBADF;
if (send_handle) {
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.
* Don't call uv__stream_fd() on those handles, it's a macro that on OS X
* which works but only by accident.
*/
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;
stream->type == UV_TTY);
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
* expresses the desired state of the user.
int uv__platform_loop_init(uv_loop_t* loop, int default_loop) {
+ int err;
+ int fd;
+
loop->fs_fd = -1;
- loop->backend_fd = port_create();
+ loop->backend_fd = -1;
- if (loop->backend_fd == -1)
- return -1;
+ fd = port_create();
+ 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;
}
ssize_t res;
char buf[128];
- if (buffer == NULL)
- return (-1);
-
- if (size == NULL)
- return (-1);
+ if (buffer == NULL || size == NULL)
+ return -EINVAL;
(void) snprintf(buf, sizeof(buf), "/proc/%lu/path/a.out", (unsigned long) getpid());
res = readlink(buf, buffer, *size - 1);
-
- if (res < 0)
- return (res);
+ if (res == -1)
+ return -errno;
buffer[res] = '\0';
*size = res;
- return (0);
+ return 0;
}
#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)
- return;
+ return -EBADF;
if (port_associate(handle->loop->fs_fd,
PORT_SOURCE_FILE,
(uintptr_t) &handle->fo,
FILE_ATTRIB | FILE_MODIFIED,
handle) == -1) {
- uv__set_sys_error(handle->loop, errno);
+ return -errno;
}
handle->fd = PORT_LOADED;
+
+ return 0;
}
while (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. */
}
int first_run = 0;
if (loop->fs_fd == -1) {
- if ((portfd = port_create()) == -1) {
- uv__set_sys_error(loop, errno);
- return -1;
- }
+ portfd = port_create();
+ if (portfd == -1)
+ return -errno;
loop->fs_fd = portfd;
first_run = 1;
}
memset(&handle->fo, 0, sizeof handle->fo);
handle->fo.fo_name = handle->filename;
- uv__fs_event_rearm(handle);
+ uv__fs_event_rearm(handle); /* FIXME(bnoordhuis) Check return code. */
if (first_run) {
uv__io_init(&loop->fs_event_watcher, uv__fs_event_read, portfd);
const char* filename,
uv_fs_event_cb cb,
int flags) {
- uv__set_sys_error(loop, ENOSYS);
- return -1;
+ return -ENOSYS;
}
}
-uv_err_t uv_set_process_title(const char* title) {
- return uv_ok_;
+int uv_set_process_title(const char* title) {
+ 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) {
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;
- uv_err_t err;
+ int err;
int fd;
fd = open("/proc/self/psinfo", O_RDONLY);
if (fd == -1)
- return uv__new_sys_error(errno);
-
- err = uv_ok_;
+ return -errno;
- 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;
- else
- err = uv__new_sys_error(EINVAL);
-
+ err = 0;
+ }
close(fd);
return err;
}
-uv_err_t uv_uptime(double* uptime) {
+int uv_uptime(double* uptime) {
kstat_ctl_t *kc;
kstat_t *ksp;
kstat_named_t *knp;
long hz = sysconf(_SC_CLK_TCK);
- if ((kc = kstat_open()) == NULL)
- return uv__new_sys_error(errno);
+ kc = kstat_open();
+ if (kc == NULL)
+ return -EPERM;
ksp = kstat_lookup(kc, (char*) "unix", 0, (char*) "system_misc");
-
if (kstat_read(kc, ksp, NULL) == -1) {
*uptime = -1;
} else {
knp = (kstat_named_t*) kstat_data_lookup(ksp, (char*) "clk_intr");
*uptime = knp->value.ul / hz;
}
-
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;
kstat_ctl_t *kc;
kstat_t *ksp;
kstat_named_t *knp;
uv_cpu_info_t* cpu_info;
- if ((kc = kstat_open()) == NULL) {
- return uv__new_sys_error(errno);
- }
+ kc = kstat_open();
+ if (kc == NULL)
+ return -EPERM;
/* Get count of cpus */
lookup_instance = 0;
lookup_instance++;
}
- *cpu_infos = (uv_cpu_info_t*)
- malloc(lookup_instance * sizeof(uv_cpu_info_t));
+ *cpu_infos = malloc(lookup_instance * sizeof(**cpu_infos));
if (!(*cpu_infos)) {
- return uv__new_artificial_error(UV_ENOMEM);
+ kstat_close(kc);
+ return -ENOMEM;
}
*count = lookup_instance;
kstat_close(kc);
- return uv_ok_;
+ return 0;
}
}
-uv_err_t uv_interface_addresses(uv_interface_address_t** addresses,
- int* count) {
+int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
#ifdef SUNOS_NO_IFADDRS
- return uv__new_artificial_error(UV_ENOSYS);
+ return -ENOSYS;
#else
struct ifaddrs *addrs, *ent;
char ip[INET6_ADDRSTRLEN];
uv_interface_address_t* address;
- if (getifaddrs(&addrs) != 0) {
- return uv__new_sys_error(errno);
- }
+ if (getifaddrs(&addrs))
+ return -errno;
*count = 0;
(*count)++;
}
- *addresses = (uv_interface_address_t*)
- malloc(*count * sizeof(uv_interface_address_t));
- if (!(*addresses)) {
- return uv__new_artificial_error(UV_ENOMEM);
- }
+ *addresses = malloc(*count * sizeof(**addresses));
+ if (!(*addresses))
+ return -ENOMEM;
address = *addresses;
freeifaddrs(addrs);
- return uv_ok_;
+ return 0;
#endif /* SUNOS_NO_IFADDRS */
}
static int maybe_new_socket(uv_tcp_t* handle, int domain, int flags) {
int sockfd;
+ int err;
if (uv__stream_fd(handle) != -1)
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)
- return uv__set_sys_error(handle->loop, errno);
-
- if (uv__stream_open((uv_stream_t*)handle, sockfd, flags)) {
+ err = uv__stream_open((uv_stream_t*) handle, sockfd, flags);
+ if (err) {
close(sockfd);
- return -1;
+ return err;
}
return 0;
int domain,
struct sockaddr* addr,
int addrsize) {
+ int err;
int on;
- if (maybe_new_socket(tcp, domain, UV_STREAM_READABLE|UV_STREAM_WRITABLE))
- return -1;
+ err = maybe_new_socket(tcp, domain, UV_STREAM_READABLE | UV_STREAM_WRITABLE);
+ if (err)
+ return err;
on = 1;
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;
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;
}
struct sockaddr* addr,
socklen_t addrlen,
uv_connect_cb cb) {
+ int err;
int r;
assert(handle->type == UV_TCP);
- if (handle->connect_req)
- return uv__set_sys_error(handle->loop, EALREADY);
+ if (handle->connect_req != NULL)
+ return -EALREADY; /* FIXME(bnoordhuis) -EINVAL or maybe -EBUSY. */
- if (maybe_new_socket(handle,
- addr->sa_family,
- UV_STREAM_READABLE|UV_STREAM_WRITABLE)) {
- return -1;
- }
+ err = maybe_new_socket(handle,
+ addr->sa_family,
+ UV_STREAM_READABLE | UV_STREAM_WRITABLE);
+ if (err)
+ return err;
handle->delayed_error = 0;
* error. Solaris wants to report immediately--other unixes want to
* wait.
*/
- handle->delayed_error = errno;
+ handle->delayed_error = -errno;
else
- return uv__set_sys_error(handle->loop, errno);
+ return -errno;
}
uv__req_init(handle->loop, req, UV_CONNECT);
socklen_t socklen;
if (handle->delayed_error)
- return uv__set_sys_error(handle->loop, handle->delayed_error);
+ return handle->delayed_error;
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. */
socklen = (socklen_t) *namelen;
- if (getsockname(uv__stream_fd(handle), name, &socklen) == -1)
- return uv__set_sys_error(handle->loop, errno);
+ if (getsockname(uv__stream_fd(handle), name, &socklen))
+ return -errno;
*namelen = (int) socklen;
return 0;
socklen_t socklen;
if (handle->delayed_error)
- return uv__set_sys_error(handle->loop, handle->delayed_error);
+ return handle->delayed_error;
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. */
socklen = (socklen_t) *namelen;
- if (getpeername(uv__stream_fd(handle), name, &socklen) == -1)
- return uv__set_sys_error(handle->loop, errno);
+ if (getpeername(uv__stream_fd(handle), name, &socklen))
+ return -errno;
*namelen = (int) socklen;
return 0;
int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) {
static int single_accept = -1;
+ int err;
if (tcp->delayed_error)
- return uv__set_sys_error(tcp->loop, tcp->delayed_error);
+ return tcp->delayed_error;
if (single_accept == -1) {
const char* val = getenv("UV_TCP_SINGLE_ACCEPT");
if (single_accept)
tcp->flags |= UV_TCP_SINGLE_ACCEPT;
- if (maybe_new_socket(tcp, AF_INET, UV_STREAM_READABLE))
- return -1;
+ err = maybe_new_socket(tcp, AF_INET, UV_STREAM_READABLE);
+ if (err)
+ return err;
if (listen(tcp->io_watcher.fd, backlog))
- return uv__set_sys_error(tcp->loop, errno);
+ return -errno;
tcp->connection_cb = cb;
int uv__tcp_keepalive(int fd, int on, unsigned int delay) {
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on)))
- return -1;
+ return -errno;
#ifdef TCP_KEEPIDLE
if (on && setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &delay, sizeof(delay)))
- return -1;
+ return -errno;
#endif
/* Solaris/SmartOS, if you don't support keep-alive,
* 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 (on && setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE, &delay, sizeof(delay)))
- return -1;
+ return -errno;
#endif
return 0;
int uv_tcp_nodelay(uv_tcp_t* handle, int on) {
- if (uv__stream_fd(handle) != -1)
- if (uv__tcp_nodelay(uv__stream_fd(handle), on))
- return -1;
+ int err;
+
+ if (uv__stream_fd(handle) != -1) {
+ err = uv__tcp_nodelay(uv__stream_fd(handle), on);
+ if (err)
+ return err;
+ }
if (on)
handle->flags |= UV_TCP_NODELAY;
int uv_tcp_keepalive(uv_tcp_t* handle, int on, unsigned int delay) {
- if (uv__stream_fd(handle) != -1)
- if (uv__tcp_keepalive(uv__stream_fd(handle), on, delay))
- return -1;
+ int err;
+
+ if (uv__stream_fd(handle) != -1) {
+ err =uv__tcp_keepalive(uv__stream_fd(handle), on, delay);
+ if (err)
+ return err;
+ }
if (on)
handle->flags |= UV_TCP_KEEPALIVE;
#define NANOSEC ((uint64_t) 1e9)
int uv_thread_join(uv_thread_t *tid) {
- if (pthread_join(*tid, NULL))
- return -1;
- else
- return 0;
+ return -pthread_join(*tid, NULL);
}
int uv_mutex_init(uv_mutex_t* mutex) {
-#ifdef NDEBUG
- if (pthread_mutex_init(mutex, NULL))
- return -1;
- else
- return 0;
+#if defined(NDEBUG) || !defined(PTHREAD_MUTEX_ERRORCHECK)
+ return -pthread_mutex_init(mutex, NULL);
#else
pthread_mutexattr_t attr;
- int r;
+ int err;
if (pthread_mutexattr_init(&attr))
abort();
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK))
abort();
- r = pthread_mutex_init(mutex, &attr);
+ err = pthread_mutex_init(mutex, &attr);
if (pthread_mutexattr_destroy(&attr))
abort();
- return r ? -1 : 0;
+ return -err;
#endif
}
int uv_mutex_trylock(uv_mutex_t* mutex) {
- int r;
+ int err;
- r = pthread_mutex_trylock(mutex);
-
- if (r && r != EBUSY && r != EAGAIN)
+ /* FIXME(bnoordhuis) EAGAIN means recursive lock limit reached. Arguably
+ * a bug, should probably abort rather than return -EAGAIN.
+ */
+ err = pthread_mutex_trylock(mutex);
+ if (err && err != EBUSY && err != EAGAIN)
abort();
- if (r)
- return -1;
- else
- return 0;
+ return -err;
}
int uv_rwlock_init(uv_rwlock_t* rwlock) {
- if (pthread_rwlock_init(rwlock, NULL))
- return -1;
- else
- return 0;
+ return -pthread_rwlock_init(rwlock, NULL);
}
int uv_rwlock_tryrdlock(uv_rwlock_t* rwlock) {
- int r;
-
- r = pthread_rwlock_tryrdlock(rwlock);
+ int err;
- if (r && r != EBUSY && r != EAGAIN)
+ err = pthread_rwlock_tryrdlock(rwlock);
+ if (err && err != EBUSY && err != EAGAIN)
abort();
- if (r)
- return -1;
- else
- return 0;
+ return -err;
}
int uv_rwlock_trywrlock(uv_rwlock_t* rwlock) {
- int r;
+ int err;
- r = pthread_rwlock_trywrlock(rwlock);
-
- if (r && r != EBUSY && r != EAGAIN)
+ err = pthread_rwlock_trywrlock(rwlock);
+ if (err && err != EBUSY && err != EAGAIN)
abort();
- if (r)
- return -1;
- else
- return 0;
+ return -err;
}
#if defined(__APPLE__) && defined(__MACH__)
int uv_sem_init(uv_sem_t* sem, unsigned int value) {
- if (semaphore_create(mach_task_self(), sem, SYNC_POLICY_FIFO, value))
- return -1;
- else
+ kern_return_t err;
+
+ err = semaphore_create(mach_task_self(), sem, SYNC_POLICY_FIFO, value);
+ if (err == KERN_SUCCESS)
return 0;
+ if (err == KERN_INVALID_ARGUMENT)
+ return -EINVAL;
+ if (err == KERN_RESOURCE_SHORTAGE)
+ return -ENOMEM;
+
+ abort();
+ return -EINVAL; /* Satisfy the compiler. */
}
int uv_sem_trywait(uv_sem_t* sem) {
mach_timespec_t interval;
+ kern_return_t err;
interval.tv_sec = 0;
interval.tv_nsec = 0;
- if (semaphore_timedwait(*sem, interval) == KERN_SUCCESS)
+ err = semaphore_timedwait(*sem, interval);
+ if (err == KERN_SUCCESS)
return 0;
- else
- return -1;
+ if (err == KERN_OPERATION_TIMED_OUT)
+ return -EAGAIN;
+
+ abort();
+ return -EINVAL; /* Satisfy the compiler. */
}
#else /* !(defined(__APPLE__) && defined(__MACH__)) */
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;
}
r = sem_trywait(sem);
while (r == -1 && errno == EINTR);
- if (r && errno != EAGAIN)
+ if (r) {
+ if (errno == EAGAIN)
+ return -EAGAIN;
abort();
+ }
- return r;
+ return 0;
}
#endif /* defined(__APPLE__) && defined(__MACH__) */
#if defined(__APPLE__) && defined(__MACH__)
int uv_cond_init(uv_cond_t* cond) {
- if (pthread_cond_init(cond, NULL))
- return -1;
- else
- return 0;
+ return -pthread_cond_init(cond, NULL);
}
#else /* !(defined(__APPLE__) && defined(__MACH__)) */
int uv_cond_init(uv_cond_t* cond) {
pthread_condattr_t attr;
+ int err;
- if (pthread_condattr_init(&attr))
- return -1;
+ err = pthread_condattr_init(&attr);
+ if (err)
+ return -err;
#if !defined(__ANDROID__)
- if (pthread_condattr_setclock(&attr, CLOCK_MONOTONIC))
+ err = pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
+ if (err)
goto error2;
#endif
- if (pthread_cond_init(cond, &attr))
+ err = pthread_cond_init(cond, &attr);
+ if (err)
goto error2;
- if (pthread_condattr_destroy(&attr))
+ err = pthread_condattr_destroy(&attr);
+ if (err)
goto error;
return 0;
pthread_cond_destroy(cond);
error2:
pthread_condattr_destroy(&attr);
- return -1;
+ return -err;
}
#endif /* defined(__APPLE__) && defined(__MACH__) */
return 0;
if (r == ETIMEDOUT)
- return -1;
+ return -ETIMEDOUT;
abort();
- return -1; /* Satisfy the compiler. */
+ return -EINVAL; /* Satisfy the compiler. */
}
#if defined(__APPLE__) && defined(__MACH__)
int uv_barrier_init(uv_barrier_t* barrier, unsigned int count) {
+ int err;
+
barrier->n = count;
barrier->count = 0;
- if (uv_mutex_init(&barrier->mutex))
- return -1;
+ err = uv_mutex_init(&barrier->mutex);
+ if (err)
+ return -err;
- if (uv_sem_init(&barrier->turnstile1, 0))
+ err = uv_sem_init(&barrier->turnstile1, 0);
+ if (err)
goto error2;
- if (uv_sem_init(&barrier->turnstile2, 1))
+ err = uv_sem_init(&barrier->turnstile2, 1);
+ if (err)
goto error;
return 0;
uv_sem_destroy(&barrier->turnstile1);
error2:
uv_mutex_destroy(&barrier->mutex);
- return -1;
+ return -err;
}
#else /* !(defined(__APPLE__) && defined(__MACH__)) */
int uv_barrier_init(uv_barrier_t* barrier, unsigned int count) {
- if (pthread_barrier_init(barrier, NULL, count))
- return -1;
- else
- return 0;
+ return -pthread_barrier_init(barrier, NULL, count);
}
uv_mutex_unlock(&mutex);
if (!cancelled)
- return -1;
+ return -EBUSY;
w->work = uv__cancelled;
uv_mutex_lock(&loop->wq_mutex);
QUEUE_REMOVE(q);
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);
}
}
}
-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;
req = container_of(w, uv_work_t, work_req);
if (req->after_work_cb == NULL)
return;
- if (status == -UV_ECANCELED)
- uv__set_artificial_error(req->loop, UV_ECANCELED);
-
- req->after_work_cb(req, status ? -1 : 0);
+ req->after_work_cb(req, err);
}
uv_work_cb work_cb,
uv_after_work_cb after_work_cb) {
if (work_cb == NULL)
- return uv__set_artificial_error(loop, UV_EINVAL);
+ return -EINVAL;
uv__req_init(loop, req, UV_WORK);
req->loop = loop;
wreq = &((uv_work_t*) req)->work_req;
break;
default:
- return -1;
+ return -EINVAL;
}
return uv__work_cancel(loop, req, wreq);
int uv_timer_again(uv_timer_t* handle) {
if (handle->timer_cb == NULL)
- return uv__set_artificial_error(handle->loop, UV_EINVAL);
+ return -EINVAL;
if (handle->repeat) {
uv_timer_stop(handle);
uv__stream_init(loop, (uv_stream_t*)tty, UV_TTY);
#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__) */
if (readable) {
}
fatal:
- uv__set_sys_error(tty->loop, errno);
- return -1;
+ return -errno;
}
int uv_tty_get_winsize(uv_tty_t* tty, int* width, int* height) {
struct winsize ws;
- if (ioctl(uv__stream_fd(tty), TIOCGWINSZ, &ws) < 0) {
- uv__set_sys_error(tty->loop, errno);
- return -1;
- }
+ if (ioctl(uv__stream_fd(tty), TIOCGWINSZ, &ws))
+ return -errno;
*width = ws.ws_col;
*height = ws.ws_row;
free(req->bufs);
req->bufs = NULL;
- if (req->send_cb) {
- uv__set_artificial_error(handle->loop, UV_ECANCELED);
- req->send_cb(req, -1);
- }
+ if (req->send_cb != NULL)
+ req->send_cb(req, -ECANCELED);
}
/* Now tear down the handle. */
/* req->status >= 0 == bytes written
* req->status < 0 == errno
*/
- if (req->status >= 0) {
+ if (req->status >= 0)
req->send_cb(req, 0);
- }
- else {
- uv__set_sys_error(handle->loop, -req->status);
- req->send_cb(req, -1);
- }
+ else
+ req->send_cb(req, req->status);
}
}
while (nread == -1 && errno == EINTR);
if (nread == -1) {
- if (errno == EAGAIN || errno == EWOULDBLOCK) {
- uv__set_sys_error(handle->loop, EAGAIN);
+ if (errno == EAGAIN || errno == EWOULDBLOCK)
handle->recv_cb(handle, 0, buf, NULL, 0);
- }
- else {
- uv__set_sys_error(handle->loop, errno);
- handle->recv_cb(handle, -1, buf, NULL, 0);
- }
+ else
+ handle->recv_cb(handle, -errno, buf, NULL, 0);
}
else {
flags = 0;
struct sockaddr* addr,
socklen_t len,
unsigned flags) {
+ int err;
int yes;
int fd;
+ err = -EINVAL;
fd = -1;
/* Check for bad flags. */
if (flags & ~UV_UDP_IPV6ONLY)
- return uv__set_sys_error(handle->loop, EINVAL);
+ return -EINVAL;
/* Cannot set IPv6-only mode on non-IPv6 socket. */
if ((flags & UV_UDP_IPV6ONLY) && domain != AF_INET6)
- return uv__set_sys_error(handle->loop, EINVAL);
+ return -EINVAL;
fd = handle->io_watcher.fd;
if (fd == -1) {
fd = uv__socket(domain, SOCK_DGRAM, 0);
if (fd == -1)
- return uv__set_sys_error(handle->loop, errno);
+ return -errno;
handle->io_watcher.fd = fd;
}
yes = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes) == -1) {
- uv__set_sys_error(handle->loop, errno);
+ err = -errno;
goto out;
}
#ifdef SO_REUSEPORT
yes = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof yes) == -1) {
- uv__set_sys_error(handle->loop, errno);
+ err = -errno;
goto out;
}
#endif
#ifdef IPV6_V6ONLY
yes = 1;
if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &yes, sizeof yes) == -1) {
- uv__set_sys_error(handle->loop, errno);
+ err = -errno;
goto out;
}
#else
- uv__set_sys_error(handle->loop, ENOTSUP);
+ err = -ENOTSUP;
goto out;
#endif
}
if (bind(fd, addr, len) == -1) {
- uv__set_sys_error(handle->loop, errno);
+ err = -errno;
goto out;
}
out:
close(handle->io_watcher.fd);
handle->io_watcher.fd = -1;
- return -1;
+ return err;
}
struct sockaddr* addr,
socklen_t addrlen,
uv_udp_send_cb send_cb) {
+ int err;
+
assert(bufcnt > 0);
- if (uv__udp_maybe_deferred_bind(handle, addr->sa_family))
- return -1;
+ err = uv__udp_maybe_deferred_bind(handle, addr->sa_family);
+ if (err)
+ return err;
uv__req_init(handle->loop, req, UV_UDP_SEND);
req->handle = handle;
req->bufcnt = bufcnt;
- if (bufcnt <= (int) ARRAY_SIZE(req->bufsml)) {
+ if (bufcnt <= (int) ARRAY_SIZE(req->bufsml))
req->bufs = req->bufsml;
- }
- else if ((req->bufs = malloc(bufcnt * sizeof(bufs[0]))) == NULL) {
- uv__set_sys_error(handle->loop, ENOMEM);
- return -1;
- }
+ else
+ req->bufs = malloc(bufcnt * sizeof(*bufs));
+
+ if (req->bufs == NULL)
+ return -ENOMEM;
memcpy(req->bufs, bufs, bufcnt * sizeof(bufs[0]));
QUEUE_INSERT_TAIL(&handle->write_queue, &req->queue);
/* Check for already active socket. */
if (handle->io_watcher.fd != -1)
- return uv__set_artificial_error(handle->loop, UV_EALREADY);
+ return -EALREADY; /* FIXME(bnoordhuis) Should be -EBUSY. */
yes = 1;
- if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes) == -1)
- return uv__set_sys_error(handle->loop, errno);
+ if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes))
+ return -errno;
/* 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
*/
#ifdef SO_REUSEPORT
yes = 1;
- if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof yes) == -1)
- return uv__set_sys_error(handle->loop, errno);
+ if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof yes))
+ return -errno;
#endif
handle->io_watcher.fd = sock;
optname = IP_DROP_MEMBERSHIP;
break;
default:
- return uv__set_artificial_error(handle->loop, UV_EINVAL);
+ return -EINVAL;
}
if (setsockopt(handle->io_watcher.fd,
optname,
&mreq,
sizeof(mreq))) {
- return uv__set_sys_error(handle->loop, errno);
+ return -errno;
}
return 0;
#endif
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)))
- return uv__set_sys_error(handle->loop, errno);
+ return -errno;
return 0;
}
SO_BROADCAST,
&on,
sizeof(on))) {
- return uv__set_sys_error(handle->loop, errno);
+ return -errno;
}
return 0;
int uv_udp_set_ttl(uv_udp_t* handle, int ttl) {
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)))
- return uv__set_sys_error(handle->loop, errno);
+ return -errno;
return 0;
}
socklen_t socklen;
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. */
socklen = (socklen_t) *namelen;
- if (getsockname(handle->io_watcher.fd, name, &socklen) == -1)
- return uv__set_sys_error(handle->loop, errno);
+ if (getsockname(handle->io_watcher.fd, name, &socklen))
+ return -errno;
*namelen = (int) socklen;
return 0;
int uv__udp_recv_start(uv_udp_t* handle,
uv_alloc_cb alloc_cb,
uv_udp_recv_cb recv_cb) {
- if (alloc_cb == NULL || recv_cb == NULL) {
- uv__set_artificial_error(handle->loop, UV_EINVAL);
- return -1;
- }
+ int err;
- if (uv__io_active(&handle->io_watcher, UV__POLLIN)) {
- uv__set_artificial_error(handle->loop, UV_EALREADY);
- return -1;
- }
+ if (alloc_cb == NULL || recv_cb == NULL)
+ return -EINVAL;
+
+ 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))
- return -1;
+ err = uv__udp_maybe_deferred_bind(handle, AF_INET);
+ if (err)
+ return err;
handle->alloc_cb = alloc_cb;
handle->recv_cb = recv_cb;
#include <stdlib.h> /* malloc */
#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);
}
-const uv_err_t uv_ok_ = { UV_OK, 0 };
-
-#define UV_ERR_NAME_GEN(val, name, s) case UV_##name : return #name;
-const char* uv_err_name(uv_err_t err) {
- switch (err.code) {
+#define UV_ERR_NAME_GEN(name, _) case UV_ ## name: return #name;
+const char* uv_err_name(int err) {
+ switch (err) {
UV_ERRNO_MAP(UV_ERR_NAME_GEN)
default:
assert(0);
#undef UV_ERR_NAME_GEN
-#define UV_STRERROR_GEN(val, name, s) case UV_##name : return s;
-const char* uv_strerror(uv_err_t err) {
- switch (err.code) {
+#define UV_STRERROR_GEN(name, msg) case UV_ ## name: return msg;
+const char* uv_strerror(int err) {
+ switch (err) {
UV_ERRNO_MAP(UV_STRERROR_GEN)
default:
return "Unknown system error";
#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 addr;
struct sockaddr_in6 uv_ip6_addr(const char* ip, int port) {
struct sockaddr_in6 addr;
+ char address_part[40];
+ size_t address_part_size;
+ const char* zone_index;
memset(&addr, 0, sizeof(struct sockaddr_in6));
addr.sin6_family = AF_INET6;
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);
return addr;
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 err.code != UV_OK;
+ return uv_inet_ntop(AF_INET, &src->sin_addr, dst, 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 err.code != UV_OK;
+ return uv_inet_ntop(AF_INET6, &src->sin6_addr, dst, size);
}
int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr) {
if (handle->type != UV_TCP || addr.sin_family != AF_INET)
- return uv__set_artificial_error(handle->loop, UV_EINVAL);
+ return UV_EINVAL;
else
return uv__tcp_bind(handle, addr);
}
int uv_tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr) {
if (handle->type != UV_TCP || addr.sin6_family != AF_INET6)
- return uv__set_artificial_error(handle->loop, UV_EINVAL);
+ return UV_EINVAL;
else
return uv__tcp_bind6(handle, addr);
}
struct sockaddr_in addr,
unsigned int flags) {
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_bind(handle, addr, flags);
}
struct sockaddr_in6 addr,
unsigned int flags) {
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_bind6(handle, addr, flags);
}
struct sockaddr_in address,
uv_connect_cb cb) {
if (handle->type != UV_TCP || address.sin_family != AF_INET)
- return uv__set_artificial_error(handle->loop, UV_EINVAL);
+ return UV_EINVAL;
else
return uv__tcp_connect(req, handle, address, cb);
}
struct sockaddr_in6 address,
uv_connect_cb cb) {
if (handle->type != UV_TCP || address.sin6_family != AF_INET6)
- return uv__set_artificial_error(handle->loop, UV_EINVAL);
+ return UV_EINVAL;
else
return uv__tcp_connect6(req, handle, address, cb);
}
int bufcnt,
struct sockaddr_in addr,
uv_udp_send_cb send_cb) {
- if (handle->type != UV_UDP || addr.sin_family != AF_INET) {
- return uv__set_artificial_error(handle->loop, UV_EINVAL);
- }
-
- return uv__udp_send(req, handle, bufs, bufcnt, addr, send_cb);
+ if (handle->type != UV_UDP || addr.sin_family != AF_INET)
+ return UV_EINVAL;
+ else
+ return uv__udp_send(req, handle, bufs, bufcnt, addr, send_cb);
}
int bufcnt,
struct sockaddr_in6 addr,
uv_udp_send_cb send_cb) {
- if (handle->type != UV_UDP || addr.sin6_family != AF_INET6) {
- return uv__set_artificial_error(handle->loop, UV_EINVAL);
- }
-
- return uv__udp_send6(req, handle, bufs, bufcnt, addr, send_cb);
+ if (handle->type != UV_UDP || addr.sin6_family != AF_INET6)
+ return UV_EINVAL;
+ else
+ return uv__udp_send6(req, handle, bufs, bufcnt, addr, send_cb);
}
int uv_udp_recv_start(uv_udp_t* handle,
uv_alloc_cb alloc_cb,
uv_udp_recv_cb recv_cb) {
- if (handle->type != UV_UDP || alloc_cb == NULL || recv_cb == NULL) {
- return uv__set_artificial_error(handle->loop, UV_EINVAL);
- }
-
- return uv__udp_recv_start(handle, alloc_cb, recv_cb);
+ if (handle->type != UV_UDP || alloc_cb == NULL || recv_cb == NULL)
+ return UV_EINVAL;
+ else
+ return uv__udp_recv_start(handle, alloc_cb, recv_cb);
}
int uv_udp_recv_stop(uv_udp_t* handle) {
- if (handle->type != UV_UDP) {
- return uv__set_artificial_error(handle->loop, UV_EINVAL);
- }
-
- return uv__udp_recv_stop(handle);
+ if (handle->type != UV_UDP)
+ return UV_EINVAL;
+ else
+ return uv__udp_recv_stop(handle);
}
ctx = malloc(sizeof(*ctx));
if (ctx == NULL)
- return -1;
+ return UV_ENOMEM;
ctx->entry = entry;
ctx->arg = arg;
uint64_t uv_now(uv_loop_t* loop) {
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();
+}
#include <stddef.h>
#if defined(_MSC_VER) && _MSC_VER < 1600
-# include "uv-private/stdint-msvc2008.h"
+# include "stdint-msvc2008.h"
#else
# include <stdint.h>
#endif
# define UV__HANDLE_CLOSING 0x01
#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_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr);
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) \
(QUEUE_EMPTY(&(loop)->active_reqs) == 0)
#define UV_VERSION_MAJOR 0
#define UV_VERSION_MINOR 11
-#define UV_VERSION_PATCH 5
+#define UV_VERSION_PATCH 6
#define UV_VERSION_IS_RELEASE 1
loop->timer_counter = 0;
loop->stop_flag = 0;
-
- loop->last_err = uv_ok_;
}
}
-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) {
- case ERROR_SUCCESS: return UV_OK;
case ERROR_NOACCESS: return UV_EACCES;
case WSAEACCES: return UV_EACCES;
case ERROR_ADDRESS_ALREADY_ASSOCIATED: return UV_EADDRINUSE;
case ERROR_OPEN_FAILED: return UV_EIO;
case ERROR_SETMARK_DETECTED: 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_TOO_MANY_OPEN_FILES: return UV_EMFILE;
case WSAEMFILE: return UV_EMFILE;
default: return UV_UNKNOWN;
}
}
-
if (!uv_utf8_to_utf16(filename, filenamew,
name_size / sizeof(WCHAR))) {
- uv__set_sys_error(loop, GetLastError());
- return -1;
+ return uv_translate_sys_error(GetLastError());
}
/* Determine whether filename is a file or a directory. */
handle->buffer = NULL;
}
- uv__set_sys_error(loop, last_error);
- return -1;
+ return uv_translate_sys_error(last_error);
}
void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req,
uv_fs_event_t* handle) {
FILE_NOTIFY_INFORMATION* file_info;
- int sizew, size, result;
+ int err, sizew, size, result;
char* filename = NULL;
WCHAR* filenamew, *long_filenamew = NULL;
DWORD offset = 0;
handle->cb(handle, NULL, UV_CHANGE, 0);
}
} else {
- uv__set_sys_error(loop, GET_REQ_ERROR(req));
- handle->cb(handle, NULL, 0, -1);
+ err = GET_REQ_ERROR(req);
+ handle->cb(handle, NULL, 0, uv_translate_sys_error(err));
}
if (!(handle->flags & UV__HANDLE_CLOSING)) {
if (!QueueUserWorkItem(&uv_fs_thread_proc, \
req, \
WT_EXECUTEDEFAULT)) { \
- uv__set_sys_error((loop), GetLastError()); \
- return -1; \
+ return uv_translate_sys_error(GetLastError()); \
} \
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) \
req->result = (result_value); \
if (req->result == -1) { \
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) \
- req->result = -1; \
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) \
- req->result = -1; \
+ req->result = (uv_errno); \
req->sys_errno_ = (sys_errno); \
- req->errorno = (uv_errno);
#define VERIFY_FD(fd, req) \
if (fd == -1) { \
- req->result = -1; \
- req->errorno = UV_EBADF; \
+ req->result = UV_EBADF; \
req->sys_errno_ = ERROR_INVALID_HANDLE; \
return; \
}
NULL,
0);
if (pathw_len == 0) {
- uv__set_sys_error(loop, GetLastError());
- return -1;
+ return GetLastError();
}
buf_sz += pathw_len * sizeof(WCHAR);
NULL,
0);
if (new_pathw_len == 0) {
- uv__set_sys_error(loop, GetLastError());
- return -1;
+ return GetLastError();
}
buf_sz += new_pathw_len * sizeof(WCHAR);
buf = (char*) malloc(buf_sz);
if (buf == NULL) {
- uv__set_artificial_error(loop, UV_ENOMEM);
- return -1;
+ return ERROR_OUTOFMEMORY;
}
pos = buf;
req->fs_type = fs_type;
req->result = 0;
req->ptr = NULL;
- req->errorno = UV_OK;
req->path = NULL;
if (cb != NULL) {
/* Figure out whether path is a file or a directory. */
if (!(GetFileAttributesW(pathw) & FILE_ATTRIBUTE_DIRECTORY)) {
- req->result = -1;
- req->errorno = UV_ENOTDIR;
+ req->result = UV_ENOTDIR;
req->sys_errno_ = ERROR_SUCCESS;
return;
}
statbuf->st_blksize = 0;
statbuf->st_blocks = 0;
+ statbuf->st_flags = 0;
+ statbuf->st_gen = 0;
+
if (info.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
if (fs__readlink_handle(handle, NULL, &statbuf->st_size) != 0) {
return -1;
FILETIME_TO_TIMESPEC(statbuf->st_mtim, info.ftLastWriteTime);
FILETIME_TO_TIMESPEC(statbuf->st_atim, info.ftLastAccessTime);
FILETIME_TO_TIMESPEC(statbuf->st_ctim, info.ftCreationTime);
+ FILETIME_TO_TIMESPEC(statbuf->st_birthtim, info.ftCreationTime);
statbuf->st_nlink = (info.nNumberOfLinks <= SHRT_MAX) ?
(short) info.nNumberOfLinks : SHRT_MAX;
int uv_fs_open(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags,
int mode, uv_fs_cb cb) {
+ int err;
+
uv_fs_req_init(loop, req, UV_FS_OPEN, cb);
- if (fs__capture_path(loop, req, path, NULL, cb != NULL) < 0) {
- return -1;
+ err = fs__capture_path(loop, req, path, NULL, cb != NULL);
+ if (err) {
+ return uv_translate_sys_error(err);
}
req->file_flags = flags;
return 0;
} else {
fs__open(req);
- SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result;
}
}
return 0;
} else {
fs__close(req);
- SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result;
}
}
return 0;
} else {
fs__read(req);
- SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result;
}
}
return 0;
} else {
fs__write(req);
- SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result;
}
}
int uv_fs_unlink(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_UNLINK, cb);
- if (fs__capture_path(loop, req, path, NULL, cb != NULL) < 0) {
- return -1;
+ err = fs__capture_path(loop, req, path, NULL, cb != NULL);
+ if (err) {
+ return uv_translate_sys_error(err);
}
if (cb) {
return 0;
} else {
fs__unlink(req);
- SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result;
}
}
int uv_fs_mkdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode,
uv_fs_cb cb) {
+ int err;
+
uv_fs_req_init(loop, req, UV_FS_MKDIR, cb);
- if (fs__capture_path(loop, req, path, NULL, cb != NULL) < 0) {
- return -1;
+ err = fs__capture_path(loop, req, path, NULL, cb != NULL);
+ if (err) {
+ return uv_translate_sys_error(err);
}
req->mode = mode;
return 0;
} else {
fs__mkdir(req);
- SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result;
}
}
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);
- if (fs__capture_path(loop, req, path, NULL, cb != NULL) < 0) {
- return -1;
+ err = fs__capture_path(loop, req, path, NULL, cb != NULL);
+ if (err) {
+ return uv_translate_sys_error(err);
}
if (cb) {
return 0;
} else {
fs__rmdir(req);
- SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result;
}
}
int uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags,
uv_fs_cb cb) {
+ int err;
+
uv_fs_req_init(loop, req, UV_FS_READDIR, cb);
- if (fs__capture_path(loop, req, path, NULL, cb != NULL) < 0) {
- return -1;
+ err = fs__capture_path(loop, req, path, NULL, cb != NULL);
+ if (err) {
+ return uv_translate_sys_error(err);
}
req->file_flags;
return 0;
} else {
fs__readdir(req);
- SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result;
}
}
int uv_fs_link(uv_loop_t* loop, uv_fs_t* req, const char* path,
const char* new_path, uv_fs_cb cb) {
+ int err;
+
uv_fs_req_init(loop, req, UV_FS_LINK, cb);
- if (fs__capture_path(loop, req, path, new_path, cb != NULL) < 0) {
- return -1;
+ err = fs__capture_path(loop, req, path, new_path, cb != NULL);
+ if (err) {
+ return uv_translate_sys_error(err);
}
if (cb) {
return 0;
} else {
fs__link(req);
- SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result;
}
}
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) {
+ int err;
+
uv_fs_req_init(loop, req, UV_FS_SYMLINK, cb);
- if (fs__capture_path(loop, req, path, new_path, cb != NULL) < 0) {
- return -1;
+ err = fs__capture_path(loop, req, path, new_path, cb != NULL);
+ if (err) {
+ return uv_translate_sys_error(err);
}
req->file_flags = flags;
return 0;
} else {
fs__symlink(req);
- SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result;
}
}
int uv_fs_readlink(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_READLINK, cb);
- if (fs__capture_path(loop, req, path, NULL, cb != NULL) < 0) {
- return -1;
+ err = fs__capture_path(loop, req, path, NULL, cb != NULL);
+ if (err) {
+ return uv_translate_sys_error(err);
}
if (cb) {
return 0;
} else {
fs__readlink(req);
- SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result;
}
}
int uv_fs_chown(uv_loop_t* loop, uv_fs_t* req, const char* path, int uid,
int gid, uv_fs_cb cb) {
+ int err;
+
uv_fs_req_init(loop, req, UV_FS_CHOWN, cb);
- if (fs__capture_path(loop, req, path, NULL, cb != NULL) < 0) {
- return -1;
+ err = fs__capture_path(loop, req, path, NULL, cb != NULL);
+ if (err) {
+ return uv_translate_sys_error(err);
}
if (cb) {
return 0;
} else {
fs__chown(req);
- SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result;
}
}
return 0;
} else {
fs__fchown(req);
- SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result;
}
}
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);
- if (fs__capture_path(loop, req, path, NULL, cb != NULL) < 0) {
- return -1;
+ err = fs__capture_path(loop, req, path, NULL, cb != NULL);
+ if (err) {
+ return uv_translate_sys_error(err);
}
if (cb) {
return 0;
} else {
fs__stat(req);
- SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result;
}
}
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);
- if (fs__capture_path(loop, req, path, NULL, cb != NULL) < 0) {
- return -1;
+ err = fs__capture_path(loop, req, path, NULL, cb != NULL);
+ if (err) {
+ return uv_translate_sys_error(err);
}
if (cb) {
return 0;
} else {
fs__lstat(req);
- SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result;
}
}
return 0;
} else {
fs__fstat(req);
- SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result;
}
}
int uv_fs_rename(uv_loop_t* loop, uv_fs_t* req, const char* path,
const char* new_path, uv_fs_cb cb) {
+ int err;
+
uv_fs_req_init(loop, req, UV_FS_RENAME, cb);
- if (fs__capture_path(loop, req, path, new_path, cb != NULL) < 0) {
- return -1;
+ err = fs__capture_path(loop, req, path, new_path, cb != NULL);
+ if (err) {
+ return uv_translate_sys_error(err);
}
if (cb) {
return 0;
} else {
fs__rename(req);
- SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result;
}
}
return 0;
} else {
fs__fsync(req);
- SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result;
}
}
return 0;
} else {
fs__fdatasync(req);
- SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result;
}
}
return 0;
} else {
fs__ftruncate(req);
- SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result;
}
}
return 0;
} else {
fs__sendfile(req);
- SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result;
}
}
int uv_fs_chmod(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode,
uv_fs_cb cb) {
+ int err;
+
uv_fs_req_init(loop, req, UV_FS_CHMOD, cb);
- if (fs__capture_path(loop, req, path, NULL, cb != NULL) < 0) {
- return -1;
+ err = fs__capture_path(loop, req, path, NULL, cb != NULL);
+ if (err) {
+ return uv_translate_sys_error(err);
}
req->mode = mode;
return 0;
} else {
fs__chmod(req);
- SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result;
}
}
return 0;
} else {
fs__fchmod(req);
- SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result;
}
}
int uv_fs_utime(uv_loop_t* loop, uv_fs_t* req, const char* path, double atime,
double mtime, uv_fs_cb cb) {
+ int err;
+
uv_fs_req_init(loop, req, UV_FS_UTIME, cb);
- if (fs__capture_path(loop, req, path, NULL, cb != NULL) < 0) {
- return -1;
+ err = fs__capture_path(loop, req, path, NULL, cb != NULL);
+ if (err) {
+ return uv_translate_sys_error(err);
}
req->atime = atime;
return 0;
} else {
fs__utime(req);
- SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result;
}
}
return 0;
} else {
fs__futime(req);
- SET_UV_LAST_ERROR_FROM_REQ(req);
return req->result;
}
}
void uv_process_fs_req(uv_loop_t* loop, uv_fs_t* req) {
assert(req->cb);
uv__req_unregister(loop, req);
- SET_UV_LAST_ERROR_FROM_REQ(req);
req->cb(req);
}
#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 */
static DWORD WINAPI getaddrinfo_thread_proc(void* parameter) {
uv_getaddrinfo_t* req = (uv_getaddrinfo_t*) parameter;
struct addrinfo* addrinfo_ptr;
char* alloc_ptr = NULL;
char* cur_ptr = NULL;
- int status = 0;
+ int err = 0;
/* release input parameter memory */
if (req->alloc != NULL) {
if (addrinfow_ptr->ai_canonname != NULL) {
name_len = uv_utf16_to_utf8(addrinfow_ptr->ai_canonname, -1, NULL, 0);
if (name_len == 0) {
- uv__set_sys_error(loop, GetLastError());
- status = -1;
+ /* FIXME(bnoordhuis) Retain GetLastError(). */
+ err = UV_EAI_SYSTEM;
goto complete;
}
addrinfo_len += ALIGNED_SIZE(name_len);
}
}
} else {
- uv__set_artificial_error(loop, UV_ENOMEM);
- status = -1;
+ err = UV_EAI_MEMORY;
}
} else {
/* GetAddrInfo failed */
- uv__set_artificial_error(loop, uv_translate_eai_error(req->retcode));
- status = -1;
+ err = uv__getaddrinfo_translate_error(req->retcode);
}
/* return memory to system */
uv__req_unregister(loop, req);
/* finally do callback with converted result */
- req->getaddrinfo_cb(req, status, (struct addrinfo*)alloc_ptr);
+ req->getaddrinfo_cb(req, err, (struct addrinfo*)alloc_ptr);
}
* and save the UNICODE string pointers in the req
* We also copy hints so that caller does not need to keep memory until the
* callback.
- * return UV_OK if a callback will be made
+ * return 0 if a callback will be made
* return error code if validation fails
*
* To minimize allocation we calculate total size required,
int servicesize = 0;
int hintssize = 0;
char* alloc_ptr = NULL;
+ int err;
if (req == NULL || getaddrinfo_cb == NULL ||
(node == NULL && service == NULL)) {
- uv__set_sys_error(loop, WSAEINVAL);
+ err = WSAEINVAL;
goto error;
}
if (node != NULL) {
nodesize = ALIGNED_SIZE(uv_utf8_to_utf16(node, NULL, 0) * sizeof(WCHAR));
if (nodesize == 0) {
- uv__set_sys_error(loop, GetLastError());
+ err = GetLastError();
goto error;
}
}
servicesize = ALIGNED_SIZE(uv_utf8_to_utf16(service, NULL, 0) *
sizeof(WCHAR));
if (servicesize == 0) {
- uv__set_sys_error(loop, GetLastError());
+ err = GetLastError();
goto error;
}
}
/* allocate memory for inputs, and partition it as needed */
alloc_ptr = (char*)malloc(nodesize + servicesize + hintssize);
if (!alloc_ptr) {
- uv__set_sys_error(loop, WSAENOBUFS);
+ err = WSAENOBUFS;
goto error;
}
if (uv_utf8_to_utf16(node,
(WCHAR*) alloc_ptr,
nodesize / sizeof(WCHAR)) == 0) {
- uv__set_sys_error(loop, GetLastError());
+ err = GetLastError();
goto error;
}
alloc_ptr += nodesize;
if (uv_utf8_to_utf16(service,
(WCHAR*) alloc_ptr,
servicesize / sizeof(WCHAR)) == 0) {
- uv__set_sys_error(loop, GetLastError());
+ err = GetLastError();
goto error;
}
alloc_ptr += servicesize;
if (QueueUserWorkItem(&getaddrinfo_thread_proc,
req,
WT_EXECUTELONGFUNCTION) == 0) {
- uv__set_sys_error(loop, GetLastError());
+ err = GetLastError();
goto error;
}
if (req != NULL && req->alloc != NULL) {
free(req->alloc);
}
- return -1;
+ return uv_translate_sys_error(err);
}
/*
* 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);
int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb);
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);
void uv_poll_endgame(uv_loop_t* loop, uv_poll_t* handle);
/*
+ * Error
+ */
+int uv_translate_sys_error(int sys_errno);
+
+
+/*
* Getaddrinfo
*/
void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t* req);
int uv_parent_pid();
void uv_fatal_error(const int errorno, const char* syscall);
-uv_err_code uv_translate_sys_error(int sys_errno);
/*
* 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);
void uv__stdio_destroy(BYTE* buffer);
void uv__stdio_noinherit(BYTE* buffer);
return 0; \
\
if (cb == NULL) \
- return uv__set_artificial_error(handle->loop, UV_EINVAL); \
+ return UV_EINVAL; \
\
old_head = loop->name##_handles; \
\
}
-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) {
HANDLE pipeHandle;
- int errorno;
- uv_err_t err;
+ int err;
char* ptr = (char*)handle;
for (;;) {
break;
}
- errorno = GetLastError();
- if (errorno != ERROR_PIPE_BUSY && errorno != ERROR_ACCESS_DENIED) {
- err = uv__new_sys_error(errorno);
+ err = GetLastError();
+ if (err != ERROR_PIPE_BUSY && err != ERROR_ACCESS_DENIED) {
goto error;
}
loop->iocp,
(ULONG_PTR)handle,
0) == NULL) {
- err = uv__new_sys_error(GetLastError());
+ err = GetLastError();
goto error;
}
uv_pipe_connection_init(handle);
handle->handle = pipeHandle;
- return uv_ok_;
+ return 0;
error:
if (pipeHandle != INVALID_HANDLE_VALUE) {
void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) {
+ int err;
DWORD result;
uv_shutdown_t* req;
NTSTATUS nt_status;
/* Already closing. Cancel the shutdown. */
if (req->cb) {
- uv__set_artificial_error(loop, UV_ECANCELED);
- req->cb(req, -1);
+ req->cb(req, UV_ECANCELED);
}
DECREASE_PENDING_REQ_COUNT(handle);
handle->flags |= UV_HANDLE_WRITABLE; /* Questionable */
if (req->cb) {
- uv__set_sys_error(loop, pRtlNtStatusToDosError(nt_status));
- req->cb(req, -1);
+ err = pRtlNtStatusToDosError(nt_status);
+ req->cb(req, uv_translate_sys_error(err));
}
DECREASE_PENDING_REQ_COUNT(handle);
handle->flags |= UV_HANDLE_WRITABLE; /* Questionable */
if (req->cb) {
- uv__set_sys_error(loop, GetLastError());
- req->cb(req, -1);
+ err = GetLastError();
+ req->cb(req, uv_translate_sys_error(err));
}
DECREASE_PENDING_REQ_COUNT(handle);
/* Creates a pipe server. */
int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
uv_loop_t* loop = handle->loop;
- int i, errorno, nameSize;
+ int i, err, nameSize;
uv_pipe_accept_t* req;
if (handle->flags & UV_HANDLE_BOUND) {
- uv__set_sys_error(loop, WSAEINVAL);
- return -1;
+ return UV_EINVAL;
}
if (!name) {
- uv__set_sys_error(loop, WSAEINVAL);
- return -1;
+ return UV_EINVAL;
}
if (!(handle->flags & UV_HANDLE_PIPESERVER)) {
}
if (!uv_utf8_to_utf16(name, handle->name, nameSize / sizeof(WCHAR))) {
- uv__set_sys_error(loop, GetLastError());
- return -1;
+ return uv_translate_sys_error(GetLastError());
}
/*
PIPE_UNLIMITED_INSTANCES, 65536, 65536, 0, NULL);
if (handle->accept_reqs[0].pipeHandle == INVALID_HANDLE_VALUE) {
- errorno = GetLastError();
- if (errorno == ERROR_ACCESS_DENIED) {
- uv__set_error(loop, UV_EADDRINUSE, errorno);
- } else if (errorno == ERROR_PATH_NOT_FOUND || errorno == ERROR_INVALID_NAME) {
- uv__set_error(loop, UV_EACCES, errorno);
- } else {
- uv__set_sys_error(loop, errorno);
+ err = GetLastError();
+ if (err == ERROR_ACCESS_DENIED) {
+ err = WSAEADDRINUSE; /* Translates to UV_EADDRINUSE. */
+ } else if (err == ERROR_PATH_NOT_FOUND || err == ERROR_INVALID_NAME) {
+ err = WSAEACCES; /* Translates to UV_EACCES. */
}
goto error;
}
if (uv_set_pipe_handle(loop, handle, handle->accept_reqs[0].pipeHandle, 0)) {
- uv__set_sys_error(loop, GetLastError());
+ err = GetLastError();
goto error;
}
handle->accept_reqs[0].pipeHandle = INVALID_HANDLE_VALUE;
}
- return -1;
+ return uv_translate_sys_error(err);
}
void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle,
const char* name, uv_connect_cb cb) {
uv_loop_t* loop = handle->loop;
- int errorno, nameSize;
+ int err, nameSize;
HANDLE pipeHandle = INVALID_HANDLE_VALUE;
DWORD duplex_flags;
}
if (!uv_utf8_to_utf16(name, handle->name, nameSize / sizeof(WCHAR))) {
- errorno = GetLastError();
+ err = GetLastError();
goto error;
}
if (!QueueUserWorkItem(&pipe_connect_thread_proc,
req,
WT_EXECUTELONGFUNCTION)) {
- errorno = GetLastError();
+ err = GetLastError();
goto error;
}
return;
}
- errorno = GetLastError();
+ err = GetLastError();
goto error;
}
(uv_pipe_t*) req->handle,
pipeHandle,
duplex_flags)) {
- errorno = GetLastError();
+ err = GetLastError();
goto 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);
handle->reqs_pending++;
REGISTER_HANDLE_REQ(loop, handle, req);
if (server->ipc) {
if (!server->pending_ipc_info.socket_info) {
/* No valid pending sockets. */
- uv__set_sys_error(loop, WSAEWOULDBLOCK);
- return -1;
+ return WSAEWOULDBLOCK;
}
return uv_tcp_import((uv_tcp_t*)client, server->pending_ipc_info.socket_info,
if (!req) {
/* No valid connections found, so we error out. */
- uv__set_sys_error(loop, WSAEWOULDBLOCK);
- return -1;
+ return WSAEWOULDBLOCK;
}
/* Initialize the client handle and copy the pipeHandle to the client */
}
if (!(handle->flags & UV_HANDLE_BOUND)) {
- uv__set_artificial_error(loop, UV_EINVAL);
- return -1;
+ return WSAEINVAL;
}
if (handle->flags & UV_HANDLE_READING) {
- uv__set_artificial_error(loop, UV_EISCONN);
- return -1;
+ return WSAEISCONN;
}
if (!(handle->flags & UV_HANDLE_PIPESERVER)) {
- uv__set_artificial_error(loop, UV_ENOTSUP);
- return -1;
+ return ERROR_NOT_SUPPORTED;
}
handle->flags |= UV_HANDLE_LISTENING;
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_stream_t* send_handle, uv_write_cb cb) {
+ int err;
int result;
uv_tcp_t* tcp_send_handle;
uv_write_t* ipc_header_req;
uv_ipc_frame_uv_stream ipc_frame;
if (bufcnt != 1 && (bufcnt != 0 || !send_handle)) {
- uv__set_artificial_error(loop, UV_ENOTSUP);
- return -1;
+ return ERROR_NOT_SUPPORTED;
}
/* Only TCP handles are supported for sharing. */
if (send_handle && ((send_handle->type != UV_TCP) ||
(!(send_handle->flags & UV_HANDLE_BOUND) &&
!(send_handle->flags & UV_HANDLE_CONNECTION)))) {
- uv__set_artificial_error(loop, UV_ENOTSUP);
- return -1;
+ return ERROR_NOT_SUPPORTED;
}
assert(handle->handle != INVALID_HANDLE_VALUE);
if (send_handle) {
tcp_send_handle = (uv_tcp_t*)send_handle;
- if (uv_tcp_duplicate_socket(tcp_send_handle, handle->ipc_pid,
- &ipc_frame.socket_info)) {
- return -1;
+ err = uv_tcp_duplicate_socket(tcp_send_handle, handle->ipc_pid,
+ &ipc_frame.socket_info);
+ if (err) {
+ return err;
}
ipc_frame.header.flags |= UV_IPC_TCP_SERVER;
NULL,
&ipc_header_req->overlapped);
if (!result && GetLastError() != ERROR_IO_PENDING) {
- uv__set_sys_error(loop, GetLastError());
+ err = GetLastError();
CloseHandle(ipc_header_req->overlapped.hEvent);
- return -1;
+ return err;
}
if (!result) {
/* Request not completed immediately. Wait for it.*/
if (WaitForSingleObject(ipc_header_req->overlapped.hEvent, INFINITE) !=
WAIT_OBJECT_0) {
- uv__set_sys_error(loop, GetLastError());
+ err = GetLastError();
CloseHandle(ipc_header_req->overlapped.hEvent);
- return -1;
+ return err;
}
}
ipc_header_req->queued_bytes = 0;
NULL);
if (!result) {
- return uv__set_sys_error(loop, GetLastError());
+ return err;
} else {
/* Request completed immediately. */
req->queued_bytes = 0;
&req->overlapped);
if (!result && GetLastError() != ERROR_IO_PENDING) {
- uv__set_sys_error(loop, GetLastError());
+ err = GetLastError();
CloseHandle(req->overlapped.hEvent);
- return -1;
+ return err;
}
if (result) {
/* Request queued by the kernel. */
if (WaitForSingleObject(ipc_header_req->overlapped.hEvent, INFINITE) !=
WAIT_OBJECT_0) {
- uv__set_sys_error(loop, GetLastError());
+ err = GetLastError();
CloseHandle(ipc_header_req->overlapped.hEvent);
- return -1;
+ return uv_translate_sys_error(err);
}
}
CloseHandle(req->overlapped.hEvent);
&req->overlapped);
if (!result && GetLastError() != ERROR_IO_PENDING) {
- uv__set_sys_error(loop, GetLastError());
- return -1;
+ return GetLastError();
}
if (result) {
if (!RegisterWaitForSingleObject(&req->wait_handle,
req->overlapped.hEvent, post_completion_write_wait, (void*) req,
INFINITE, WT_EXECUTEINWAITTHREAD)) {
- uv__set_sys_error(loop, GetLastError());
- return -1;
+ return GetLastError();
}
}
}
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) {
if (!handle->ipc) {
- uv__set_artificial_error(loop, UV_EINVAL);
- return -1;
+ return WSAEINVAL;
}
return uv_pipe_write_impl(loop, req, handle, bufs, bufcnt, send_handle, cb);
handle->flags &= ~UV_HANDLE_READABLE;
uv_read_stop((uv_stream_t*) handle);
- uv__set_artificial_error(loop, UV_EOF);
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 {
- handle->read_cb((uv_stream_t*) handle, -1, uv_null_buf_);
+ handle->read_cb((uv_stream_t*) handle, UV_EOF, uv_null_buf_);
}
}
uv_read_stop((uv_stream_t*) handle);
- uv__set_sys_error(loop, error);
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 {
- handle->read_cb((uv_stream_t*)handle, -1, buf);
+ handle->read_cb((uv_stream_t*)handle, uv_translate_sys_error(error), buf);
}
}
void uv_process_pipe_write_req(uv_loop_t* loop, uv_pipe_t* handle,
uv_write_t* req) {
+ int err;
+
assert(handle->type == UV_NAMED_PIPE);
assert(handle->write_queue_size >= req->queued_bytes);
}
} else {
if (req->cb) {
- if (!REQ_SUCCESS(req)) {
- uv__set_sys_error(loop, GET_REQ_ERROR(req));
- ((uv_write_cb)req->cb)(req, -1);
- } else {
- ((uv_write_cb)req->cb)(req, 0);
- }
+ err = GET_REQ_ERROR(req);
+ req->cb(req, uv_translate_sys_error(err));
}
}
void uv_process_pipe_connect_req(uv_loop_t* loop, uv_pipe_t* handle,
uv_connect_t* req) {
+ int err;
+
assert(handle->type == UV_NAMED_PIPE);
UNREGISTER_HANDLE_REQ(loop, handle, req);
if (req->cb) {
+ err = 0;
if (REQ_SUCCESS(req)) {
uv_pipe_connection_init(handle);
- ((uv_connect_cb)req->cb)(req, 0);
} else {
- uv__set_sys_error(loop, GET_REQ_ERROR(req));
- ((uv_connect_cb)req->cb)(req, -1);
+ err = GET_REQ_ERROR(req);
}
+ req->cb(req, uv_translate_sys_error(err));
}
DECREASE_PENDING_REQ_COUNT(handle);
if (os_handle == INVALID_HANDLE_VALUE ||
uv_set_pipe_handle(pipe->loop, pipe, os_handle, 0) == -1) {
- uv__set_sys_error(pipe->loop, WSAEINVAL);
- return -1;
+ return UV_EINVAL;
}
uv_pipe_connection_init(pipe);
if (result == SOCKET_ERROR) {
DWORD error = WSAGetLastError();
if (error != WSA_IO_PENDING) {
- uv__set_sys_error(loop, WSAGetLastError());
- return -1;
+ return WSAGetLastError();
}
}
DWORD error = GET_REQ_SOCK_ERROR(req);
if (error != WSAEINTR && handle->events != 0) {
handle->events = 0; /* Stop the watcher */
- uv__set_sys_error(loop, error);
- handle->poll_cb(handle, -1, 0);
+ handle->poll_cb(handle, uv_translate_sys_error(error), 0);
}
} else if (afd_poll_info->NumberOfHandles >= 1) {
}
-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;
uv__handle_closing(handle);
if (handle->submitted_events_1 == 0 &&
handle->submitted_events_2 == 0) {
uv_want_endgame(loop, (uv_handle_t*) handle);
+ return 0;
} else {
/* Cancel outstanding poll requests by executing another, unique poll */
/* 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);
}
}
static void uv__slow_poll_process_poll_req(uv_loop_t* loop, uv_poll_t* handle,
uv_req_t* req) {
unsigned char mask_events;
+ int err;
+
if (req == &handle->poll_req_1) {
handle->submitted_events_1 = 0;
mask_events = handle->mask_events_1;
if (!REQ_SUCCESS(req)) {
/* Error. */
if (handle->events != 0) {
+ err = GET_REQ_ERROR(req);
handle->events = 0; /* Stop the watcher */
- uv__set_sys_error(loop, GET_REQ_ERROR(req));
- handle->poll_cb(handle, -1, 0);
+ handle->poll_cb(handle, uv_translate_sys_error(err), 0);
}
} else {
/* Got some 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;
uv__handle_closing(handle);
handle->submitted_events_2 == 0) {
uv_want_endgame(loop, (uv_handle_t*) handle);
}
+
+ return 0;
}
SO_PROTOCOL_INFOW,
(char*) &protocol_info,
&len) != 0) {
- uv__set_sys_error(loop, WSAGetLastError());
- return -1;
+ return WSAGetLastError();
}
/* Get the peer socket that is needed to enable fast poll. If the returned */
int uv_poll_start(uv_poll_t* handle, int events, uv_poll_cb cb) {
+ int err;
+
if (!(handle->flags & UV_HANDLE_POLL_SLOW)) {
- if (uv__fast_poll_set(handle->loop, handle, events) < 0)
- return -1;
+ err = uv__fast_poll_set(handle->loop, handle, events);
} else {
- if (uv__slow_poll_set(handle->loop, handle, events) < 0)
- return -1;
+ err = uv__slow_poll_set(handle->loop, handle, events);
+ }
+
+ if (err) {
+ return uv_translate_sys_error(err);
}
handle->poll_cb = cb;
int uv_poll_stop(uv_poll_t* handle) {
+ int err;
+
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 {
- return uv__slow_poll_set(handle->loop, handle, 0);
+ err = uv__slow_poll_set(handle->loop, handle, 0);
}
+
+ return uv_translate_sys_error(err);
}
}
-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)) {
- uv__fast_poll_close(loop, handle);
+ return uv__fast_poll_close(loop, handle);
} else {
- uv__slow_poll_close(loop, handle);
+ return uv__slow_poll_close(loop, handle);
}
}
}
-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) {
char pipe_name[64];
SECURITY_ATTRIBUTES sa;
DWORD server_access = 0;
DWORD client_access = 0;
HANDLE child_pipe = INVALID_HANDLE_VALUE;
- uv_err_t err;
+ int err;
if (flags & UV_READABLE_PIPE) {
server_access |= PIPE_ACCESS_OUTBOUND;
server_access,
pipe_name,
sizeof(pipe_name));
- if (err.code != UV_OK)
+ if (err)
goto error;
/* Create child pipe handle. */
server_pipe->ipc ? FILE_FLAG_OVERLAPPED : 0,
NULL);
if (child_pipe == INVALID_HANDLE_VALUE) {
- err = uv__new_sys_error(GetLastError());
+ err = GetLastError();
goto error;
}
/* both ends of the pipe created. */
if (!ConnectNamedPipe(server_pipe->handle, NULL)) {
if (GetLastError() != ERROR_PIPE_CONNECTED) {
- err = uv__new_sys_error(GetLastError());
+ err = GetLastError();
goto error;
}
}
server_pipe->flags |= UV_HANDLE_READABLE | UV_HANDLE_WRITABLE;
*child_pipe_ptr = child_pipe;
- return uv_ok_;
+ return 0;
error:
if (server_pipe->handle != INVALID_HANDLE_VALUE) {
handle == NULL ||
handle == (HANDLE) -2) {
*dup = INVALID_HANDLE_VALUE;
- uv__set_artificial_error(loop, UV_EBADF);
- return -1;
+ return ERROR_INVALID_HANDLE;
}
current_process = GetCurrentProcess();
TRUE,
DUPLICATE_SAME_ACCESS)) {
*dup = INVALID_HANDLE_VALUE;
- uv__set_sys_error(loop, GetLastError());
- return -1;
+ return GetLastError();
}
return 0;
if (fd == -1) {
*dup = INVALID_HANDLE_VALUE;
- uv__set_artificial_error(loop, UV_EBADF);
- return -1;
+ return ERROR_INVALID_HANDLE;
}
handle = (HANDLE) _get_osfhandle(fd);
}
-uv_err_t uv__create_nul_handle(HANDLE* handle_ptr,
+int uv__create_nul_handle(HANDLE* handle_ptr,
DWORD access) {
HANDLE handle;
SECURITY_ATTRIBUTES sa;
0,
NULL);
if (handle == INVALID_HANDLE_VALUE) {
- return uv__new_sys_error(GetLastError());
+ return GetLastError();
}
*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;
int count, i;
- uv_err_t err;
+ int err;
count = options->stdio_count;
if (count < 0 || count > 255) {
/* Only support FDs 0-255 */
- return uv__new_artificial_error(UV_ENOTSUP);
+ return ERROR_NOT_SUPPORTED;
} else if (count < 3) {
/* There should always be at least 3 stdio handles. */
count = 3;
/* Allocate the child stdio buffer */
buffer = (BYTE*) malloc(CHILD_STDIO_SIZE(count));
if (buffer == NULL) {
- return uv__new_artificial_error(UV_ENOMEM);
+ return ERROR_OUTOFMEMORY;
}
/* Prepopulate the buffer with INVALID_HANDLE_VALUE handles so we can */
err = uv__create_nul_handle(&CHILD_STDIO_HANDLE(buffer, i),
access);
- if (err.code != UV_OK)
+ if (err)
goto error;
CHILD_STDIO_CRT_FLAGS(buffer, i) = FOPEN | FDEV;
parent_pipe,
&child_pipe,
fdopt.flags);
- if (err.code != UV_OK)
+ if (err)
goto error;
CHILD_STDIO_HANDLE(buffer, i) = child_pipe;
HANDLE child_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 */
/* 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_HANDLE(buffer, i) = INVALID_HANDLE_VALUE;
break;
case FILE_TYPE_UNKNOWN:
if (GetLastError() != 0) {
- uv__set_sys_error(loop, GetLastError());
+ err = GetLastError();
CloseHandle(child_handle);
goto error;
}
stream_handle == INVALID_HANDLE_VALUE) {
/* The handle is already closed, or not yet created, or the */
/* stream type is not supported. */
- uv__set_artificial_error(loop, UV_ENOTSUP);
+ err = ERROR_NOT_SUPPORTED;
goto error;
}
}
*buffer_ptr = buffer;
- return uv_ok_;
+ return 0;
error:
uv__stdio_destroy(buffer);
}
-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;
WCHAR* ws;
NULL,
0);
if (ws_len <= 0) {
- return uv__new_sys_error(GetLastError());
+ return GetLastError();
}
ws = (WCHAR*) malloc(ws_len * sizeof(WCHAR));
if (ws == NULL) {
- return uv__new_artificial_error(UV_ENOMEM);
+ return ERROR_OUTOFMEMORY;
}
r = MultiByteToWideChar(CP_UTF8,
assert(r == ws_len);
*ws_ptr = ws;
- return uv_ok_;
+ return 0;
}
uv__handle_init(loop, (uv_handle_t*) handle, UV_PROCESS);
handle->exit_cb = NULL;
handle->pid = 0;
- handle->spawn_error = uv_ok_;
+ handle->spawn_error = 0;
handle->exit_signal = 0;
handle->wait_handle = INVALID_HANDLE_VALUE;
handle->process_handle = INVALID_HANDLE_VALUE;
attrs = GetFileAttributesW(result);
if (attrs != INVALID_FILE_ATTRIBUTES &&
- !(attrs & (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_REPARSE_POINT))) {
+ !(attrs & FILE_ATTRIBUTE_DIRECTORY)) {
return result;
}
}
-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;
WCHAR* dst = NULL;
WCHAR* temp_buffer = NULL;
size_t temp_buffer_len = 0;
WCHAR* pos;
int arg_count = 0;
- uv_err_t err = uv_ok_;
+ int err = 0;
/* Count the required size. */
for (arg = args; *arg; arg++) {
NULL,
0);
if (arg_len == 0) {
- return uv__new_sys_error(GetLastError());
+ return GetLastError();
}
dst_len += arg_len;
/* Allocate buffer for the final command line. */
dst = (WCHAR*) malloc(dst_len * sizeof(WCHAR));
if (dst == NULL) {
- err = uv__new_artificial_error(UV_ENOMEM);
+ err = ERROR_OUTOFMEMORY;
goto error;
}
/* Allocate temporary working buffer. */
temp_buffer = (WCHAR*) malloc(temp_buffer_len * sizeof(WCHAR));
if (temp_buffer == NULL) {
- err = uv__new_artificial_error(UV_ENOMEM);
+ err = ERROR_OUTOFMEMORY;
goto error;
}
temp_buffer,
(int) (dst + dst_len - pos));
if (arg_len == 0) {
+ err = GetLastError();
goto error;
}
free(temp_buffer);
*dst_ptr = dst;
- return uv_ok_;
+ return 0;
error:
free(dst);
* these get defined if the input environment block does not contain any
* 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* ptr;
char** env;
NULL,
0);
if (len <= 0) {
- return uv__new_sys_error(GetLastError());
+ return GetLastError();
}
env_len += len;
env_len += required_vars[i].len;
var_size = GetEnvironmentVariableW(required_vars[i].wide, NULL, 0);
if (var_size == 0) {
- return uv__new_sys_error(GetLastError());
+ return GetLastError();
}
required_vars[i].value_len = var_size;
env_len += var_size;
dst = malloc(env_len * sizeof(WCHAR));
if (!dst) {
- return uv__new_artificial_error(UV_ENOMEM);
+ return ERROR_OUTOFMEMORY;
}
ptr = dst;
(int) (env_len - (ptr - dst)));
if (len <= 0) {
free(dst);
- return uv__new_sys_error(GetLastError());
+ return GetLastError();
}
}
*ptr = L'\0';
*dst_ptr = dst;
- return uv_ok_;
+ return 0;
}
/* Called on main thread after a child process has exited. */
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);
handle->exit_cb_pending = 0;
/* callback.*/
uv__handle_stop(handle);
- if (handle->spawn_error.code != UV_OK) {
+ if (handle->spawn_error) {
/* Spawning failed. */
- exit_code = (DWORD) -1;
- } else if (!GetExitCodeProcess(handle->process_handle, &exit_code)) {
+ exit_code = uv_translate_sys_error(handle->spawn_error);
+ } else if (!GetExitCodeProcess(handle->process_handle, &status)) {
/* 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. */
if (handle->exit_cb) {
- loop->last_err = handle->spawn_error;
handle->exit_cb(handle, exit_code, handle->exit_signal);
}
}
int uv_spawn(uv_loop_t* loop, uv_process_t* process,
uv_process_options_t options) {
int i;
- uv_err_t err = uv_ok_;
+ int err = 0;
WCHAR* path = NULL;
BOOL result;
WCHAR* application_path = NULL, *application = NULL, *arguments = NULL,
DWORD process_flags;
if (options.flags & (UV_PROCESS_SETGID | UV_PROCESS_SETUID)) {
- uv__set_artificial_error(loop, UV_ENOTSUP);
- return -1;
+ return UV_ENOTSUP;
}
if (options.file == NULL ||
options.args == NULL) {
- uv__set_artificial_error(loop, UV_EINVAL);
- return -1;
+ return UV_EINVAL;
}
assert(options.file != NULL);
process->exit_cb = options.exit_cb;
err = uv_utf8_to_utf16_alloc(options.file, &application);
- if (err.code != UV_OK)
+ if (err)
goto done;
err = make_program_args(options.args,
options.flags & UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS,
&arguments);
- if (err.code != UV_OK)
+ if (err)
goto done;
if (options.env) {
err = make_program_env(options.env, &env);
- if (err.code != UV_OK)
+ if (err)
goto done;
}
if (options.cwd) {
/* Explicit cwd */
err = uv_utf8_to_utf16_alloc(options.cwd, &cwd);
- if (err.code != UV_OK)
+ if (err)
goto done;
} else {
cwd_len = GetCurrentDirectoryW(0, NULL);
if (!cwd_len) {
- err = uv__new_sys_error(GetLastError());
+ err = GetLastError();
goto done;
}
cwd = (WCHAR*) malloc(cwd_len * sizeof(WCHAR));
if (cwd == NULL) {
- err = uv__new_artificial_error(UV_ENOMEM);
+ err = ERROR_OUTOFMEMORY;
goto done;
}
r = GetCurrentDirectoryW(cwd_len, cwd);
if (r == 0 || r >= cwd_len) {
- err = uv__new_sys_error(GetLastError());
+ err = GetLastError();
goto done;
}
}
path_len = GetEnvironmentVariableW(L"PATH", NULL, 0);
if (path_len == 0) {
- err = uv__new_sys_error(GetLastError());
+ err = GetLastError();
goto done;
}
path = (WCHAR*) malloc(path_len * sizeof(WCHAR));
if (path == NULL) {
- err = uv__new_artificial_error(UV_ENOMEM);
+ err = ERROR_OUTOFMEMORY;
goto done;
}
r = GetEnvironmentVariableW(L"PATH", path, path_len);
if (r == 0 || r >= path_len) {
- err = uv__new_sys_error(GetLastError());
+ err = GetLastError();
goto done;
}
}
path);
if (application_path == NULL) {
/* Not found. */
- err = uv__new_artificial_error(UV_ENOENT);
+ err = ERROR_FILE_NOT_FOUND;
goto done;
}
-
err = uv__stdio_create(loop, &options, &process->child_stdio_buffer);
- if (err.code != UV_OK)
+ if (err)
goto done;
startup.cb = sizeof(startup);
} else {
/* CreateProcessW failed. */
- err = uv__new_sys_error(GetLastError());
+ err = GetLastError();
}
done:
uv__handle_start(process);
/* If an error happened, queue the exit req. */
- if (err.code != UV_OK) {
+ if (err) {
process->exit_cb_pending = 1;
uv_insert_pending_req(loop, (uv_req_t*) &process->exit_req);
}
}
-static uv_err_t uv__kill(HANDLE process_handle, int signum) {
+static int uv__kill(HANDLE process_handle, int signum) {
switch (signum) {
case SIGTERM:
case SIGKILL:
case SIGINT: {
/* Unconditionally terminate the process. On Windows, killed processes */
/* normally return 1. */
- DWORD error, status;
+ DWORD status;
+ int err;
if (TerminateProcess(process_handle, 1))
- return uv_ok_;
+ return 0;
/* If the process already exited before TerminateProcess was called, */
/* TerminateProcess will fail with ERROR_ACESS_DENIED. */
- error = GetLastError();
- if (error == ERROR_ACCESS_DENIED &&
+ err = GetLastError();
+ if (err == ERROR_ACCESS_DENIED &&
GetExitCodeProcess(process_handle, &status) &&
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: {
DWORD status;
if (!GetExitCodeProcess(process_handle, &status))
- return uv__new_sys_error(GetLastError());
+ return uv_translate_sys_error(GetLastError());
if (status != STILL_ACTIVE)
- return uv__new_artificial_error(UV_ESRCH);
+ return UV_ESRCH;
- return uv_ok_;
+ return 0;
}
default:
/* Unsupported signal. */
- return uv__new_artificial_error(UV_ENOSYS);
+ return UV_ENOSYS;
}
}
int uv_process_kill(uv_process_t* process, int signum) {
- uv_err_t err;
+ int err;
if (process->process_handle == INVALID_HANDLE_VALUE) {
- uv__set_artificial_error(process->loop, UV_EINVAL);
- return -1;
+ return UV_EINVAL;
}
err = uv__kill(process->process_handle, signum);
-
- if (err.code != UV_OK) {
- uv__set_error(process->loop, err.code, err.sys_errno_);
- return -1;
+ if (err) {
+ return err; /* err is already translated. */
}
process->exit_signal = signum;
}
-uv_err_t uv_kill(int pid, int signum) {
- uv_err_t err;
+int uv_kill(int pid, int signum) {
+ int err;
HANDLE process_handle = OpenProcess(PROCESS_TERMINATE |
PROCESS_QUERY_INFORMATION, FALSE, pid);
if (process_handle == NULL) {
- if (GetLastError() == ERROR_INVALID_PARAMETER) {
- return uv__new_artificial_error(UV_ESRCH);
+ err = GetLastError();
+ if (err == ERROR_INVALID_PARAMETER) {
+ return UV_ESRCH;
} else {
- return uv__new_sys_error(GetLastError());
+ return uv_translate_sys_error(err);
}
}
err = uv__kill(process_handle, signum);
CloseHandle(process_handle);
- return err;
+ return err; /* err is already translated. */
}
}
-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. */
/* If the console control handler has already been hooked, just add a */
/* reference. */
if (uv__signal_control_handler_refs > 0)
- return uv_ok_;
+ return 0;
if (!SetConsoleCtrlHandler(uv__signal_control_handler, TRUE))
- return uv__new_sys_error(GetLastError());
+ return GetLastError();
uv__signal_control_handler_refs++;
- return uv_ok_;
+ return 0;
}
}
-static uv_err_t uv__signal_register(int signum) {
+static int uv__signal_register(int signum) {
switch (signum) {
case SIGINT:
case SIGBREAK:
case SIGWINCH:
/* SIGWINCH is generated in tty.c. No need to register anything. */
- return uv_ok_;
+ return 0;
case SIGILL:
case SIGABRT_COMPAT:
case SIGTERM:
case SIGABRT:
/* Signal is never raised. */
- return uv_ok_;
+ return 0;
default:
/* Invalid signal. */
- return uv__new_artificial_error(UV_EINVAL);
+ return ERROR_INVALID_PARAMETER;
}
}
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 */
/* signum is otherwise invalid then uv__signal_register will find out */
/* eventually. */
if (signum == 0) {
- uv__set_artificial_error(handle->loop, UV_EINVAL);
- return -1;
+ return UV_EINVAL;
}
/* Short circuit: if the signal watcher is already watching {signum} don't */
EnterCriticalSection(&uv__signal_lock);
err = uv__signal_register(signum);
- if (err.code != UV_OK) {
+ if (err) {
/* Uh-oh, didn't work. */
- handle->loop->last_err = err;
LeaveCriticalSection(&uv__signal_lock);
- return -1;
+ return uv_translate_sys_error(err);
}
handle->signum = signum;
int uv_listen(uv_stream_t* stream, int backlog, uv_connection_cb cb) {
+ int err;
+
+ err = ERROR_INVALID_PARAMETER;
switch (stream->type) {
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:
- return uv_pipe_listen((uv_pipe_t*)stream, backlog, cb);
+ err = uv_pipe_listen((uv_pipe_t*)stream, backlog, cb);
+ break;
default:
assert(0);
- return -1;
}
+
+ return uv_translate_sys_error(err);
}
int uv_accept(uv_stream_t* server, uv_stream_t* client) {
+ int err;
+
+ err = ERROR_INVALID_PARAMETER;
switch (server->type) {
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:
- return uv_pipe_accept((uv_pipe_t*)server, client);
+ err = uv_pipe_accept((uv_pipe_t*)server, client);
+ break;
default:
assert(0);
- return -1;
}
+
+ return uv_translate_sys_error(err);
}
int uv_read_start(uv_stream_t* handle, uv_alloc_cb alloc_cb,
uv_read_cb read_cb) {
+ int err;
+
if (handle->flags & UV_HANDLE_READING) {
- uv__set_artificial_error(handle->loop, UV_EALREADY);
- return -1;
+ return UV_EALREADY;
}
if (!(handle->flags & UV_HANDLE_READABLE)) {
- uv__set_artificial_error(handle->loop, UV_ENOTCONN);
- return -1;
+ return UV_ENOTCONN;
}
+ err = ERROR_INVALID_PARAMETER;
switch (handle->type) {
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:
- 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:
- 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:
assert(0);
- return -1;
}
+
+ return uv_translate_sys_error(err);
}
int uv_read2_start(uv_stream_t* handle, uv_alloc_cb alloc_cb,
uv_read2_cb read_cb) {
+ int err;
+
if (handle->flags & UV_HANDLE_READING) {
- uv__set_artificial_error(handle->loop, UV_EALREADY);
- return -1;
+ return UV_EALREADY;
}
if (!(handle->flags & UV_HANDLE_READABLE)) {
- uv__set_artificial_error(handle->loop, UV_ENOTCONN);
- return -1;
+ return UV_ENOTCONN;
}
+ err = ERROR_INVALID_PARAMETER;
switch (handle->type) {
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:
assert(0);
- return -1;
}
+
+ return uv_translate_sys_error(err);
}
int uv_read_stop(uv_stream_t* handle) {
+ int err;
+
if (!(handle->flags & UV_HANDLE_READING))
return 0;
+ err = 0;
if (handle->type == UV_TTY) {
- return uv_tty_read_stop((uv_tty_t*) handle);
+ err = uv_tty_read_stop((uv_tty_t*) handle);
} else {
handle->flags &= ~UV_HANDLE_READING;
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,
uv_write_cb cb) {
uv_loop_t* loop = handle->loop;
+ int err;
if (!(handle->flags & UV_HANDLE_WRITABLE)) {
- uv__set_artificial_error(loop, UV_EPIPE);
- return -1;
+ return UV_EPIPE;
}
+ err = ERROR_INVALID_PARAMETER;
switch (handle->type) {
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:
- 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:
- 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:
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,
uv_stream_t* send_handle, uv_write_cb cb) {
uv_loop_t* loop = handle->loop;
+ int err;
if (!(handle->flags & UV_HANDLE_WRITABLE)) {
- uv__set_artificial_error(loop, UV_EPIPE);
- return -1;
+ return UV_EPIPE;
}
+ err = ERROR_INVALID_PARAMETER;
switch (handle->type) {
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:
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) {
uv_loop_t* loop = handle->loop;
- if (!(handle->flags & UV_HANDLE_WRITABLE)) {
- uv__set_artificial_error(loop, UV_EPIPE);
- return -1;
+ if (!(handle->flags & UV_HANDLE_WRITABLE)) {
+ return UV_EPIPE;
}
if (!(handle->flags & UV_HANDLE_WRITABLE)) {
- uv__set_artificial_error(loop, UV_EPIPE);
- return -1;
+ return UV_EPIPE;
}
uv_req_init(loop, (uv_req_t*) req);
TCP_NODELAY,
(const char*)&enable,
sizeof enable) == -1) {
- uv__set_sys_error(handle->loop, WSAGetLastError());
- return -1;
+ return WSAGetLastError();
}
return 0;
}
SO_KEEPALIVE,
(const char*)&enable,
sizeof enable) == -1) {
- uv__set_sys_error(handle->loop, WSAGetLastError());
- return -1;
+ return WSAGetLastError();
}
if (enable && setsockopt(socket,
TCP_KEEPALIVE,
(const char*)&delay,
sizeof delay) == -1) {
- uv__set_sys_error(handle->loop, WSAGetLastError());
- return -1;
+ return WSAGetLastError();
}
return 0;
SOCKET socket, int family, int imported) {
DWORD yes = 1;
int non_ifs_lsp;
+ int err;
assert(handle->socket == INVALID_SOCKET);
/* Set the socket to nonblocking mode */
if (ioctlsocket(socket, FIONBIO, &yes) == SOCKET_ERROR) {
- uv__set_sys_error(loop, WSAGetLastError());
- return -1;
+ return WSAGetLastError();
}
/* Associate it with the I/O completion port. */
if (imported) {
handle->flags |= UV_HANDLE_EMULATE_IOCP;
} else {
- uv__set_sys_error(loop, GetLastError());
- return -1;
+ return GetLastError();
}
}
FILE_SKIP_COMPLETION_PORT_ON_SUCCESS)) {
handle->flags |= UV_HANDLE_SYNC_BYPASS_IOCP;
} else if (GetLastError() != ERROR_INVALID_FUNCTION) {
- uv__set_sys_error(loop, GetLastError());
- return -1;
+ return GetLastError();
}
}
- if ((handle->flags & UV_HANDLE_TCP_NODELAY) &&
- uv__tcp_nodelay(handle, socket, 1)) {
- return -1;
+ if (handle->flags & UV_HANDLE_TCP_NODELAY) {
+ err = uv__tcp_nodelay(handle, socket, 1);
+ if (err)
+ return err;
}
/* TODO: Use stored delay. */
- if ((handle->flags & UV_HANDLE_TCP_KEEPALIVE) &&
- uv__tcp_keepalive(handle, socket, 1, 60)) {
- return -1;
+ if (handle->flags & UV_HANDLE_TCP_KEEPALIVE) {
+ err = uv__tcp_keepalive(handle, socket, 1, 60);
+ if (err)
+ return err;
}
handle->socket = socket;
void uv_tcp_endgame(uv_loop_t* loop, uv_tcp_t* handle) {
- int status;
+ int err;
unsigned int i;
uv_tcp_accept_t* req;
UNREGISTER_HANDLE_REQ(loop, handle, handle->shutdown_req);
+ err = 0;
if (handle->flags & UV__HANDLE_CLOSING) {
- status = -1;
- uv__set_artificial_error(loop, UV_ECANCELED);
- } else if (shutdown(handle->socket, SD_SEND) != SOCKET_ERROR) {
- status = 0;
- } else {
- status = -1;
- uv__set_sys_error(loop, WSAGetLastError());
+ err = ERROR_OPERATION_ABORTED;
+ } else if (shutdown(handle->socket, SD_SEND) == SOCKET_ERROR) {
+ err = WSAGetLastError();
}
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;
if (handle->socket == INVALID_SOCKET) {
SOCKET sock = socket(family, SOCK_STREAM, 0);
if (sock == INVALID_SOCKET) {
- uv__set_sys_error(handle->loop, WSAGetLastError());
- return -1;
+ return WSAGetLastError();
}
/* Make the socket non-inheritable */
if (!SetHandleInformation((HANDLE) sock, HANDLE_FLAG_INHERIT, 0)) {
- uv__set_sys_error(handle->loop, GetLastError());
+ err = GetLastError();
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);
- return -1;
+ return err;
}
}
handle->bind_error = err;
handle->flags |= UV_HANDLE_BIND_ERROR;
} else {
- uv__set_sys_error(handle->loop, err);
- return -1;
+ return err;
}
}
int uv__tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr) {
- return uv__bind(handle,
- AF_INET,
- (struct sockaddr*)&addr,
- sizeof(struct sockaddr_in));
+ return uv_translate_sys_error(
+ uv__bind(handle, AF_INET, (struct sockaddr*) &addr, sizeof(addr)));
}
int uv__tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr) {
- return uv__bind(handle,
- AF_INET6,
- (struct sockaddr*)&addr,
- sizeof(struct sockaddr_in6));
+ return uv_translate_sys_error(
+ uv__bind(handle, AF_INET6, (struct sockaddr*) &addr, sizeof(addr)));
}
uv_loop_t* loop = handle->loop;
unsigned int i, simultaneous_accepts;
uv_tcp_accept_t* req;
+ int err;
assert(backlog > 0);
}
if (handle->flags & UV_HANDLE_READING) {
- uv__set_artificial_error(loop, UV_EISCONN);
- return -1;
+ return WSAEISCONN;
}
if (handle->flags & UV_HANDLE_BIND_ERROR) {
- uv__set_sys_error(loop, handle->bind_error);
- return -1;
+ return handle->bind_error;
}
- if (!(handle->flags & UV_HANDLE_BOUND) &&
- uv_tcp_bind(handle, uv_addr_ip4_any_) < 0)
- return -1;
+ if (!(handle->flags & UV_HANDLE_BOUND)) {
+ err = uv_tcp_bind(handle, uv_addr_ip4_any_);
+ if (err)
+ return err;
+ }
if (!handle->func_acceptex) {
- if(!uv_get_acceptex_function(handle->socket, &handle->func_acceptex)) {
- uv__set_sys_error(loop, WSAEAFNOSUPPORT);
- return -1;
+ if (!uv_get_acceptex_function(handle->socket, &handle->func_acceptex)) {
+ return WSAEAFNOSUPPORT;
}
}
if (!(handle->flags & UV_HANDLE_SHARED_TCP_SOCKET) &&
listen(handle->socket, backlog) == SOCKET_ERROR) {
- uv__set_sys_error(loop, WSAGetLastError());
- return -1;
+ return WSAGetLastError();
}
handle->flags |= UV_HANDLE_LISTENING;
int uv_tcp_accept(uv_tcp_t* server, uv_tcp_t* client) {
uv_loop_t* loop = server->loop;
- int rv = 0;
+ int err = 0;
int family;
uv_tcp_accept_t* req = server->pending_accepts;
if (!req) {
/* No valid connections found, so we error out. */
- uv__set_sys_error(loop, WSAEWOULDBLOCK);
- return -1;
+ return WSAEWOULDBLOCK;
}
if (req->accept_socket == INVALID_SOCKET) {
- uv__set_sys_error(loop, WSAENOTCONN);
- return -1;
+ return WSAENOTCONN;
}
if (server->flags & UV_HANDLE_IPV6) {
family = AF_INET;
}
- if (uv_tcp_set_socket(client->loop,
- client,
- req->accept_socket,
- family,
- 0) < 0) {
+ err = uv_tcp_set_socket(client->loop,
+ client,
+ req->accept_socket,
+ family,
+ 0);
+ if (err) {
closesocket(req->accept_socket);
- rv = -1;
} else {
uv_connection_init((uv_stream_t*) client);
/* AcceptEx() implicitly binds the accepted socket. */
loop->active_tcp_streams++;
- return rv;
+ return err;
}
int addrsize = sizeof(struct sockaddr_in);
BOOL success;
DWORD bytes;
+ int err;
if (handle->flags & UV_HANDLE_BIND_ERROR) {
- uv__set_sys_error(loop, handle->bind_error);
- return -1;
+ return handle->bind_error;
}
- if (!(handle->flags & UV_HANDLE_BOUND) &&
- uv_tcp_bind(handle, uv_addr_ip4_any_) < 0)
- return -1;
+ if (!(handle->flags & UV_HANDLE_BOUND)) {
+ err = uv_tcp_bind(handle, uv_addr_ip4_any_);
+ if (err)
+ return err;
+ }
if (!handle->func_connectex) {
- if(!uv_get_connectex_function(handle->socket, &handle->func_connectex)) {
- uv__set_sys_error(loop, WSAEAFNOSUPPORT);
- return -1;
+ if (!uv_get_connectex_function(handle->socket, &handle->func_connectex)) {
+ return WSAEAFNOSUPPORT;
}
}
handle->reqs_pending++;
REGISTER_HANDLE_REQ(loop, handle, req);
} else {
- uv__set_sys_error(loop, WSAGetLastError());
- return -1;
+ return WSAGetLastError();
}
return 0;
int addrsize = sizeof(struct sockaddr_in6);
BOOL success;
DWORD bytes;
+ int err;
if (handle->flags & UV_HANDLE_BIND_ERROR) {
- uv__set_sys_error(loop, handle->bind_error);
- return -1;
+ return handle->bind_error;
}
- if (!(handle->flags & UV_HANDLE_BOUND) &&
- uv_tcp_bind6(handle, uv_addr_ip6_any_) < 0)
- return -1;
+ if (!(handle->flags & UV_HANDLE_BOUND)) {
+ err = uv_tcp_bind6(handle, uv_addr_ip6_any_);
+ if (err)
+ return err;
+ }
if (!handle->func_connectex) {
- if(!uv_get_connectex_function(handle->socket, &handle->func_connectex)) {
- uv__set_sys_error(loop, WSAEAFNOSUPPORT);
- return -1;
+ if (!uv_get_connectex_function(handle->socket, &handle->func_connectex)) {
+ return WSAEAFNOSUPPORT;
}
}
handle->reqs_pending++;
REGISTER_HANDLE_REQ(loop, handle, req);
} else {
- uv__set_sys_error(loop, WSAGetLastError());
- return -1;
+ return WSAGetLastError();
}
return 0;
int result;
if (!(handle->flags & UV_HANDLE_BOUND)) {
- uv__set_sys_error(loop, WSAEINVAL);
- return -1;
+ return UV_EINVAL;
}
if (handle->flags & UV_HANDLE_BIND_ERROR) {
- uv__set_sys_error(loop, handle->bind_error);
- return -1;
+ return uv_translate_sys_error(handle->bind_error);
}
result = getsockname(handle->socket, name, namelen);
if (result != 0) {
- uv__set_sys_error(loop, WSAGetLastError());
- return -1;
+ return uv_translate_sys_error(WSAGetLastError());
}
return 0;
int result;
if (!(handle->flags & UV_HANDLE_BOUND)) {
- uv__set_sys_error(loop, WSAEINVAL);
- return -1;
+ return UV_EINVAL;
}
if (handle->flags & UV_HANDLE_BIND_ERROR) {
- uv__set_sys_error(loop, handle->bind_error);
- return -1;
+ return uv_translate_sys_error(handle->bind_error);
}
result = getpeername(handle->socket, name, namelen);
if (result != 0) {
- uv__set_sys_error(loop, WSAGetLastError());
- return -1;
+ return uv_translate_sys_error(WSAGetLastError());
}
return 0;
}
} else {
/* Send failed due to an error. */
- uv__set_sys_error(loop, WSAGetLastError());
- return -1;
+ return WSAGetLastError();
}
return 0;
/*
* Turn WSAECONNABORTED into UV_ECONNRESET to be consistent with Unix.
*/
- uv__set_error(loop, UV_ECONNRESET, err);
- } else {
- uv__set_sys_error(loop, err);
+ err = WSAECONNRESET;
}
- handle->read_cb((uv_stream_t*)handle, -1, buf);
+ handle->read_cb((uv_stream_t*)handle,
+ uv_translate_sys_error(err),
+ buf);
}
} else {
if (!(handle->flags & UV_HANDLE_ZERO_READ)) {
}
handle->flags &= ~UV_HANDLE_READABLE;
- uv__set_error(loop, UV_EOF, ERROR_SUCCESS);
buf.base = 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;
}
}
handle->flags &= ~(UV_HANDLE_READING | UV_HANDLE_READABLE);
DECREASE_ACTIVE_COUNT(loop, handle);
- uv__set_error(loop, UV_EOF, ERROR_SUCCESS);
- handle->read_cb((uv_stream_t*)handle, -1, buf);
+ handle->read_cb((uv_stream_t*)handle, UV_EOF, buf);
break;
}
} else {
err = WSAGetLastError();
if (err == WSAEWOULDBLOCK) {
/* 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);
} else {
/* Ouch! serious error. */
if (err == WSAECONNABORTED) {
/* Turn WSAECONNABORTED into UV_ECONNRESET to be consistent with */
/* Unix. */
- uv__set_error(loop, UV_ECONNRESET, err);
- } else {
- uv__set_sys_error(loop, err);
+ err = WSAECONNRESET;
}
- handle->read_cb((uv_stream_t*)handle, -1, buf);
+ handle->read_cb((uv_stream_t*)handle,
+ uv_translate_sys_error(err),
+ buf);
}
break;
}
void uv_process_tcp_write_req(uv_loop_t* loop, uv_tcp_t* handle,
uv_write_t* req) {
+ int err;
+
assert(handle->type == UV_TCP);
assert(handle->write_queue_size >= req->queued_bytes);
}
if (req->cb) {
- uv__set_sys_error(loop, GET_REQ_SOCK_ERROR(req));
- ((uv_write_cb)req->cb)(req, loop->last_err.code == UV_OK ? 0 : -1);
+ err = GET_REQ_SOCK_ERROR(req);
+ req->cb(req, uv_translate_sys_error(err));
}
handle->write_reqs_pending--;
void uv_process_tcp_accept_req(uv_loop_t* loop, uv_tcp_t* handle,
uv_req_t* raw_req) {
uv_tcp_accept_t* req = (uv_tcp_accept_t*) raw_req;
+ int err;
assert(handle->type == UV_TCP);
handle->flags &= ~UV_HANDLE_LISTENING;
DECREASE_ACTIVE_COUNT(loop, handle);
if (handle->connection_cb) {
- uv__set_sys_error(loop, GET_REQ_SOCK_ERROR(req));
- handle->connection_cb((uv_stream_t*)handle, -1);
+ err = GET_REQ_SOCK_ERROR(req);
+ handle->connection_cb((uv_stream_t*)handle,
+ uv_translate_sys_error(err));
}
}
} else if (REQ_SUCCESS(req) &&
void uv_process_tcp_connect_req(uv_loop_t* loop, uv_tcp_t* handle,
uv_connect_t* req) {
+ int err;
+
assert(handle->type == UV_TCP);
UNREGISTER_HANDLE_REQ(loop, handle, req);
+ err = 0;
if (REQ_SUCCESS(req)) {
if (setsockopt(handle->socket,
SOL_SOCKET,
uv_connection_init((uv_stream_t*)handle);
handle->flags |= UV_HANDLE_READABLE | UV_HANDLE_WRITABLE;
loop->active_tcp_streams++;
- ((uv_connect_cb)req->cb)(req, 0);
} else {
- uv__set_sys_error(loop, WSAGetLastError());
- ((uv_connect_cb)req->cb)(req, -1);
+ err = WSAGetLastError();
}
} else {
- uv__set_sys_error(loop, GET_REQ_SOCK_ERROR(req));
- ((uv_connect_cb)req->cb)(req, -1);
+ err = GET_REQ_SOCK_ERROR(req);
}
+ req->cb(req, uv_translate_sys_error(err));
DECREASE_PENDING_REQ_COUNT(handle);
}
int uv_tcp_import(uv_tcp_t* tcp, WSAPROTOCOL_INFOW* socket_protocol_info,
int tcp_connection) {
+ int err;
+
SOCKET socket = WSASocketW(AF_INET,
SOCK_STREAM,
IPPROTO_IP,
WSA_FLAG_OVERLAPPED);
if (socket == INVALID_SOCKET) {
- uv__set_sys_error(tcp->loop, WSAGetLastError());
- return -1;
+ return WSAGetLastError();
}
if (!SetHandleInformation((HANDLE) socket, HANDLE_FLAG_INHERIT, 0)) {
- uv__set_sys_error(tcp->loop, GetLastError());
+ err = GetLastError();
closesocket(socket);
- return -1;
+ return err;
}
- if (uv_tcp_set_socket(tcp->loop,
- tcp,
- socket,
- socket_protocol_info->iAddressFamily,
- 1) < 0) {
+ err = uv_tcp_set_socket(tcp->loop,
+ tcp,
+ socket,
+ socket_protocol_info->iAddressFamily,
+ 1);
+ if (err) {
closesocket(socket);
- return -1;
+ return err;
}
if (tcp_connection) {
int uv_tcp_nodelay(uv_tcp_t* handle, int enable) {
- if (handle->socket != INVALID_SOCKET &&
- uv__tcp_nodelay(handle, handle->socket, enable)) {
- return -1;
+ int err;
+
+ if (handle->socket != INVALID_SOCKET) {
+ err = uv__tcp_nodelay(handle, handle->socket, enable);
+ if (err)
+ return err;
}
if (enable) {
int uv_tcp_keepalive(uv_tcp_t* handle, int enable, unsigned int delay) {
- if (handle->socket != INVALID_SOCKET &&
- uv__tcp_keepalive(handle, handle->socket, enable, delay)) {
- return -1;
+ int err;
+
+ if (handle->socket != INVALID_SOCKET) {
+ err = uv__tcp_keepalive(handle, handle->socket, enable, delay);
+ if (err)
+ return err;
}
if (enable) {
if (!(handle->flags & UV_HANDLE_LISTENING)) {
if (!(handle->flags & UV_HANDLE_BOUND)) {
- uv__set_artificial_error(handle->loop, UV_EINVAL);
- return -1;
+ return ERROR_INVALID_PARAMETER;
}
if (listen(handle->socket, SOMAXCONN) == SOCKET_ERROR) {
- uv__set_sys_error(handle->loop, WSAGetLastError());
- return -1;
+ return WSAGetLastError();
}
}
}
if (WSADuplicateSocketW(handle->socket, pid, protocol_info)) {
- uv__set_sys_error(handle->loop, WSAGetLastError());
- return -1;
+ return WSAGetLastError();
}
handle->flags |= UV_HANDLE_SHARED_TCP_SOCKET;
int uv_tcp_simultaneous_accepts(uv_tcp_t* handle, int enable) {
if (handle->flags & UV_HANDLE_CONNECTION) {
- uv__set_artificial_error(handle->loop, UV_EINVAL);
- return -1;
+ return UV_EINVAL;
}
/* Check if we're already in the desired mode. */
/* Don't allow switching from single pending accept to many. */
if (enable) {
- uv__set_artificial_error(handle->loop, UV_ENOTSUP);
- return -1;
+ return UV_ENOTSUP;
}
/* Check if we're in a middle of changing the number of pending accepts. */
assert(socket != 0 && socket != INVALID_SOCKET);
if (!CancelIo((HANDLE) socket)) {
- return -1;
+ return GetLastError();
}
/* It worked. */
int uv_tcp_open(uv_tcp_t* handle, uv_os_sock_t sock) {
WSAPROTOCOL_INFOW protocol_info;
int opt_len;
+ int err;
/* Detect the address family of the socket. */
opt_len = (int) sizeof protocol_info;
SO_PROTOCOL_INFOW,
(char*) &protocol_info,
&opt_len) == SOCKET_ERROR) {
- uv__set_sys_error(handle->loop, GetLastError());
- return -1;
+ return uv_translate_sys_error(GetLastError());
}
/* Make the socket non-inheritable */
if (!SetHandleInformation((HANDLE) sock, HANDLE_FLAG_INHERIT, 0)) {
- uv__set_sys_error(handle->loop, GetLastError());
- return -1;
+ return uv_translate_sys_error(GetLastError());
}
- if (uv_tcp_set_socket(handle->loop,
- handle,
- sock,
- protocol_info.iAddressFamily,
- 1) < 0) {
- return -1;
+ err = uv_tcp_set_socket(handle->loop,
+ handle,
+ sock,
+ protocol_info.iAddressFamily,
+ 1);
+ if (err) {
+ return uv_translate_sys_error(err);
}
return 0;
int uv_thread_join(uv_thread_t *tid) {
if (WaitForSingleObject(*tid, INFINITE))
- return -1;
+ return uv_translate_sys_error(GetLastError());
else {
CloseHandle(*tid);
*tid = 0;
if (TryEnterCriticalSection(mutex))
return 0;
else
- return -1;
+ return UV_EAGAIN;
}
int uv_sem_init(uv_sem_t* sem, unsigned int value) {
*sem = CreateSemaphore(NULL, value, INT_MAX, NULL);
- return *sem ? 0 : -1;
+ if (*sem == NULL)
+ return uv_translate_sys_error(GetLastError());
+ else
+ return 0;
}
return 0;
if (r == WAIT_TIMEOUT)
- return -1;
+ return UV_EAGAIN;
abort();
return -1; /* Satisfy the compiler. */
if (pTryAcquireSRWLockShared(&rwlock->srwlock_))
return 0;
else
- return -1;
+ return UV_EBUSY; /* TODO(bnoordhuis) EAGAIN when owned by this thread. */
}
if (pTryAcquireSRWLockExclusive(&rwlock->srwlock_))
return 0;
else
- return -1;
+ return UV_EBUSY; /* TODO(bnoordhuis) EAGAIN when owned by this thread. */
}
inline static int uv__rwlock_fallback_init(uv_rwlock_t* rwlock) {
- if (uv_mutex_init(&rwlock->fallback_.read_mutex_))
- return -1;
+ int err;
+
+ 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_);
- return -1;
+ return err;
}
rwlock->fallback_.num_readers_ = 0;
inline static int uv__rwlock_fallback_tryrdlock(uv_rwlock_t* rwlock) {
- int ret;
+ int err;
- ret = -1;
-
- if (uv_mutex_trylock(&rwlock->fallback_.read_mutex_))
+ err = uv_mutex_trylock(&rwlock->fallback_.read_mutex_);
+ if (err)
goto out;
+ err = 0;
if (rwlock->fallback_.num_readers_ == 0)
- ret = uv_mutex_trylock(&rwlock->fallback_.write_mutex_);
- else
- ret = 0;
+ err = uv_mutex_trylock(&rwlock->fallback_.write_mutex_);
- if (ret == 0)
+ if (err == 0)
rwlock->fallback_.num_readers_++;
uv_mutex_unlock(&rwlock->fallback_.read_mutex_);
out:
- return ret;
+ return err;
}
*/
inline static int uv_cond_fallback_init(uv_cond_t* cond) {
+ int err;
+
/* Initialize the count to 0. */
cond->fallback.waiters_count = 0;
FALSE, /* auto-reset event */
FALSE, /* non-signaled initially */
NULL); /* unnamed */
- if (!cond->fallback.signal_event)
+ if (!cond->fallback.signal_event) {
+ err = GetLastError();
goto error2;
+ }
/* Create a manual-reset event. */
cond->fallback.broadcast_event = CreateEvent(NULL, /* no security */
TRUE, /* manual-reset */
FALSE, /* non-signaled */
NULL); /* unnamed */
- if (!cond->fallback.broadcast_event)
+ if (!cond->fallback.broadcast_event) {
+ err = GetLastError();
goto error;
+ }
return 0;
CloseHandle(cond->fallback.signal_event);
error2:
DeleteCriticalSection(&cond->fallback.waiters_count_lock);
- return -1;
+ return uv_translate_sys_error(err);
}
return 0;
if (result == WAIT_TIMEOUT)
- return -1;
+ return UV_ETIMEDOUT;
abort();
return -1; /* Satisfy the compiler. */
return 0;
if (GetLastError() != ERROR_TIMEOUT)
abort();
- return -1;
+ return UV_ETIMEDOUT;
}
int uv_barrier_init(uv_barrier_t* barrier, unsigned int count) {
+ int err;
+
barrier->n = count;
barrier->count = 0;
- if (uv_mutex_init(&barrier->mutex))
- return -1;
+ err = uv_mutex_init(&barrier->mutex);
+ if (err)
+ return err;
- if (uv_sem_init(&barrier->turnstile1, 0))
+ err = uv_sem_init(&barrier->turnstile1, 0);
+ if (err)
goto error2;
- if (uv_sem_init(&barrier->turnstile2, 1))
+ err = uv_sem_init(&barrier->turnstile2, 1);
+ if (err)
goto error;
return 0;
uv_sem_destroy(&barrier->turnstile1);
error2:
uv_mutex_destroy(&barrier->mutex);
- return -1;
+ return err;
}
int uv_queue_work(uv_loop_t* loop, uv_work_t* req, uv_work_cb work_cb,
uv_after_work_cb after_work_cb) {
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);
if (!QueueUserWorkItem(&uv_work_thread_proc, req, WT_EXECUTELONGFUNCTION)) {
- uv__set_sys_error(loop, GetLastError());
- return -1;
+ return uv_translate_sys_error(GetLastError());
}
uv__req_register(loop, req);
int uv_cancel(uv_req_t* req) {
- return -1;
+ return UV_ENOSYS;
}
/* If timer_cb is NULL that means that the timer was never started. */
if (!handle->timer_cb) {
- uv__set_sys_error(loop, ERROR_INVALID_DATA);
- return -1;
+ return UV_EINVAL;
}
if (handle->flags & UV_HANDLE_ACTIVE) {
#include <string.h>
#if defined(_MSC_VER) && _MSC_VER < 1600
-# include "uv-private/stdint-msvc2008.h"
+# include "stdint-msvc2008.h"
#else
# include <stdint.h>
#endif
handle = (HANDLE) _get_osfhandle(fd);
if (handle == INVALID_HANDLE_VALUE) {
- uv__set_artificial_error(loop, UV_EBADF);
- return -1;
+ return UV_EBADF;
}
if (!readable) {
/* Obtain the screen buffer info with the output handle. */
if (!GetConsoleScreenBufferInfo(handle, &screen_buffer_info)) {
- uv__set_sys_error(loop, GetLastError());
- return -1;
+ return uv_translate_sys_error(GetLastError());
}
/* Obtain the the tty_output_lock because the virtual window state is */
unsigned char was_reading;
uv_alloc_cb alloc_cb;
uv_read_cb read_cb;
+ int err;
if (!(tty->flags & UV_HANDLE_TTY_READABLE)) {
- uv__set_artificial_error(tty->loop, UV_EINVAL);
- return -1;
+ return UV_EINVAL;
}
if (!!mode == !!(tty->flags & UV_HANDLE_TTY_RAW)) {
}
if (!SetConsoleMode(tty->handle, flags)) {
- uv__set_sys_error(tty->loop, GetLastError());
- return -1;
+ return uv_translate_sys_error(GetLastError());
}
/* If currently reading, stop, and restart reading. */
alloc_cb = tty->alloc_cb;
read_cb = tty->read_cb;
- if (was_reading && uv_tty_read_stop(tty) != 0) {
- return -1;
+ if (was_reading) {
+ err = uv_tty_read_stop(tty);
+ if (err) {
+ return uv_translate_sys_error(err);
+ }
}
} else {
was_reading = 0;
tty->flags |= mode ? UV_HANDLE_TTY_RAW : 0;
/* If we just stopped reading, restart. */
- if (was_reading && uv_tty_read_start(tty, alloc_cb, read_cb) != 0) {
- return -1;
+ if (was_reading) {
+ err = uv_tty_read_start(tty, alloc_cb, read_cb);
+ if (err) {
+ return uv_translate_sys_error(err);
+ }
}
return 0;
CONSOLE_SCREEN_BUFFER_INFO info;
if (!GetConsoleScreenBufferInfo(tty->handle, &info)) {
- uv__set_sys_error(tty->loop, GetLastError());
- return -1;
+ return uv_translate_sys_error(GetLastError());
}
EnterCriticalSection(&uv_tty_output_lock);
/* An error occurred while waiting for the event. */
if ((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, -1, uv_null_buf_);
+ handle->read_cb((uv_stream_t*)handle,
+ uv_translate_sys_error(GET_REQ_ERROR(req)),
+ uv_null_buf_);
}
goto out;
}
/* Fetch the number of events */
if (!GetNumberOfConsoleInputEvents(handle->handle, &records_left)) {
- uv__set_sys_error(loop, GetLastError());
handle->flags &= ~UV_HANDLE_READING;
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;
}
&handle->last_input_record,
1,
&records_read)) {
- uv__set_sys_error(loop, GetLastError());
handle->flags &= ~UV_HANDLE_READING;
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;
}
records_left--;
/* If the utf16 character(s) couldn't be converted something must */
/* be wrong. */
if (!char_len) {
- uv__set_sys_error(loop, GetLastError());
handle->flags &= ~UV_HANDLE_READING;
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;
}
/* Real error */
handle->flags &= ~UV_HANDLE_READING;
DECREASE_ACTIVE_COUNT(loop, handle);
- uv__set_sys_error(loop, GET_REQ_ERROR(req));
- handle->read_cb((uv_stream_t*) handle, -1, buf);
+ handle->read_cb((uv_stream_t*) handle,
+ uv_translate_sys_error(GET_REQ_ERROR(req)),
+ buf);
} else {
/* 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);
}
/* Read successful */
/* TODO: read unicode, convert to utf-8 */
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);
}
uv_loop_t* loop = handle->loop;
if (!(handle->flags & UV_HANDLE_TTY_READABLE)) {
- uv__set_artificial_error(handle->loop, UV_EINVAL);
- return -1;
+ return ERROR_INVALID_PARAMETER;
}
handle->flags |= UV_HANDLE_READING;
DWORD written;
memset(&record, 0, sizeof record);
if (!WriteConsoleInputW(handle->handle, &record, 1, &written)) {
- uv__set_sys_error(loop, GetLastError());
- return -1;
+ return GetLastError();
}
}
void uv_process_tty_write_req(uv_loop_t* loop, uv_tty_t* handle,
uv_write_t* req) {
+ int err;
handle->write_queue_size -= req->queued_bytes;
UNREGISTER_HANDLE_REQ(loop, handle, req);
if (req->cb) {
- uv__set_sys_error(loop, GET_REQ_ERROR(req));
- ((uv_write_cb)req->cb)(req, loop->last_err.code == UV_OK ? 0 : -1);
+ err = GET_REQ_ERROR(req);
+ req->cb(req, uv_translate_sys_error(err));
}
handle->write_reqs_pending--;
/* TTY shutdown is really just a no-op */
if (handle->shutdown_req->cb) {
if (handle->flags & UV__HANDLE_CLOSING) {
- uv__set_artificial_error(loop, UV_ECANCELED);
- handle->shutdown_req->cb(handle->shutdown_req, -1);
+ handle->shutdown_req->cb(handle->shutdown_req, UV_ECANCELED);
} else {
handle->shutdown_req->cb(handle->shutdown_req, 0);
}
int result;
if (!(handle->flags & UV_HANDLE_BOUND)) {
- uv__set_sys_error(loop, WSAEINVAL);
- return -1;
+ return UV_EINVAL;
}
result = getsockname(handle->socket, name, namelen);
if (result != 0) {
- uv__set_sys_error(loop, WSAGetLastError());
- return -1;
+ return uv_translate_sys_error(WSAGetLastError());
}
return 0;
SO_REUSEADDR,
(char*) &yes,
sizeof yes) == SOCKET_ERROR) {
- uv__set_sys_error(loop, WSAGetLastError());
- return -1;
+ return WSAGetLastError();
}
/* Set the socket to nonblocking mode */
if (ioctlsocket(socket, FIONBIO, &yes) == SOCKET_ERROR) {
- uv__set_sys_error(loop, WSAGetLastError());
- return -1;
+ return WSAGetLastError();
}
/* Make the socket non-inheritable */
if (!SetHandleInformation((HANDLE)socket, HANDLE_FLAG_INHERIT, 0)) {
- uv__set_sys_error(loop, GetLastError());
- return -1;
+ return GetLastError();
}
/* Associate it with the I/O completion port. */
loop->iocp,
(ULONG_PTR)socket,
0) == NULL) {
- uv__set_sys_error(loop, GetLastError());
- return -1;
+ return GetLastError();
}
if (pSetFileCompletionNotificationModes) {
SO_PROTOCOL_INFOW,
(char*) &info,
&opt_len) == SOCKET_ERROR) {
- uv__set_sys_error(loop, GetLastError());
- return -1;
+ return GetLastError();
}
if (info.ProtocolChain.ChainLen == 1) {
handle->func_wsarecv = uv_wsarecv_workaround;
handle->func_wsarecvfrom = uv_wsarecvfrom_workaround;
} else if (GetLastError() != ERROR_INVALID_FUNCTION) {
- uv__set_sys_error(loop, GetLastError());
- return -1;
+ return GetLastError();
}
}
}
int addrsize,
unsigned int flags) {
int r;
+ int err;
DWORD no = 0;
if ((flags & UV_UDP_IPV6ONLY) && family != AF_INET6) {
/* UV_UDP_IPV6ONLY is supported only for IPV6 sockets */
- uv__set_artificial_error(handle->loop, UV_EINVAL);
- return -1;
+ return ERROR_INVALID_PARAMETER;
}
if (handle->socket == INVALID_SOCKET) {
SOCKET sock = socket(family, SOCK_DGRAM, 0);
if (sock == INVALID_SOCKET) {
- uv__set_sys_error(handle->loop, WSAGetLastError());
- return -1;
+ return WSAGetLastError();
}
- 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);
- return -1;
+ return err;
}
if (family == AF_INET6)
r = bind(handle->socket, addr, addrsize);
if (r == SOCKET_ERROR) {
- uv__set_sys_error(handle->loop, WSAGetLastError());
- return -1;
+ return WSAGetLastError();
}
handle->flags |= UV_HANDLE_BOUND;
}
-int uv__udp_bind(uv_udp_t* handle, struct sockaddr_in addr,
- unsigned int flags) {
- return uv__bind(handle,
- AF_INET,
- (struct sockaddr*) &addr,
- sizeof(struct sockaddr_in),
- flags);
+int uv__udp_bind(uv_udp_t* handle,
+ struct sockaddr_in addr,
+ unsigned int flags) {
+ int err;
+
+ err = uv__bind(handle,
+ 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,
- unsigned int flags) {
- return uv__bind(handle,
- AF_INET6,
- (struct sockaddr*) &addr,
- sizeof(struct sockaddr_in6),
- flags);
+int uv__udp_bind6(uv_udp_t* handle,
+ struct sockaddr_in6 addr,
+ unsigned int flags) {
+ int err;
+
+ err = uv__bind(handle,
+ AF_INET6,
+ (struct sockaddr*) &addr,
+ sizeof(addr),
+ flags);
+
+ return uv_translate_sys_error(err);
}
int uv__udp_recv_start(uv_udp_t* handle, uv_alloc_cb alloc_cb,
uv_udp_recv_cb recv_cb) {
uv_loop_t* loop = handle->loop;
+ int err;
if (handle->flags & UV_HANDLE_READING) {
- uv__set_sys_error(loop, WSAEALREADY);
- return -1;
+ return WSAEALREADY;
}
- if (!(handle->flags & UV_HANDLE_BOUND) &&
- uv_udp_bind(handle, uv_addr_ip4_any_, 0) < 0) {
- return -1;
+ if (!(handle->flags & UV_HANDLE_BOUND)) {
+ err = uv_udp_bind(handle, uv_addr_ip4_any_, 0);
+ if (err)
+ return err;
}
handle->flags |= UV_HANDLE_READING;
REGISTER_HANDLE_REQ(loop, handle, req);
} else {
/* Send failed due to an error. */
- uv__set_sys_error(loop, WSAGetLastError());
- return -1;
+ return WSAGetLastError();
}
return 0;
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 err;
- if (!(handle->flags & UV_HANDLE_BOUND) &&
- uv_udp_bind(handle, uv_addr_ip4_any_, 0) < 0) {
- return -1;
+ if (!(handle->flags & UV_HANDLE_BOUND)) {
+ err = uv_udp_bind(handle, uv_addr_ip4_any_, 0);
+ if (err)
+ return err;
}
return uv__send(req,
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 err;
- if (!(handle->flags & UV_HANDLE_BOUND) &&
- uv_udp_bind6(handle, uv_addr_ip6_any_, 0) < 0) {
- return -1;
+ if (!(handle->flags & UV_HANDLE_BOUND)) {
+ err = uv_udp_bind6(handle, uv_addr_ip6_any_, 0);
+ if (err)
+ return err;
}
return uv__send(req,
/* A real error occurred. Report the error to the user only if we're */
/* currently reading. */
if (handle->flags & UV_HANDLE_READING) {
- uv__set_sys_error(loop, err);
uv_udp_recv_stop(handle);
buf = (handle->flags & UV_HANDLE_ZERO_READ) ?
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;
}
UV_UDP_PARTIAL);
} if (err == WSAEWOULDBLOCK) {
/* Kernel buffer empty */
- uv__set_sys_error(loop, WSAEWOULDBLOCK);
handle->recv_cb(handle, 0, buf, NULL, 0);
} else if (err != WSAECONNRESET && err != WSAENETRESET) {
/* Serious error. WSAECONNRESET/WSANETRESET is ignored because this */
/* just indicates that a previous sendto operation failed. */
uv_udp_recv_stop(handle);
- uv__set_sys_error(loop, err);
- handle->recv_cb(handle, -1, buf, NULL, 0);
+ handle->recv_cb(handle, uv_translate_sys_error(err), buf, NULL, 0);
}
}
}
void uv_process_udp_send_req(uv_loop_t* loop, uv_udp_t* handle,
uv_udp_send_t* req) {
+ int err;
+
assert(handle->type == UV_UDP);
UNREGISTER_HANDLE_REQ(loop, handle, req);
if (req->cb) {
- if (REQ_SUCCESS(req)) {
- req->cb(req, 0);
- } else {
- uv__set_sys_error(loop, GET_REQ_SOCK_ERROR(req));
- req->cb(req, -1);
+ err = 0;
+ if (!REQ_SUCCESS(req)) {
+ err = GET_REQ_SOCK_ERROR(req);
}
+ req->cb(req, uv_translate_sys_error(err));
}
DECREASE_PENDING_REQ_COUNT(handle);
int uv_udp_set_membership(uv_udp_t* handle, const char* multicast_addr,
const char* interface_addr, uv_membership membership) {
+ int err;
int optname;
struct ip_mreq mreq;
/* If the socket is unbound, bind to inaddr_any. */
- if (!(handle->flags & UV_HANDLE_BOUND) &&
- uv_udp_bind(handle, uv_addr_ip4_any_, 0) < 0) {
- return -1;
+ if (!(handle->flags & UV_HANDLE_BOUND)) {
+ err = uv__udp_bind(handle, uv_addr_ip4_any_, 0);
+ if (err)
+ return uv_translate_sys_error(err);
}
if (handle->flags & UV_HANDLE_IPV6) {
- uv__set_artificial_error(handle->loop, UV_ENOSYS);
- return -1;
+ return UV_ENOSYS;
}
memset(&mreq, 0, sizeof mreq);
optname = IP_DROP_MEMBERSHIP;
break;
default:
- return uv__set_artificial_error(handle->loop, UV_EINVAL);
+ return UV_EINVAL;
}
if (setsockopt(handle->socket,
optname,
(char*) &mreq,
sizeof mreq) == SOCKET_ERROR) {
- uv__set_sys_error(handle->loop, WSAGetLastError());
- return -1;
+ return uv_translate_sys_error(WSAGetLastError());
}
return 0;
int uv_udp_set_broadcast(uv_udp_t* handle, int value) {
BOOL optval = (BOOL) value;
+ int err;
/* If the socket is unbound, bind to inaddr_any. */
- if (!(handle->flags & UV_HANDLE_BOUND) &&
- uv_udp_bind(handle, uv_addr_ip4_any_, 0) < 0) {
- return -1;
+ if (!(handle->flags & UV_HANDLE_BOUND)) {
+ err = uv__udp_bind(handle, uv_addr_ip4_any_, 0);
+ if (err)
+ return uv_translate_sys_error(err);
}
if (setsockopt(handle->socket,
SO_BROADCAST,
(char*) &optval,
sizeof optval)) {
- uv__set_sys_error(handle->loop, WSAGetLastError());
- return -1;
+ return uv_translate_sys_error(WSAGetLastError());
}
+
return 0;
}
int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock) {
WSAPROTOCOL_INFOW protocol_info;
int opt_len;
+ int err;
/* Detect the address family of the socket. */
opt_len = (int) sizeof protocol_info;
SO_PROTOCOL_INFOW,
(char*) &protocol_info,
&opt_len) == SOCKET_ERROR) {
- uv__set_sys_error(handle->loop, GetLastError());
- return -1;
- }
-
- if (uv_udp_set_socket(handle->loop,
- handle,
- sock,
- protocol_info.iAddressFamily) < 0) {
- return -1;
+ return uv_translate_sys_error(GetLastError());
}
- 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) \
int uv_udp_set_##name(uv_udp_t* handle, int value) { \
DWORD optval = (DWORD) value; \
+ int err; \
\
if (!(validate(value))) { \
- uv__set_artificial_error(handle->loop, UV_EINVAL); \
- return -1; \
+ return UV_EINVAL; \
} \
\
/* If the socket is unbound, bind to inaddr_any. */ \
- if (!(handle->flags & UV_HANDLE_BOUND) && \
- uv_udp_bind(handle, uv_addr_ip4_any_, 0) < 0) { \
- return -1; \
+ if (!(handle->flags & UV_HANDLE_BOUND)) { \
+ err = uv__udp_bind(handle, uv_addr_ip4_any_, 0); \
+ if (err) \
+ return uv_translate_sys_error(err); \
} \
\
if (!(handle->flags & UV_HANDLE_IPV6)) { \
option4, \
(char*) &optval, \
sizeof optval)) { \
- uv__set_sys_error(handle->loop, WSAGetLastError()); \
- return -1; \
+ return uv_translate_sys_error(WSAGetLastError()); \
} \
} else { \
/* Set IPv6 socket option */ \
option6, \
(char*) &optval, \
sizeof optval)) { \
- uv__set_sys_error(handle->loop, WSAGetLastError()); \
- return -1; \
+ return uv_translate_sys_error(WSAGetLastError()); \
} \
} \
return 0; \
int uv_exepath(char* buffer, size_t* size_ptr) {
int utf8_len, utf16_buffer_len, utf16_len;
WCHAR* utf16_buffer;
+ int err;
if (buffer == NULL || size_ptr == NULL || *size_ptr == 0) {
- return -1;
+ return UV_EINVAL;
}
if (*size_ptr > 32768) {
utf16_buffer = (WCHAR*) malloc(sizeof(WCHAR) * utf16_buffer_len);
if (!utf16_buffer) {
- return -1;
+ return UV_ENOMEM;
}
/* Get the path as UTF-16. */
utf16_len = GetModuleFileNameW(NULL, utf16_buffer, utf16_buffer_len);
if (utf16_len <= 0) {
+ err = GetLastError();
goto error;
}
NULL,
NULL);
if (utf8_len == 0) {
+ err = GetLastError();
goto error;
}
error:
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;
WCHAR utf16_buffer[MAX_PATH];
int r;
if (buffer == NULL || size == 0) {
- return uv__new_artificial_error(UV_EINVAL);
+ return UV_EINVAL;
}
utf16_len = GetCurrentDirectoryW(MAX_PATH, utf16_buffer);
if (utf16_len == 0) {
- return uv__new_sys_error(GetLastError());
+ return uv_translate_sys_error(GetLastError());
} else if (utf16_len > MAX_PATH) {
/* This should be impossible; however the CRT has a code path to deal */
/* 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. */
NULL,
NULL);
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];
size_t utf16_len;
WCHAR drive_letter, env_var[4];
if (dir == NULL) {
- return uv__new_artificial_error(UV_EINVAL);
+ return UV_EINVAL;
}
if (MultiByteToWideChar(CP_UTF8,
/* including terminating null. If it doesn't fit, the path name must be */
/* too long. */
if (error == ERROR_INSUFFICIENT_BUFFER) {
- return uv__new_artificial_error(UV_ENAMETOOLONG);
+ return UV_ENAMETOOLONG;
} else {
- return uv__new_sys_error(error);
+ return uv_translate_sys_error(error);
}
}
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, */
/* update this, so we'll have to do it. */
utf16_len = GetCurrentDirectoryW(MAX_PATH, utf16_buffer);
if (utf16_len == 0) {
- return uv__new_sys_error(GetLastError());
+ return uv_translate_sys_error(GetLastError());
} 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 */
env_var[3] = L'\0';
if (!SetEnvironmentVariableW(env_var, utf16_buffer)) {
- return uv__new_sys_error(GetLastError());
+ return uv_translate_sys_error(GetLastError());
}
}
- return uv_ok_;
+ return 0;
}
}
-uv_err_t uv_set_process_title(const char* title) {
- uv_err_t err;
+int uv_set_process_title(const char* title) {
+ int err;
int length;
WCHAR* title_w = NULL;
/* Find out how big the buffer for the wide-char title must be */
length = uv_utf8_to_utf16(title, NULL, 0);
if (!length) {
- err = uv__new_sys_error(GetLastError());
+ err = GetLastError();
goto done;
}
length = uv_utf8_to_utf16(title, title_w, length);
if (!length) {
- err = uv__new_sys_error(GetLastError());
+ err = GetLastError();
goto done;
};
}
if (!SetConsoleTitleW(title_w)) {
- err = uv__new_sys_error(GetLastError());
+ err = GetLastError();
goto done;
}
process_title = strdup(title);
LeaveCriticalSection(&process_title_lock);
- err = uv_ok_;
+ err = 0;
done:
free(title_w);
- return err;
+ return uv_translate_sys_error(err);
}
}
-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();
EnterCriticalSection(&process_title_lock);
* we must query it with getConsoleTitleW
*/
if (!process_title && uv__get_process_title() == -1) {
- return uv__new_sys_error(GetLastError());
+ return uv_translate_sys_error(GetLastError());
}
assert(process_title);
strncpy(buffer, process_title, size);
LeaveCriticalSection(&process_title_lock);
- return uv_ok_;
+ return 0;
}
}
-uv_err_t uv_resident_set_memory(size_t* rss) {
+int uv_resident_set_memory(size_t* rss) {
HANDLE current_process;
PROCESS_MEMORY_COUNTERS pmc;
current_process = GetCurrentProcess();
if (!GetProcessMemoryInfo(current_process, &pmc, sizeof(pmc))) {
- return uv__new_sys_error(GetLastError());
+ return uv_translate_sys_error(GetLastError());
}
*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* malloced_buffer = NULL;
BYTE* buffer = (BYTE*) stack_buffer;
break;
} else if (result != ERROR_MORE_DATA) {
*uptime = 0;
- return uv__new_sys_error(result);
+ return uv_translate_sys_error(result);
}
free(malloced_buffer);
buffer = malloced_buffer = (BYTE*) malloc(buffer_size);
if (malloced_buffer == NULL) {
*uptime = 0;
- return uv__new_artificial_error(UV_ENOMEM);
+ return UV_ENOMEM;
}
}
*uptime = (double) (object_type->PerfTime.QuadPart - value) /
(double) object_type->PerfFreq.QuadPart;
free(malloced_buffer);
- return uv_ok_;
+ return 0;
}
}
/* If we get here, the uptime value was not found. */
free(malloced_buffer);
*uptime = 0;
- return uv__new_artificial_error(UV_ENOSYS);
+ return UV_ENOSYS;
internalError:
free(malloced_buffer);
*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;
SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* sppi;
DWORD sppi_size;
DWORD cpu_count, r, i;
NTSTATUS status;
ULONG result_size;
- uv_err_t err;
+ int err;
uv_cpu_info_t* cpu_info;
cpu_infos = NULL;
cpu_infos = calloc(cpu_count, sizeof *cpu_infos);
if (cpu_infos == NULL) {
- err = uv__new_artificial_error(UV_ENOMEM);
+ err = ERROR_OUTOFMEMORY;
goto error;
}
sppi_size = cpu_count * sizeof(*sppi);
sppi = malloc(sppi_size);
if (sppi == NULL) {
- err = uv__new_artificial_error(UV_ENOMEM);
+ err = ERROR_OUTOFMEMORY;
goto error;
}
sppi_size,
&result_size);
if (!NT_SUCCESS(status)) {
- err = uv__new_sys_error(pRtlNtStatusToDosError(status));
+ err = pRtlNtStatusToDosError(status);
goto error;
}
KEY_QUERY_VALUE,
&processor_key);
if (r != ERROR_SUCCESS) {
- err = uv__new_sys_error(GetLastError());
+ err = GetLastError();
goto error;
}
NULL,
(BYTE*) &cpu_speed,
&cpu_speed_size) != ERROR_SUCCESS) {
- err = uv__new_sys_error(GetLastError());
+ err = GetLastError();
RegCloseKey(processor_key);
goto error;
}
NULL,
(BYTE*) &cpu_brand,
&cpu_brand_size) != ERROR_SUCCESS) {
- err = uv__new_sys_error(GetLastError());
+ err = GetLastError();
RegCloseKey(processor_key);
goto error;
}
NULL,
NULL);
if (len == 0) {
- err = uv__new_sys_error(GetLastError());
+ err = GetLastError();
goto error;
}
/* Allocate 1 extra byte for the null terminator. */
cpu_info->model = malloc(len + 1);
if (cpu_info->model == NULL) {
- err = uv__new_artificial_error(UV_ENOMEM);
+ err = ERROR_OUTOFMEMORY;
goto error;
}
len,
NULL,
NULL) == 0) {
- err = uv__new_sys_error(GetLastError());
+ err = GetLastError();
goto error;
}
*cpu_count_ptr = cpu_count;
*cpu_infos_ptr = cpu_infos;
- return uv_ok_;
+ return 0;
error:
/* This is safe because the cpu_infos array is zeroed on allocation. */
free(cpu_infos);
free(sppi);
- return err;
+ return uv_translate_sys_error(err);
}
}
-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) {
IP_ADAPTER_ADDRESSES* win_address_buf;
ULONG win_address_buf_size;
/* all adapters. */
win_address_buf = malloc(win_address_buf_size);
if (win_address_buf == NULL)
- return uv__new_artificial_error(UV_ENOMEM);
+ return UV_ENOMEM;
continue;
/* No adapters were found. */
uv_address_buf = malloc(1);
if (uv_address_buf == NULL)
- return uv__new_artificial_error(UV_ENOMEM);
+ return UV_ENOMEM;
*count_ptr = 0;
*addresses_ptr = uv_address_buf;
- return uv_ok_;
+ return 0;
}
case ERROR_ADDRESS_NOT_ASSOCIATED:
- return uv__new_artificial_error(UV_EAGAIN);
+ return UV_EAGAIN;
case ERROR_INVALID_PARAMETER:
/* MSDN says:
* Since the first two conditions are not met, it must be that the
* adapter data is too big.
*/
- return uv__new_artificial_error(UV_ENOBUFS);
+ return UV_ENOBUFS;
default:
/* Other (unspecified) errors can happen, but we don't have any */
/* special meaning for them. */
assert(r != ERROR_SUCCESS);
- return uv__new_sys_error(r);
+ return uv_translate_sys_error(r);
}
}
FALSE);
if (name_size <= 0) {
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 = malloc(uv_address_buf_size);
if (uv_address_buf == NULL) {
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 */
if (name_size <= 0) {
free(win_address_buf);
free(uv_address_buf);
- return uv__new_sys_error(GetLastError());
+ return uv_translate_sys_error(GetLastError());
}
prefix = win_address->FirstPrefix;
*addresses_ptr = uv_address_buf;
*count_ptr = count;
- return uv_ok_;
+ return 0;
}
static void sv_read_cb(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) {
- ASSERT(nread == -1);
- ASSERT(uv_last_error(handle->loop).code == UV_EOF);
+ ASSERT(nread == UV_EOF);
uv_close((uv_handle_t*) handle, (uv_close_cb) free);
}
pinger = (pinger_t*)tcp->data;
if (nread < 0) {
- ASSERT(uv_last_error(loop).code == UV_EOF);
+ ASSERT(nread == UV_EOF);
if (buf.base) {
buf_free(buf);
static void after_write(uv_write_t* req, int status) {
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);
conns_failed++;
return;
if (status != 0) {
#if DEBUG
- fprintf(stderr,
- "connect error %s\n",
- uv_err_name(uv_last_error(uv_default_loop())));
+ fprintf(stderr, "connect error %s\n", uv_err_name(status));
#endif
uv_close((uv_handle_t*)req->handle, close_cb);
conns_failed++;
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);
uv_close((uv_handle_t*)stream, close_cb);
- if (nread == -1) {
- if (err.code == UV_EOF) {
+ if (nread < 0) {
+ if (nread == UV_EOF) {
;
- } else if (err.code == UV_ECONNRESET) {
+ } else if (nread == UV_ECONNRESET) {
conns_failed++;
} 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);
}
}
r = uv_tcp_connect(&((tcp_conn_rec*)p)->conn_req, (uv_tcp_t*)&p->stream, addr, connect_cb);
if (r) {
- fprintf(stderr, "uv_tcp_connect error %s\n",
- uv_err_name(uv_last_error(loop)));
+ fprintf(stderr, "uv_tcp_connect error %s\n", uv_err_name(r));
ASSERT(0);
}
static void connect_cb(uv_connect_t* req, int status) {
int i;
- if (status) LOG(uv_strerror(uv_last_error(loop)));
+ if (status) LOG(uv_strerror(status));
ASSERT(status == 0);
write_sockets++;
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) {
ASSERT(pipe_open == 1);
output_used += nread;
} else if (nread < 0) {
- if (err.code == UV_EOF) {
+ if (nread == UV_EOF) {
uv_close((uv_handle_t*)pipe, pipe_close_cb);
}
}
ASSERT(req != NULL);
if (status != 0) {
- ASSERT(status == -1);
- ASSERT(uv_last_error(req->handle->loop).code == UV_ECANCELED);
+ ASSERT(status == UV_ECANCELED);
return;
}
if (nread == 0)
return;
- if (nread == -1) {
- ASSERT(uv_last_error(handle->loop).code == UV_ECANCELED);
+ if (nread < 0) {
+ ASSERT(nread == UV_ECANCELED);
return;
}
if (nread >= 0)
return;
- ASSERT(uv_last_error(stream->loop).code == UV_EOF);
+ ASSERT(nread == UV_EOF);
conn = container_of(stream, conn_rec, handle);
write_req_t* wr;
if (status) {
- uv_err_t err = uv_last_error(loop);
- fprintf(stderr, "uv_write error: %s\n", uv_strerror(err));
+ fprintf(stderr, "uv_write error: %s\n", uv_strerror(status));
ASSERT(0);
}
if (nread < 0) {
/* Error or EOF */
- ASSERT (uv_last_error(loop).code == UV_EOF);
+ ASSERT(nread == UV_EOF);
if (buf.base) {
free(buf.base);
static void after_write(uv_write_t* req, int status) {
write_req_t* wr;
- uv_err_t err;
/* Free the read/write buffer and the request */
wr = (write_req_t*) req;
if (status == 0)
return;
- err = uv_last_error(loop);
- fprintf(stderr, "uv_write error: %s\n", uv_strerror(err));
+ fprintf(stderr, "uv_write error: %s\n", uv_strerror(status));
- if (err.code == UV_ECANCELED)
+ if (status == UV_ECANCELED)
return;
- ASSERT(err.code == UV_EPIPE);
+ ASSERT(status == UV_EPIPE);
uv_close((uv_handle_t*)req->handle, on_close);
}
if (nread < 0) {
/* Error or EOF */
- ASSERT (uv_last_error(loop).code == UV_EOF);
+ ASSERT(nread == UV_EOF);
if (buf.base) {
free(buf.base);
int r;
if (status != 0) {
- fprintf(stderr, "Connect error %d\n",
- uv_last_error(loop).code);
+ fprintf(stderr, "Connect error %s\n", uv_err_name(status));
}
ASSERT(status == 0);
r = uv_listen((uv_stream_t*)&tcpServer, SOMAXCONN, on_connection);
if (r) {
/* TODO: Error codes */
- fprintf(stderr, "Listen error %s\n",
- uv_err_name(uv_last_error(loop)));
+ fprintf(stderr, "Listen error %s\n", uv_err_name(r));
return 1;
}
r = uv_udp_init(loop, &udpServer);
if (r) {
- fprintf(stderr, "uv_udp_init: %s\n",
- uv_strerror(uv_last_error(loop)));
+ fprintf(stderr, "uv_udp_init: %s\n", uv_strerror(r));
return 1;
}
r = uv_udp_recv_start(&udpServer, echo_alloc, on_recv);
if (r) {
- fprintf(stderr, "uv_udp_recv_start: %s\n",
- uv_strerror(uv_last_error(loop)));
+ fprintf(stderr, "uv_udp_recv_start: %s\n", uv_strerror(r));
return 1;
}
r = uv_pipe_init(loop, &pipeServer, 0);
if (r) {
- fprintf(stderr, "uv_pipe_init: %s\n",
- uv_strerror(uv_last_error(loop)));
+ fprintf(stderr, "uv_pipe_init: %s\n", uv_strerror(r));
return 1;
}
r = uv_pipe_bind(&pipeServer, pipeName);
if (r) {
- fprintf(stderr, "uv_pipe_bind: %s\n",
- uv_strerror(uv_last_error(loop)));
+ fprintf(stderr, "uv_pipe_bind: %s\n", uv_strerror(r));
return 1;
}
r = uv_listen((uv_stream_t*)&pipeServer, SOMAXCONN, on_connection);
if (r) {
- fprintf(stderr, "uv_pipe_listen: %s\n",
- uv_strerror(uv_last_error(loop)));
+ fprintf(stderr, "uv_pipe_listen: %s\n", uv_strerror(r));
return 1;
}
#include <stdlib.h>
#if defined(_MSC_VER) && _MSC_VER < 1600
-# include "uv-private/stdint-msvc2008.h"
+# include "stdint-msvc2008.h"
#else
# include <stdint.h>
#endif
free(buf.base);
if (nread == 0) {
- ASSERT(uv_last_error(uv_default_loop()).code == UV_EAGAIN);
return;
- } else if (nread == -1) {
- ASSERT(uv_last_error(uv_default_loop()).code == UV_EOF);
+ } else if (nread < 0) {
+ ASSERT(nread == UV_EOF);
nested++;
uv_close((uv_handle_t*)tcp, close_cb);
uv_mutex_lock(&wc.mutex);
r = uv_cond_timedwait(&wc.cond, &wc.mutex, (uint64_t)(50 * 1e6));
- ASSERT(r == -1);
+ ASSERT(r == UV_ETIMEDOUT);
uv_mutex_unlock(&wc.mutex);
ASSERT(0 == uv_thread_join(&thread));
static void on_connect_with_close(uv_connect_t *req, int status) {
ASSERT((uv_stream_t*) &tcp == req->handle);
- ASSERT(status == -1);
- ASSERT(uv_last_error(uv_default_loop()).code == UV_ECONNREFUSED);
+ ASSERT(status == UV_ECONNREFUSED);
connect_cb_calls++;
ASSERT(close_cb_calls == 0);
static void on_connect_without_close(uv_connect_t *req, int status) {
- ASSERT(status == -1);
- ASSERT(uv_last_error(uv_default_loop()).code == UV_ECONNREFUSED);
+ ASSERT(status == UV_ECONNREFUSED);
connect_cb_calls++;
uv_timer_start(&timer, timer_cb, 100, 0);
char buffer_new[PATHMAX];
size_t size;
char* last_slash;
- uv_err_t err;
+ int err;
size = sizeof(buffer_orig) / sizeof(buffer_orig[0]);
err = uv_cwd(buffer_orig, size);
- ASSERT(err.code == UV_OK);
+ ASSERT(err == 0);
/* Remove trailing slash unless at a root directory. */
#ifdef _WIN32
#endif
err = uv_chdir(buffer_orig);
- ASSERT(err.code == UV_OK);
+ ASSERT(err == 0);
err = uv_cwd(buffer_new, size);
- ASSERT(err.code == UV_OK);
+ ASSERT(err == 0);
ASSERT(strcmp(buffer_orig, buffer_new) == 0);
free(buf.base);
}
- if (nread != -1) {
+ if (nread >= 0) {
ASSERT(nread == 0);
- ASSERT(uv_last_error(uv_default_loop()).code == UV_EAGAIN);
} else {
ASSERT(tcp != NULL);
- ASSERT(nread == -1);
- ASSERT(uv_last_error(uv_default_loop()).code == UV_EOF);
+ ASSERT(nread == UV_EOF);
uv_close((uv_handle_t*)tcp, close_cb);
}
}
* See https://github.com/joyent/libuv/issues/210
*/
TEST_IMPL(error_message) {
- uv_err_t e;
-
/* Cop out. Can't do proper checks on systems with
* i18n-ized error messages...
*/
- e.code = 0, e.sys_errno_ = 0;
-
- if (strcmp(uv_strerror(e), "Success") != 0) {
+ if (strcmp(uv_strerror(0), "Success") != 0) {
printf("i18n error messages detected, skipping test.\n");
return 0;
}
- e.code = UV_EINVAL, e.sys_errno_ = 0;
- ASSERT(strstr(uv_strerror(e), "Success") == NULL);
-
- 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);
+ ASSERT(strstr(uv_strerror(UV_EINVAL), "Success") == NULL);
+ ASSERT(strcmp(uv_strerror(1337), "Unknown error") == 0);
+ ASSERT(strcmp(uv_strerror(-1337), "Unknown error") == 0);
return 0;
}
int r;
uv_fs_t req;
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);
}
r = uv_fs_open(loop, &req, name, O_WRONLY | O_CREAT,
S_IWUSR | S_IRUSR, NULL);
- ASSERT(r != -1);
+ ASSERT(r >= 0);
file = r;
uv_fs_req_cleanup(&req);
r = uv_fs_close(loop, &req, file, NULL);
uv_fs_t req;
r = uv_fs_open(loop, &req, name, O_RDWR, 0, NULL);
- ASSERT(r != -1);
+ ASSERT(r >= 0);
file = r;
uv_fs_req_cleanup(&req);
r = uv_fs_write(loop, &req, file, "foo", 4, -1, NULL);
- ASSERT(r != -1);
+ ASSERT(r >= 0);
uv_fs_req_cleanup(&req);
r = uv_fs_close(loop, &req, file, NULL);
- ASSERT(r != -1);
+ ASSERT(r == 0);
uv_fs_req_cleanup(&req);
}
create_dir(loop, "watch_dir");
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);
- ASSERT(r != -1);
+ ASSERT(r == 0);
r = uv_timer_start(&timer, timer_cb_dir, 100, 0);
- ASSERT(r != -1);
+ ASSERT(r == 0);
uv_run(loop, UV_RUN_DEFAULT);
create_file(loop, "watch_dir/file2");
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);
- ASSERT(r != -1);
+ ASSERT(r == 0);
r = uv_timer_start(&timer, timer_cb_file, 100, 100);
- ASSERT(r != -1);
+ ASSERT(r == 0);
uv_run(loop, UV_RUN_DEFAULT);
r = uv_fs_event_init(loop, &fs_event, "watch_file",
fs_event_cb_file_current_dir, 0);
- ASSERT(r != -1);
+ ASSERT(r == 0);
r = uv_timer_init(loop, &timer);
ASSERT(r == 0);
"watch_dir/file1",
fs_event_cb_file,
0);
- ASSERT(r != -1);
+ ASSERT(r == 0);
uv_close((uv_handle_t*)&fs_event, close_cb);
touch_file(loop, "watch_dir/file1");
"watch_dir/file1",
fs_event_cb_file,
0);
- ASSERT(r != -1);
+ ASSERT(r == 0);
uv_close((uv_handle_t*)&fs_event, close_cb);
switch (poll_cb_called++) {
case 0:
- ASSERT(status == -1);
- ASSERT(uv_last_error(loop).code == UV_ENOENT);
+ ASSERT(status == UV_ENOENT);
ASSERT(0 == memcmp(prev, &zero_statbuf, sizeof(zero_statbuf)));
ASSERT(0 == memcmp(curr, &zero_statbuf, sizeof(zero_statbuf)));
touch_file(FIXTURE);
break;
case 4:
- ASSERT(status == -1);
+ ASSERT(status == UV_ENOENT);
ASSERT(0 != memcmp(prev, &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);
break;
/* On windows, chown is a no-op and always succeeds. */
ASSERT(req->result == 0);
#else
- /* On unix, chown'ing the root directory is not allowed. */
- ASSERT(req->result == -1);
- ASSERT(req->errorno == UV_EPERM);
+ /* On unix, chown'ing the root directory is not allowed -
+ * unless you're root, of course.
+ */
+ if (geteuid() == 0)
+ ASSERT(req->result == 0);
+ else
+ ASSERT(req->result == UV_EPERM);
#endif
chown_cb_count++;
uv_fs_req_cleanup(req);
static void unlink_cb(uv_fs_t* req) {
ASSERT(req == &unlink_req);
ASSERT(req->fs_type == UV_FS_UNLINK);
- ASSERT(req->result != -1);
+ ASSERT(req->result == 0);
unlink_cb_count++;
uv_fs_req_cleanup(req);
}
int r;
ASSERT(req == &close_req);
ASSERT(req->fs_type == UV_FS_CLOSE);
- ASSERT(req->result != -1);
+ ASSERT(req->result == 0);
close_cb_count++;
uv_fs_req_cleanup(req);
if (close_cb_count == 3) {
int r;
ASSERT(req == &ftruncate_req);
ASSERT(req->fs_type == UV_FS_FTRUNCATE);
- ASSERT(req->result != -1);
+ ASSERT(req->result == 0);
ftruncate_cb_count++;
uv_fs_req_cleanup(req);
r = uv_fs_close(loop, &close_req, open_req1.result, close_cb);
int r;
ASSERT(req == &read_req);
ASSERT(req->fs_type == UV_FS_READ);
- ASSERT(req->result != -1);
+ ASSERT(req->result >= 0); /* FIXME(bnoordhuis) Check if requested size? */
read_cb_count++;
uv_fs_req_cleanup(req);
if (read_cb_count == 1) {
ASSERT(req == &open_req1);
ASSERT(req->fs_type == UV_FS_OPEN);
if (req->result < 0) {
- /* TODO get error with uv_last_error() */
- fprintf(stderr, "async open error: %d\n", req->errorno);
+ fprintf(stderr, "async open error: %d\n", (int) req->result);
ASSERT(0);
}
open_cb_count++;
static void open_cb_simple(uv_fs_t* req) {
ASSERT(req->fs_type == UV_FS_OPEN);
if (req->result < 0) {
- /* TODO get error with uv_last_error() */
- fprintf(stderr, "async open error: %d\n", req->errorno);
+ fprintf(stderr, "async open error: %d\n", (int) req->result);
ASSERT(0);
}
open_cb_count++;
int r;
ASSERT(req == &fsync_req);
ASSERT(req->fs_type == UV_FS_FSYNC);
- ASSERT(req->result != -1);
+ ASSERT(req->result == 0);
fsync_cb_count++;
uv_fs_req_cleanup(req);
r = uv_fs_close(loop, &close_req, open_req1.result, close_cb);
int r;
ASSERT(req == &fdatasync_req);
ASSERT(req->fs_type == UV_FS_FDATASYNC);
- ASSERT(req->result != -1);
+ ASSERT(req->result == 0);
fdatasync_cb_count++;
uv_fs_req_cleanup(req);
r = uv_fs_fsync(loop, &fsync_req, open_req1.result, fsync_cb);
int r;
ASSERT(req == &write_req);
ASSERT(req->fs_type == UV_FS_WRITE);
- ASSERT(req->result != -1);
+ ASSERT(req->result >= 0); /* FIXME(bnoordhuis) Check if requested size? */
write_cb_count++;
uv_fs_req_cleanup(req);
r = uv_fs_fdatasync(loop, &fdatasync_req, open_req1.result, fdatasync_cb);
int r;
ASSERT(req == &open_req1);
ASSERT(req->fs_type == UV_FS_OPEN);
- ASSERT(req->result != -1);
+ ASSERT(req->result >= 0);
create_cb_count++;
uv_fs_req_cleanup(req);
r = uv_fs_write(loop, &write_req, req->result, test_buf, sizeof(test_buf),
static void rename_cb(uv_fs_t* req) {
ASSERT(req == &rename_req);
ASSERT(req->fs_type == UV_FS_RENAME);
- ASSERT(req->result != -1);
+ ASSERT(req->result == 0);
rename_cb_count++;
uv_fs_req_cleanup(req);
}
static void mkdir_cb(uv_fs_t* req) {
ASSERT(req == &mkdir_req);
ASSERT(req->fs_type == UV_FS_MKDIR);
- ASSERT(req->result != -1);
+ ASSERT(req->result == 0);
mkdir_cb_count++;
ASSERT(req->path);
ASSERT(memcmp(req->path, "test_dir\0", 9) == 0);
static void rmdir_cb(uv_fs_t* req) {
ASSERT(req == &rmdir_req);
ASSERT(req->fs_type == UV_FS_RMDIR);
- ASSERT(req->result != -1);
+ ASSERT(req->result == 0);
rmdir_cb_count++;
ASSERT(req->path);
ASSERT(memcmp(req->path, "test_dir\0", 9) == 0);
static void file_readdir_cb(uv_fs_t* req) {
ASSERT(req == &readdir_req);
ASSERT(req->fs_type == UV_FS_READDIR);
- ASSERT(req->result == -1);
+ ASSERT(req->result == UV_ENOTDIR);
ASSERT(req->ptr == NULL);
- ASSERT(uv_last_error(req->loop).code == UV_ENOTDIR);
uv_fs_req_cleanup(req);
readdir_cb_count++;
}
static void stat_cb(uv_fs_t* req) {
ASSERT(req == &stat_req);
ASSERT(req->fs_type == UV_FS_STAT || req->fs_type == UV_FS_LSTAT);
- ASSERT(req->result != -1);
+ ASSERT(req->result == 0);
ASSERT(req->ptr);
stat_cb_count++;
uv_fs_req_cleanup(req);
static void open_noent_cb(uv_fs_t* req) {
ASSERT(req->fs_type == UV_FS_OPEN);
- ASSERT(req->errorno == UV_ENOENT);
- ASSERT(req->result == -1);
+ ASSERT(req->result == UV_ENOENT);
open_cb_count++;
uv_fs_req_cleanup(req);
}
static void open_nametoolong_cb(uv_fs_t* req) {
ASSERT(req->fs_type == UV_FS_OPEN);
- ASSERT(req->errorno == UV_ENAMETOOLONG);
- ASSERT(req->result == -1);
+ ASSERT(req->result == UV_ENAMETOOLONG);
open_cb_count++;
uv_fs_req_cleanup(req);
}
static void open_loop_cb(uv_fs_t* req) {
ASSERT(req->fs_type == UV_FS_OPEN);
- ASSERT(req->errorno == UV_ELOOP);
- ASSERT(req->result == -1);
+ ASSERT(req->result == UV_ELOOP);
open_cb_count++;
uv_fs_req_cleanup(req);
}
loop = uv_default_loop();
r = uv_fs_open(loop, &req, "does_not_exist", O_RDONLY, 0, NULL);
- ASSERT(r == -1);
- ASSERT(req.result == -1);
- ASSERT(uv_last_error(loop).code == UV_ENOENT);
+ ASSERT(r == UV_ENOENT);
+ ASSERT(req.result == UV_ENOENT);
uv_fs_req_cleanup(&req);
r = uv_fs_open(loop, &req, "does_not_exist", O_RDONLY, 0, open_noent_cb);
name[TOO_LONG_NAME_LENGTH] = 0;
r = uv_fs_open(loop, &req, name, O_RDONLY, 0, NULL);
- ASSERT(r == -1);
- ASSERT(req.result == -1);
- ASSERT(uv_last_error(loop).code == UV_ENAMETOOLONG);
+ ASSERT(r == UV_ENAMETOOLONG);
+ ASSERT(req.result == UV_ENAMETOOLONG);
uv_fs_req_cleanup(&req);
r = uv_fs_open(loop, &req, name, O_RDONLY, 0, open_nametoolong_cb);
uv_fs_req_cleanup(&req);
r = uv_fs_open(loop, &req, "test_symlink", O_RDONLY, 0, NULL);
- ASSERT(r == -1);
- ASSERT(req.result == -1);
- ASSERT(uv_last_error(loop).code == UV_ELOOP);
+ ASSERT(r == UV_ELOOP);
+ ASSERT(req.result == UV_ELOOP);
uv_fs_req_cleanup(&req);
r = uv_fs_open(loop, &req, "test_symlink", O_RDONLY, 0, open_loop_cb);
r = uv_fs_open(loop, &open_req1, "test_file", O_WRONLY | O_CREAT,
S_IWUSR | S_IRUSR, NULL);
- ASSERT(r != -1);
- ASSERT(open_req1.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1);
r = uv_fs_write(loop, &write_req, open_req1.result, test_buf,
sizeof(test_buf), -1, NULL);
- ASSERT(r != -1);
- ASSERT(write_req.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(write_req.result >= 0);
uv_fs_req_cleanup(&write_req);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
- ASSERT(r != -1);
- ASSERT(close_req.result != -1);
+ ASSERT(r == 0);
+ ASSERT(close_req.result == 0);
uv_fs_req_cleanup(&close_req);
r = uv_fs_open(loop, &open_req1, "test_file", O_RDWR, 0, NULL);
- ASSERT(r != -1);
- ASSERT(open_req1.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1);
r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1,
NULL);
- ASSERT(r != -1);
- ASSERT(read_req.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(read_req.result >= 0);
ASSERT(strcmp(buf, test_buf) == 0);
uv_fs_req_cleanup(&read_req);
r = uv_fs_ftruncate(loop, &ftruncate_req, open_req1.result, 7, NULL);
- ASSERT(r != -1);
- ASSERT(ftruncate_req.result != -1);
+ ASSERT(r == 0);
+ ASSERT(ftruncate_req.result == 0);
uv_fs_req_cleanup(&ftruncate_req);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
- ASSERT(r != -1);
- ASSERT(close_req.result != -1);
+ ASSERT(r == 0);
+ ASSERT(close_req.result == 0);
uv_fs_req_cleanup(&close_req);
r = uv_fs_rename(loop, &rename_req, "test_file", "test_file2", NULL);
- ASSERT(r != -1);
- ASSERT(rename_req.result != -1);
+ ASSERT(r == 0);
+ ASSERT(rename_req.result == 0);
uv_fs_req_cleanup(&rename_req);
r = uv_fs_open(loop, &open_req1, "test_file2", O_RDONLY, 0, NULL);
- ASSERT(r != -1);
- ASSERT(open_req1.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1);
memset(buf, 0, sizeof(buf));
r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1,
NULL);
- ASSERT(r != -1);
- ASSERT(read_req.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(read_req.result >= 0);
ASSERT(strcmp(buf, "test-bu") == 0);
uv_fs_req_cleanup(&read_req);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
- ASSERT(r != -1);
- ASSERT(close_req.result != -1);
+ ASSERT(r == 0);
+ ASSERT(close_req.result == 0);
uv_fs_req_cleanup(&close_req);
r = uv_fs_unlink(loop, &unlink_req, "test_file2", NULL);
- ASSERT(r != -1);
- ASSERT(unlink_req.result != -1);
+ ASSERT(r == 0);
+ ASSERT(unlink_req.result == 0);
uv_fs_req_cleanup(&unlink_req);
/* Cleanup */
/* Create 2 files synchronously. */
r = uv_fs_open(loop, &open_req1, "test_dir/file1", O_WRONLY | O_CREAT,
S_IWUSR | S_IRUSR, NULL);
- ASSERT(r != -1);
+ ASSERT(r >= 0);
uv_fs_req_cleanup(&open_req1);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
ASSERT(r == 0);
r = uv_fs_open(loop, &open_req1, "test_dir/file2", O_WRONLY | O_CREAT,
S_IWUSR | S_IRUSR, NULL);
- ASSERT(r != -1);
+ ASSERT(r >= 0);
uv_fs_req_cleanup(&open_req1);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
ASSERT(r == 0);
/* Test starts here. */
r = uv_fs_open(loop, &open_req1, "test_file", O_RDWR, 0, NULL);
- ASSERT(r != -1);
- ASSERT(open_req1.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1);
r = uv_fs_open(loop, &open_req2, "test_file2", O_WRONLY | O_CREAT,
S_IWUSR | S_IRUSR, NULL);
- ASSERT(r != -1);
- ASSERT(open_req2.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(open_req2.result >= 0);
uv_fs_req_cleanup(&open_req2);
r = uv_fs_sendfile(loop, &sendfile_req, open_req2.result, open_req1.result,
r = uv_fs_open(loop, &req, "test_file", O_RDWR | O_CREAT,
S_IWUSR | S_IRUSR, NULL);
- ASSERT(r != -1);
- ASSERT(req.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(req.result >= 0);
file = req.result;
uv_fs_req_cleanup(&req);
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_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_nsec == t.st_atim.tv_nsec);
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_ctim.tv_sec == t.st_ctim.tv_sec);
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
ASSERT(s->st_atim.tv_sec == t.st_atime);
ASSERT(s->st_atim.tv_nsec == 0);
r = uv_fs_open(loop, &req, "test_file", O_RDWR | O_CREAT,
S_IWUSR | S_IRUSR, NULL);
- ASSERT(r != -1);
- ASSERT(req.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(req.result >= 0);
file = req.result;
uv_fs_req_cleanup(&req);
r = uv_fs_open(loop, &req, "test_file", O_RDWR | O_CREAT,
S_IWUSR | S_IRUSR, NULL);
- ASSERT(r != -1);
- ASSERT(req.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(req.result >= 0);
file = req.result;
uv_fs_req_cleanup(&req);
r = uv_fs_open(loop, &req, "test_file", O_RDWR | O_CREAT,
S_IWUSR | S_IRUSR, NULL);
- ASSERT(r != -1);
- ASSERT(req.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(req.result >= 0);
file = req.result;
uv_fs_req_cleanup(&req);
uv_fs_req_cleanup(&req);
r = uv_fs_open(loop, &req, "test_file_link", O_RDWR, 0, NULL);
- ASSERT(r != -1);
- ASSERT(req.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(req.result >= 0);
link = req.result;
uv_fs_req_cleanup(&req);
memset(buf, 0, sizeof(buf));
r = uv_fs_read(loop, &req, link, buf, sizeof(buf), 0, NULL);
- ASSERT(r != -1);
- ASSERT(req.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(req.result >= 0);
ASSERT(strcmp(buf, test_buf) == 0);
close(link);
ASSERT(link_cb_count == 1);
r = uv_fs_open(loop, &req, "test_file_link2", O_RDWR, 0, NULL);
- ASSERT(r != -1);
- ASSERT(req.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(req.result >= 0);
link = req.result;
uv_fs_req_cleanup(&req);
memset(buf, 0, sizeof(buf));
r = uv_fs_read(loop, &req, link, buf, sizeof(buf), 0, NULL);
- ASSERT(r != -1);
- ASSERT(req.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(req.result >= 0);
ASSERT(strcmp(buf, test_buf) == 0);
close(link);
ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT));
ASSERT(dummy_cb_count == 1);
ASSERT(req.ptr == NULL);
- ASSERT(req.result == -1);
- ASSERT(req.errorno == UV_ENOENT);
+ ASSERT(req.result == UV_ENOENT);
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.result == -1);
- ASSERT(req.errorno == UV_ENOENT);
+ ASSERT(req.result == UV_ENOENT);
uv_fs_req_cleanup(&req);
MAKE_VALGRIND_HAPPY();
r = uv_fs_open(loop, &req, "test_file", O_RDWR | O_CREAT,
S_IWUSR | S_IRUSR, NULL);
- ASSERT(r != -1);
- ASSERT(req.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(req.result >= 0);
file = req.result;
uv_fs_req_cleanup(&req);
/* sync symlink */
r = uv_fs_symlink(loop, &req, "test_file", "test_file_symlink", 0, NULL);
#ifdef _WIN32
- if (r == -1) {
- if (uv_last_error(loop).code == UV_ENOTSUP) {
+ if (r < 0) {
+ if (r == UV_ENOTSUP) {
/*
* Windows doesn't support symlinks on older versions.
* We just pass the test and bail out early if we get ENOTSUP.
*/
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.
* We pass the test and bail out early if we get UV_EPERM.
uv_fs_req_cleanup(&req);
r = uv_fs_open(loop, &req, "test_file_symlink", O_RDWR, 0, NULL);
- ASSERT(r != -1);
- ASSERT(req.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(req.result >= 0);
link = req.result;
uv_fs_req_cleanup(&req);
memset(buf, 0, sizeof(buf));
r = uv_fs_read(loop, &req, link, buf, sizeof(buf), 0, NULL);
- ASSERT(r != -1);
- ASSERT(req.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(req.result >= 0);
ASSERT(strcmp(buf, test_buf) == 0);
close(link);
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);
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);
uv_fs_req_cleanup(&req);
ASSERT(symlink_cb_count == 1);
r = uv_fs_open(loop, &req, "test_file_symlink2", O_RDWR, 0, NULL);
- ASSERT(r != -1);
- ASSERT(req.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(req.result >= 0);
link = req.result;
uv_fs_req_cleanup(&req);
memset(buf, 0, sizeof(buf));
r = uv_fs_read(loop, &req, link, buf, sizeof(buf), 0, NULL);
- ASSERT(r != -1);
- ASSERT(req.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(req.result >= 0);
ASSERT(strcmp(buf, test_buf) == 0);
close(link);
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);
r = uv_fs_readlink(loop, &req, "test_file_symlink2_symlink", readlink_cb);
- ASSERT(r != -1);
+ ASSERT(r == 0);
uv_run(loop, UV_RUN_DEFAULT);
ASSERT(readlink_cb_count == 1);
r = uv_fs_open(loop, &open_req1, "test_dir/file1", O_WRONLY | O_CREAT,
S_IWUSR | S_IRUSR, NULL);
- ASSERT(r != -1);
+ ASSERT(r >= 0);
uv_fs_req_cleanup(&open_req1);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
ASSERT(r == 0);
r = uv_fs_open(loop, &open_req1, "test_dir/file2", O_WRONLY | O_CREAT,
S_IWUSR | S_IRUSR, NULL);
- ASSERT(r != -1);
+ ASSERT(r >= 0);
uv_fs_req_cleanup(&open_req1);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
ASSERT(r == 0);
uv_fs_req_cleanup(&req);
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);
r = uv_fs_readdir(loop, &readdir_req, "test_dir", 0, NULL);
unlink(path);
r = uv_fs_open(loop, &req, path, O_RDWR | O_CREAT,
S_IWUSR | S_IRUSR, NULL);
- ASSERT(r != -1);
- ASSERT(req.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(req.result >= 0);
uv_fs_req_cleanup(&req);
close(r);
unlink(path);
r = uv_fs_open(loop, &req, path, O_RDWR | O_CREAT,
S_IWUSR | S_IRUSR, NULL);
- ASSERT(r != -1);
- ASSERT(req.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(req.result >= 0);
uv_fs_req_cleanup(&req);
close(r);
atime = mtime = 400497753; /* 1982-09-10 11:22:33 */
r = uv_fs_open(loop, &req, path, O_RDWR, 0, NULL);
- ASSERT(r != -1);
- ASSERT(req.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(req.result >= 0);
file = req.result; /* FIXME probably not how it's supposed to be used */
uv_fs_req_cleanup(&req);
loop = uv_default_loop();
r = uv_fs_stat(loop, &req, "non_existent_file", NULL);
- ASSERT(r == -1);
- ASSERT(req.result == -1);
- ASSERT(uv_last_error(loop).code == UV_ENOENT);
+ ASSERT(r == UV_ENOENT);
+ ASSERT(req.result == UV_ENOENT);
uv_fs_req_cleanup(&req);
MAKE_VALGRIND_HAPPY();
loop = uv_default_loop();
r = uv_fs_readdir(loop, &readdir_req, path, 0, NULL);
- ASSERT(r == -1);
- ASSERT(uv_last_error(loop).code == UV_ENOTDIR);
+ ASSERT(r == UV_ENOTDIR);
uv_fs_req_cleanup(&readdir_req);
r = uv_fs_readdir(loop, &readdir_req, path, 0, file_readdir_cb);
loop = uv_default_loop();
r = uv_fs_open(loop, &req, path, O_RDONLY, 0, NULL);
- ASSERT(r != -1);
- ASSERT(req.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(req.result >= 0);
ASSERT(req.ptr == NULL);
file = r;
uv_fs_req_cleanup(&req);
r = uv_fs_open(loop, &open_req1, "test_file", O_WRONLY | O_CREAT,
S_IWUSR | S_IRUSR, NULL);
- ASSERT(r != -1);
- ASSERT(open_req1.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1);
r = uv_fs_write(loop, &write_req, open_req1.result, test_buf,
sizeof(test_buf), -1, NULL);
- ASSERT(r != -1);
- ASSERT(write_req.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(write_req.result >= 0);
uv_fs_req_cleanup(&write_req);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
- ASSERT(r != -1);
- ASSERT(close_req.result != -1);
+ ASSERT(r == 0);
+ ASSERT(close_req.result == 0);
uv_fs_req_cleanup(&close_req);
r = uv_fs_open(loop, &open_req1, "test_file", O_RDWR | O_APPEND, 0, NULL);
- ASSERT(r != -1);
- ASSERT(open_req1.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1);
r = uv_fs_write(loop, &write_req, open_req1.result, test_buf,
sizeof(test_buf), -1, NULL);
- ASSERT(r != -1);
- ASSERT(write_req.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(write_req.result >= 0);
uv_fs_req_cleanup(&write_req);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
- ASSERT(r != -1);
- ASSERT(close_req.result != -1);
+ ASSERT(r == 0);
+ ASSERT(close_req.result == 0);
uv_fs_req_cleanup(&close_req);
r = uv_fs_open(loop, &open_req1, "test_file", O_RDONLY, S_IRUSR, NULL);
- ASSERT(r != -1);
- ASSERT(open_req1.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1);
r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1,
uv_fs_req_cleanup(&read_req);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
- ASSERT(r != -1);
- ASSERT(close_req.result != -1);
+ ASSERT(r == 0);
+ ASSERT(close_req.result == 0);
uv_fs_req_cleanup(&close_req);
/* Cleanup */
r = uv_fs_open(loop, &open_req1, "test_file", O_WRONLY | O_CREAT,
S_IWUSR | S_IRUSR, NULL);
- ASSERT(r != -1);
- ASSERT(open_req1.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1);
r = uv_fs_write(loop, &write_req, open_req1.result, test_buf,
sizeof(test_buf), -1, NULL);
- ASSERT(r != -1);
- ASSERT(write_req.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(write_req.result >= 0);
uv_fs_req_cleanup(&write_req);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
- ASSERT(r != -1);
- ASSERT(close_req.result != -1);
+ ASSERT(r == 0);
+ ASSERT(close_req.result == 0);
uv_fs_req_cleanup(&close_req);
r = uv_fs_open(loop, &open_req1, "test_file2", O_WRONLY | O_CREAT,
S_IWUSR | S_IRUSR, NULL);
- ASSERT(r != -1);
- ASSERT(open_req1.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
- ASSERT(r != -1);
- ASSERT(close_req.result != -1);
+ ASSERT(r == 0);
+ ASSERT(close_req.result == 0);
uv_fs_req_cleanup(&close_req);
r = uv_fs_rename(loop, &rename_req, "test_file", "test_file2", NULL);
- ASSERT(r != -1);
- ASSERT(rename_req.result != -1);
+ ASSERT(r == 0);
+ ASSERT(rename_req.result == 0);
uv_fs_req_cleanup(&rename_req);
r = uv_fs_open(loop, &open_req1, "test_file2", O_RDONLY, 0, NULL);
- ASSERT(r != -1);
- ASSERT(open_req1.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1);
memset(buf, 0, sizeof(buf));
r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1,
NULL);
- ASSERT(r != -1);
- ASSERT(read_req.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(read_req.result >= 0);
ASSERT(strcmp(buf, test_buf) == 0);
uv_fs_req_cleanup(&read_req);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
- ASSERT(r != -1);
- ASSERT(close_req.result != -1);
+ ASSERT(r == 0);
+ ASSERT(close_req.result == 0);
uv_fs_req_cleanup(&close_req);
/* Cleanup */
r = uv_fs_open(loop, &open_req1, "test_file", O_WRONLY | O_CREAT,
S_IWUSR | S_IRUSR, NULL);
- ASSERT(r != -1);
- ASSERT(open_req1.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1);
r = uv_fs_write(loop, &write_req, open_req1.result, test_buf,
sizeof(test_buf), -1, NULL);
- ASSERT(r != -1);
- ASSERT(write_req.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(write_req.result >= 0);
uv_fs_req_cleanup(&write_req);
r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
- ASSERT(r != -1);
- ASSERT(close_req.result != -1);
+ ASSERT(r == 0);
+ ASSERT(close_req.result == 0);
uv_fs_req_cleanup(&close_req);
r = uv_fs_open(loop, &open_req1, "test_file", O_RDONLY, 0, NULL);
- ASSERT(r != -1);
- ASSERT(open_req1.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(open_req1.result >= 0);
uv_fs_req_cleanup(&open_req1);
memset(buf, 0, sizeof(buf));
r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1,
NULL);
- ASSERT(r != -1);
- ASSERT(read_req.result != -1);
+ ASSERT(r >= 0);
+ ASSERT(read_req.result >= 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);
- ASSERT(r != -1);
- ASSERT(close_req.result != -1);
+ ASSERT(r == 0);
+ ASSERT(close_req.result == 0);
uv_fs_req_cleanup(&close_req);
/* Cleanup */
/* Negative tests */
size = sizeof(buffer) / sizeof(buffer[0]);
r = uv_exepath(NULL, &size);
- ASSERT(r == -1);
+ ASSERT(r == UV_EINVAL);
r = uv_exepath(buffer, NULL);
- ASSERT(r == -1);
+ ASSERT(r == UV_EINVAL);
return 0;
}
int status,
struct addrinfo* res) {
ASSERT(fail_cb_called == 0);
- ASSERT(status == -1);
+ ASSERT(status < 0);
ASSERT(res == NULL);
uv_freeaddrinfo(res); /* Should not crash. */
fail_cb_called++;
int r;
if (status != 0) {
- fprintf(stderr, "Connect error %d\n",
- uv_last_error(loop).code);
+ fprintf(stderr, "Connect error %s\n", uv_err_name(status));
}
ASSERT(status == 0);
namelen = sizeof sockname;
r = uv_tcp_getpeername(&tcpServer, &peername, &namelen);
- ASSERT(r == -1);
- ASSERT(uv_last_error(loop).code == UV_ENOTCONN);
+ ASSERT(r == UV_ENOTCONN);
getpeernamecount++;
return 0;
--- /dev/null
+/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "uv.h"
+#include "task.h"
+
+#include <stdio.h>
+#include <string.h>
+
+#ifdef __linux__
+# include <sys/socket.h>
+# include <net/if.h>
+#endif
+
+typedef void (*iface_info_cb)(const char* ip6_addr, const char* device_name,
+ unsigned iface_index);
+
+void call_iface_info_cb(iface_info_cb iface_cb,
+ char const* iface_name,
+ struct sockaddr_in6 const* address) {
+ char string_address[INET6_ADDRSTRLEN];
+
+ ASSERT(0 == uv_inet_ntop(AF_INET6,
+ &address->sin6_addr,
+ string_address,
+ INET6_ADDRSTRLEN));
+ iface_cb(string_address, iface_name, address->sin6_scope_id);
+}
+
+
+void foreach_ip6_interface(iface_info_cb iface_cb) {
+ int count, ix;
+ uv_interface_address_t* addresses;
+
+ ASSERT(0 == uv_interface_addresses(&addresses, &count));
+
+ for (ix = 0; ix < count; ix++) {
+ if (addresses[ix].address.address4.sin_family != AF_INET6)
+ continue;
+
+ call_iface_info_cb(iface_cb,
+ addresses[ix].name,
+ &addresses[ix].address.address6);
+ }
+
+ uv_free_interface_addresses(addresses, count);
+}
+
+
+void test_ip6_addr_scope(const char* ip6_addr,
+ const char* device_name,
+ unsigned iface_index) {
+ /* 40 bytes address, 16 bytes device name, plus reserve */
+ char scoped_addr[128];
+ struct sockaddr_in6 addr;
+
+ /* skip addresses that are not link-local */
+ if (strncmp(ip6_addr, "fe80::", 6) != 0) return;
+
+#ifdef _WIN32
+ sprintf(scoped_addr, "%s%%%d", ip6_addr, iface_index);
+#else
+ sprintf(scoped_addr, "%s%%%s", ip6_addr, device_name);
+#endif
+
+ LOGF("Testing link-local address %s (iface_index: 0x%02x, device_name: %s)\n",
+ scoped_addr,
+ iface_index,
+ device_name);
+
+ addr = uv_ip6_addr(scoped_addr, TEST_PORT);
+
+ LOGF("Got scope_id 0x%02x\n", addr.sin6_scope_id);
+ ASSERT(iface_index == addr.sin6_scope_id);
+}
+
+
+TEST_IMPL(ip6_addr_link_local) {
+#ifdef UV_PLATFORM_HAS_IP6_LINK_LOCAL_ADDRESS
+ foreach_ip6_interface(&test_ip6_addr_scope);
+ return 0;
+#else
+ RETURN_SKIP("Qualified link-local addresses are not supported.");
+#endif
+}
uv_handle_type pending) {
int r;
uv_buf_t outbuf;
- uv_err_t err;
if (nread == 0) {
/* Everything OK, but nothing read. */
}
if (nread < 0) {
- err = uv_last_error(pipe->loop);
- if (err.code == UV_EOF) {
+ if (nread == UV_EOF) {
free(buf.base);
return;
}
- printf("error recving on channel: %s\n", uv_strerror(err));
+ printf("error recving on channel: %s\n", uv_strerror(nread));
abort();
}
uv_handle_type pending) {
int r;
uv_buf_t outbuf;
- uv_err_t err;
if (nread == 0) {
/* Everything OK, but nothing read. */
}
if (nread < 0) {
- err = uv_last_error(pipe->loop);
- if (err.code == UV_EOF) {
+ if (nread == UV_EOF) {
free(buf.base);
return;
}
- printf("error recving on channel: %s\n", uv_strerror(err));
+ printf("error recving on channel: %s\n", uv_strerror(nread));
abort();
}
int r;
if (nread < 0) {
- if (uv_last_error(tcp->loop).code == UV_EOF) {
+ if (nread == UV_EOF) {
free(buf.base);
return;
}
- printf("error recving on tcp connection: %s\n",
- uv_strerror(uv_last_error(tcp->loop)));
+ printf("error recving on tcp connection: %s\n", uv_strerror(nread));
abort();
}
TEST_DECLARE (timer_huge_timeout)
TEST_DECLARE (timer_huge_repeat)
TEST_DECLARE (timer_run_once)
+TEST_DECLARE (timer_from_check)
TEST_DECLARE (idle_starvation)
TEST_DECLARE (loop_handles)
TEST_DECLARE (get_loadavg)
TEST_DECLARE (poll_duplex)
TEST_DECLARE (poll_unidirectional)
TEST_DECLARE (poll_close)
+TEST_DECLARE (ip6_addr_link_local)
#ifdef _WIN32
TEST_DECLARE (spawn_detect_pipe_name_collisions_on_windows)
TEST_DECLARE (argument_escaping)
TEST_ENTRY (timer_huge_timeout)
TEST_ENTRY (timer_huge_repeat)
TEST_ENTRY (timer_run_once)
+ TEST_ENTRY (timer_from_check)
TEST_ENTRY (idle_starvation)
TEST_ENTRY (strlcpy)
TEST_ENTRY (strlcat)
TEST_ENTRY (dlerror)
+ TEST_ENTRY (ip6_addr_link_local)
#if 0
/* These are for testing the test runner. */
TEST_ENTRY (fail_always)
pinger = (pinger_t*)stream->data;
if (nread < 0) {
- ASSERT(uv_last_error(uv_default_loop()).code == UV_EOF);
+ ASSERT(nread == UV_EOF);
puts("got EOF");
free(buf.base);
r = uv_pipe_init(uv_default_loop(), &server2, 0);
ASSERT(r == 0);
r = uv_pipe_bind(&server2, TEST_PIPENAME);
- ASSERT(r == -1);
-
- ASSERT(uv_last_error(uv_default_loop()).code == UV_EADDRINUSE);
+ ASSERT(r == UV_EADDRINUSE);
r = uv_listen((uv_stream_t*)&server1, SOMAXCONN, NULL);
ASSERT(r == 0);
r = uv_listen((uv_stream_t*)&server2, SOMAXCONN, NULL);
- ASSERT(r == -1);
-
- ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL);
+ ASSERT(r == UV_EINVAL);
uv_close((uv_handle_t*)&server1, close_cb);
uv_close((uv_handle_t*)&server2, close_cb);
r = uv_pipe_init(uv_default_loop(), &server, 0);
ASSERT(r == 0);
- r = uv_pipe_bind(&server, BAD_PIPENAME);
- ASSERT(r == -1);
- ASSERT(uv_last_error(uv_default_loop()).code == UV_EACCES);
+ r = uv_pipe_bind(&server, BAD_PIPENAME);
+ ASSERT(r == UV_EACCES);
uv_close((uv_handle_t*)&server, close_cb);
r = uv_pipe_bind(&server, TEST_PIPENAME);
ASSERT(r == 0);
r = uv_pipe_bind(&server, TEST_PIPENAME_2);
- ASSERT(r == -1);
-
- ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL);
+ ASSERT(r == UV_EINVAL);
uv_close((uv_handle_t*)&server, close_cb);
r = uv_pipe_init(uv_default_loop(), &server, 0);
ASSERT(r == 0);
- r = uv_listen((uv_stream_t*)&server, SOMAXCONN, NULL);
- ASSERT(r == -1);
- ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL);
+ r = uv_listen((uv_stream_t*)&server, SOMAXCONN, NULL);
+ ASSERT(r == UV_EINVAL);
uv_close((uv_handle_t*)&server, close_cb);
static void connect_cb(uv_connect_t* connect_req, int status) {
- ASSERT(status == -1);
- ASSERT(uv_last_error(uv_default_loop()).code == UV_ENOENT);
+ ASSERT(status == UV_ENOENT);
uv_close((uv_handle_t*)connect_req->handle, close_cb);
connect_cb_called++;
}
static void connect_cb_file(uv_connect_t* connect_req, int status) {
- ASSERT(status == -1);
- ASSERT(uv_last_error(uv_default_loop()).code == UV_ENOTSOCK ||
- uv_last_error(uv_default_loop()).code == UV_ECONNREFUSED);
+ ASSERT(status == UV_ENOTSOCK || status == UV_ECONNREFUSED);
uv_close((uv_handle_t*)connect_req->handle, close_cb);
connect_cb_called++;
}
uv_interface_address_t* interfaces;
int count;
int i;
- uv_err_t err;
+ int err;
err = uv_get_process_title(buffer, sizeof(buffer));
- ASSERT(UV_OK == err.code);
+ ASSERT(err == 0);
printf("uv_get_process_title: %s\n", buffer);
err = uv_resident_set_memory(&rss);
- ASSERT(UV_OK == err.code);
+ ASSERT(err == 0);
printf("uv_resident_set_memory: %llu\n", (unsigned long long) rss);
err = uv_uptime(&uptime);
- ASSERT(UV_OK == err.code);
+ ASSERT(err == 0);
ASSERT(uptime > 0);
printf("uv_uptime: %f\n", uptime);
err = uv_cpu_info(&cpus, &count);
- ASSERT(UV_OK == err.code);
+ ASSERT(err == 0);
printf("uv_cpu_info:\n");
for (i = 0; i < count; i++) {
uv_free_cpu_info(cpus, count);
err = uv_interface_addresses(&interfaces, &count);
- ASSERT(UV_OK == err.code);
+ ASSERT(err == 0);
printf("uv_interface_addresses:\n");
for (i = 0; i < count; i++) {
static void set_title(const char* title) {
char buffer[512];
- uv_err_t err;
+ int err;
err = uv_get_process_title(buffer, sizeof(buffer));
- ASSERT(UV_OK == err.code);
+ ASSERT(err == 0);
err = uv_set_process_title(title);
- ASSERT(UV_OK == err.code);
+ ASSERT(err == 0);
err = uv_get_process_title(buffer, sizeof(buffer));
- ASSERT(UV_OK == err.code);
+ ASSERT(err == 0);
ASSERT(strcmp(buffer, title) == 0);
}
uv_sem_wait(&sem); /* should not block */
uv_sem_wait(&sem); /* should not block */
ASSERT(0 == uv_sem_trywait(&sem));
- ASSERT(-1 == uv_sem_trywait(&sem));
+ ASSERT(UV_EAGAIN == uv_sem_trywait(&sem));
uv_sem_post(&sem);
ASSERT(0 == uv_sem_trywait(&sem));
- ASSERT(-1 == uv_sem_trywait(&sem));
+ ASSERT(UV_EAGAIN == uv_sem_trywait(&sem));
uv_sem_destroy(&sem);
static void shutdown_cb(uv_shutdown_t* req, int status) {
- int err = uv_last_error(uv_default_loop()).code;
ASSERT(req == &shutdown_req);
- ASSERT(status == 0 || (status == -1 && err == UV_ECANCELED));
+ ASSERT(status == 0 || status == UV_ECANCELED);
shutdown_cb_called++;
}
static void read_cb(uv_stream_t* t, ssize_t nread, uv_buf_t buf) {
- uv_err_t err = uv_last_error(uv_default_loop());
-
ASSERT((uv_tcp_t*)t == &tcp);
if (nread == 0) {
- ASSERT(err.code == UV_EAGAIN);
free(buf.base);
return;
}
got_q = 1;
puts("got Q");
} else {
- ASSERT(err.code == UV_EOF);
+ ASSERT(nread == UV_EOF);
if (buf.base) {
free(buf.base);
}
}
-static void exit_cb_failure_expected(uv_process_t* process, int exit_status,
- int term_signal) {
+static void expect(uv_process_t* process,
+ int exit_status,
+ int term_signal,
+ int err) {
printf("exit_cb\n");
exit_cb_called++;
- ASSERT(exit_status == -1);
+ ASSERT(exit_status == err);
ASSERT(term_signal == 0);
uv_close((uv_handle_t*)process, close_cb);
}
+static void exit_cb_expect_enoent(uv_process_t* process,
+ int exit_status,
+ int term_signal) {
+ expect(process, exit_status, term_signal, UV_ENOENT);
+}
+
+
+static void exit_cb_expect_eperm(uv_process_t* process,
+ int exit_status,
+ int term_signal) {
+ expect(process, exit_status, term_signal, UV_EPERM);
+}
+
+
static void kill_cb(uv_process_t* process, int exit_status, int term_signal) {
- uv_err_t err;
+ int err;
printf("exit_cb\n");
exit_cb_called++;
* This process should be dead.
*/
err = uv_kill(process->pid, 0);
- ASSERT(err.code == UV_ESRCH);
+ ASSERT(err == UV_ESRCH);
}
static void detach_failure_cb(uv_process_t* process, int exit_status, int term_signal) {
static void on_read(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) {
- uv_err_t err = uv_last_error(uv_default_loop());
-
if (nread > 0) {
output_used += nread;
} else if (nread < 0) {
- ASSERT(err.code == UV_EOF);
+ ASSERT(nread == UV_EOF);
uv_close((uv_handle_t*)tcp, close_cb);
}
}
TEST_IMPL(spawn_fails) {
- init_process_options("", exit_cb_failure_expected);
+ init_process_options("", exit_cb_expect_enoent);
options.file = options.args[0] = "program-that-had-better-not-exist";
ASSERT(0 == uv_spawn(uv_default_loop(), &process, options));
ASSERT(0 != uv_is_active((uv_handle_t*)&process));
ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT));
- ASSERT(uv_last_error(uv_default_loop()).code == UV_ENOENT);
+ ASSERT(1 == exit_cb_called);
MAKE_VALGRIND_HAPPY();
return 0;
TEST_IMPL(spawn_detached) {
int r;
- uv_err_t err;
init_process_options("spawn_helper4", detach_failure_cb);
ASSERT(exit_cb_called == 0);
- err = uv_kill(process.pid, 0);
- ASSERT(err.code == 0);
+ r = uv_kill(process.pid, 0);
+ ASSERT(r == 0);
- err = uv_kill(process.pid, 15);
- ASSERT(err.code == 0);
+ r = uv_kill(process.pid, 15);
+ ASSERT(r == 0);
MAKE_VALGRIND_HAPPY();
return 0;
TEST_IMPL(kill) {
int r;
- uv_err_t err;
#ifdef _WIN32
no_term_signal = 1;
/* Sending signum == 0 should check if the
* child process is still alive, not kill it.
*/
- err = uv_kill(process.pid, 0);
- ASSERT(err.code == UV_OK);
+ r = uv_kill(process.pid, 0);
+ ASSERT(r == 0);
/* Kill the process. */
- err = uv_kill(process.pid, /* SIGTERM */ 15);
- ASSERT(err.code == UV_OK);
+ r = uv_kill(process.pid, /* SIGTERM */ 15);
+ ASSERT(r == 0);
r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(r == 0);
}
-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);
WCHAR* quote_cmd_arg(const WCHAR *source, WCHAR *target);
TEST_IMPL(argument_escaping) {
size_t total_size = 0;
int i;
int num_args;
- uv_err_t result;
+ int result;
char* verbatim[] = {
"cmd.exe",
}
result = make_program_args(verbatim, 1, &verbatim_output);
- ASSERT(result.code == UV_OK);
+ ASSERT(result == 0);
result = make_program_args(verbatim, 0, &non_verbatim_output);
- ASSERT(result.code == UV_OK);
+ ASSERT(result == 0);
wprintf(L" verbatim_output: %s\n", verbatim_output);
wprintf(L"non_verbatim_output: %s\n", non_verbatim_output);
return 0;
}
-uv_err_t make_program_env(char** env_block, WCHAR** dst_ptr);
+int make_program_env(char** env_block, WCHAR** dst_ptr);
TEST_IMPL(environment_creation) {
int i;
WCHAR expected[512];
WCHAR* ptr = expected;
- uv_err_t result;
+ int result;
WCHAR* str;
WCHAR* env;
*ptr = '\0';
result = make_program_env(environment, &env);
- ASSERT(result.code == UV_OK);
+ ASSERT(result == 0);
for (str = env; *str; str += wcslen(str) + 1) {
wprintf(L"%s\n", str);
struct passwd* pw;
pw = getpwnam("nobody");
ASSERT(pw != NULL);
- r = setuid(pw->pw_uid);
- ASSERT(r == 0);
+ ASSERT(0 == setgid(pw->pw_gid));
+ ASSERT(0 == setuid(pw->pw_uid));
}
- init_process_options("spawn_helper1", exit_cb_failure_expected);
+ init_process_options("spawn_helper1", exit_cb_expect_eperm);
options.flags |= UV_PROCESS_SETUID;
- options.uid = (uv_uid_t) -42424242;
+ options.uid = 0;
r = uv_spawn(uv_default_loop(), &process, options);
ASSERT(r == 0);
struct passwd* pw;
pw = getpwnam("nobody");
ASSERT(pw != NULL);
- r = setuid(pw->pw_uid);
- ASSERT(r == 0);
+ ASSERT(0 == setgid(pw->pw_gid));
+ ASSERT(0 == setuid(pw->pw_uid));
}
- init_process_options("spawn_helper1", exit_cb_failure_expected);
+ init_process_options("spawn_helper1", exit_cb_expect_eperm);
options.flags |= UV_PROCESS_SETGID;
- options.gid = (uv_gid_t) -42424242;
+ options.gid = 0;
r = uv_spawn(uv_default_loop(), &process, options);
ASSERT(r == 0);
options.uid = (uv_uid_t) -42424242;
r = uv_spawn(uv_default_loop(), &process, options);
- ASSERT(r == -1);
- ASSERT(uv_last_error(uv_default_loop()).code == UV_ENOTSUP);
+ ASSERT(r == UV_ENOTSUP);
r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(r == 0);
options.gid = (uv_gid_t) -42424242;
r = uv_spawn(uv_default_loop(), &process, options);
- ASSERT(r == -1);
- ASSERT(uv_last_error(uv_default_loop()).code == UV_ENOTSUP);
+ ASSERT(r == UV_ENOTSUP);
r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(r == 0);
static void after_write(uv_write_t* req, int status) {
if (status) {
- uv_err_t err = uv_last_error(loop);
- fprintf(stderr, "uv_write error: %s\n", uv_strerror(err));
+ fprintf(stderr, "uv_write error: %s\n", uv_strerror(status));
ASSERT(0);
}
uv_buf_t wrbuf;
int r;
- ASSERT(nread > 0 || uv_last_error(uv_default_loop()).code == UV_EOF);
+ ASSERT(nread > 0 || nread == UV_EOF);
if (nread > 0) {
output_used += nread;
r = uv_listen((uv_stream_t*)&server1, 128, NULL);
ASSERT(r == 0);
r = uv_listen((uv_stream_t*)&server2, 128, NULL);
- ASSERT(r == -1);
-
- ASSERT(uv_last_error(uv_default_loop()).code == UV_EADDRINUSE);
+ ASSERT(r == UV_EADDRINUSE);
uv_close((uv_handle_t*)&server1, close_cb);
uv_close((uv_handle_t*)&server2, close_cb);
r = uv_tcp_init(uv_default_loop(), &server);
ASSERT(r == 0);
- r = uv_tcp_bind(&server, addr);
/* It seems that Linux is broken here - bind succeeds. */
- if (r == -1) {
- ASSERT(uv_last_error(uv_default_loop()).code == UV_EADDRNOTAVAIL);
- }
+ r = uv_tcp_bind(&server, addr);
+ ASSERT(r == 0 || r == UV_EADDRNOTAVAIL);
uv_close((uv_handle_t*)&server, close_cb);
r = uv_tcp_init(uv_default_loop(), &server);
ASSERT(r == 0);
r = uv_tcp_bind(&server, addr);
- ASSERT(r == -1);
- ASSERT(uv_last_error(uv_default_loop()).code == UV_EADDRNOTAVAIL);
+ ASSERT(r == UV_EADDRNOTAVAIL);
uv_close((uv_handle_t*)&server, close_cb);
r = uv_tcp_init(uv_default_loop(), &server);
ASSERT(r == 0);
r = uv_tcp_bind(&server, *garbage_addr);
- ASSERT(r == -1);
-
- ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL);
+ ASSERT(r == UV_EINVAL);
uv_close((uv_handle_t*)&server, close_cb);
r = uv_tcp_bind(&server, addr1);
ASSERT(r == 0);
r = uv_tcp_bind(&server, addr2);
- ASSERT(r == -1);
-
- ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL);
+ ASSERT(r == UV_EINVAL);
uv_close((uv_handle_t*)&server, close_cb);
r = uv_listen((uv_stream_t*)&server1, 128, NULL);
ASSERT(r == 0);
r = uv_listen((uv_stream_t*)&server2, 128, NULL);
- ASSERT(r == -1);
-
- ASSERT(uv_last_error(uv_default_loop()).code == UV_EADDRINUSE);
+ ASSERT(r == UV_EADDRINUSE);
uv_close((uv_handle_t*)&server1, close_cb);
uv_close((uv_handle_t*)&server2, close_cb);
r = uv_tcp_init(uv_default_loop(), &server);
ASSERT(r == 0);
r = uv_tcp_bind6(&server, addr);
- ASSERT(r == -1);
- ASSERT(uv_last_error(uv_default_loop()).code == UV_EADDRNOTAVAIL);
+ ASSERT(r == UV_EADDRNOTAVAIL);
uv_close((uv_handle_t*)&server, close_cb);
r = uv_tcp_init(uv_default_loop(), &server);
ASSERT(r == 0);
r = uv_tcp_bind6(&server, *garbage_addr);
- ASSERT(r == -1);
-
- ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL);
+ ASSERT(r == UV_EINVAL);
uv_close((uv_handle_t*)&server, close_cb);
r = uv_tcp_bind6(&server, addr1);
ASSERT(r == 0);
r = uv_tcp_bind6(&server, addr2);
- ASSERT(r == -1);
-
- ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL);
+ ASSERT(r == UV_EINVAL);
uv_close((uv_handle_t*)&server, close_cb);
static void connect_cb(uv_connect_t* req, int status) {
- ASSERT(status == -1);
- ASSERT(uv_last_error(req->handle->loop).code == UV_ECANCELED);
+ ASSERT(status == UV_ECANCELED);
uv_timer_stop(&timer2_handle);
connect_cb_called++;
}
static void connect_cb(uv_connect_t* req, int status) {
- ASSERT(status == -1);
+ ASSERT(status < 0);
connect_cb_called++;
uv_close((uv_handle_t*)req->handle, close_cb);
}
static void write_cb(uv_write_t* req, int status) {
- ASSERT(status == -1);
+ ASSERT(status < 0);
write_cb_called++;
}
ASSERT(r == 0);
r = uv_write(&write_req, (uv_stream_t*)&conn, &buf, 1, write_cb);
- ASSERT(r == -1);
- ASSERT(uv_last_error(uv_default_loop()).code == UV_EBADF);
+ ASSERT(r == UV_EBADF);
r = uv_tcp_connect(&connect_req, &conn, addr, connect_cb);
ASSERT(r == 0);
r = uv_tcp_init(uv_default_loop(), &server);
ASSERT(r == 0);
r = uv_tcp_connect(&req, &server, *garbage_addr, connect_cb);
- ASSERT(r == -1);
-
- ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL);
+ ASSERT(r == UV_EINVAL);
uv_close((uv_handle_t*)&server, close_cb);
static void connect_cb(uv_connect_t* req, int status) {
ASSERT(req == &connect_req);
- ASSERT(status == -1);
+ ASSERT(status == UV_ECANCELED);
connect_cb_called++;
}
r = uv_tcp_init(uv_default_loop(), &server);
ASSERT(r == 0);
r = uv_tcp_connect6(&req, &server, *garbage_addr, connect_cb);
- ASSERT(r == -1);
-
- ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL);
+ ASSERT(r == UV_EINVAL);
uv_close((uv_handle_t*)&server, close_cb);
ASSERT(memcmp("PING", buf.base, nread) == 0);
}
else {
- ASSERT(uv_last_error(uv_default_loop()).code == UV_EOF);
+ ASSERT(nread == UV_EOF);
printf("GOT EOF\n");
uv_close((uv_handle_t*)tcp, close_cb);
}
ASSERT(req != NULL);
if (status) {
- uv_err_t err = uv_last_error(uv_default_loop());
- fprintf(stderr, "uv_write error: %s\n", uv_strerror(err));
+ fprintf(stderr, "uv_write error: %s\n", uv_strerror(status));
ASSERT(0);
}
static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) {
- if (nread == -1) {
- fprintf(stderr, "read_cb error: %s\n", uv_err_name(uv_last_error(stream->loop)));
- ASSERT(uv_last_error(stream->loop).code == UV_ECONNRESET ||
- uv_last_error(stream->loop).code == UV_EOF);
+ if (nread < 0) {
+ fprintf(stderr, "read_cb error: %s\n", uv_err_name(nread));
+ ASSERT(nread == UV_ECONNRESET || nread == UV_EOF);
uv_close((uv_handle_t*)&tcp_server, NULL);
uv_close((uv_handle_t*)&tcp_peer, NULL);
bytes_received_done += nread;
}
else {
- ASSERT(uv_last_error(uv_default_loop()).code == UV_EOF);
+ ASSERT(nread == UV_EOF);
printf("GOT EOF\n");
uv_close((uv_handle_t*)tcp, close_cb);
}
ASSERT(req != NULL);
if (status) {
- uv_err_t err = uv_last_error(uv_default_loop());
- fprintf(stderr, "uv_write error: %s\n", uv_strerror(err));
+ fprintf(stderr, "uv_write error: %s\n", uv_strerror(status));
ASSERT(0);
}
static void fs_cb(uv_fs_t* req) {
- ASSERT(req->errorno == UV_ECANCELED);
+ ASSERT(req->result == UV_ECANCELED);
uv_fs_req_cleanup(req);
fs_cb_called++;
}
static void getaddrinfo_cb(uv_getaddrinfo_t* req,
int status,
struct addrinfo* res) {
- ASSERT(UV_ECANCELED == uv_last_error(req->loop).code);
- ASSERT(status == -1);
+ ASSERT(status == UV_EAI_CANCELED);
ASSERT(res == NULL);
uv_freeaddrinfo(res); /* Should not crash. */
getaddrinfo_cb_called++;
static void done2_cb(uv_work_t* req, int status) {
- ASSERT(uv_last_error(req->loop).code == UV_ECANCELED);
- ASSERT(status == -1);
+ ASSERT(status == UV_ECANCELED);
done2_cb_called++;
}
work_req.data = &data;
r = uv_queue_work(uv_default_loop(), &work_req, NULL, after_work_cb);
- ASSERT(r == -1);
+ ASSERT(r == UV_EINVAL);
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
- ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL);
ASSERT(work_cb_count == 0);
ASSERT(after_work_cb_count == 0);
r = uv_timer_init(uv_default_loop(), &dummy);
ASSERT(r == 0);
r = uv_timer_again(&dummy);
- ASSERT(r == -1);
- ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL);
+ ASSERT(r == UV_EINVAL);
uv_unref((uv_handle_t*)&dummy);
/* Start timer repeat_1. */
ASSERT(UV_TTY == uv_guess_handle(ttyin_fd));
ASSERT(UV_TTY == uv_guess_handle(ttyout_fd));
- r = uv_tty_init(uv_default_loop(), &tty_in, ttyin_fd, 1);
+ r = uv_tty_init(uv_default_loop(), &tty_in, ttyin_fd, 1); /* Readable. */
ASSERT(r == 0);
- r = uv_tty_init(uv_default_loop(), &tty_out, ttyout_fd, 2);
+ r = uv_tty_init(uv_default_loop(), &tty_out, ttyout_fd, 0); /* Writable. */
ASSERT(r == 0);
r = uv_tty_get_winsize(&tty_out, &width, &height);
CHECK_REQ(req);
CHECK_HANDLE(req->handle);
- ASSERT(status == -1);
- ASSERT(uv_last_error(uv_default_loop()).code == UV_EMSGSIZE);
+ ASSERT(status == UV_EMSGSIZE);
uv_close((uv_handle_t*)req->handle, close_cb);
send_cb_called++;
for (i = 0; i < (int) ARRAY_SIZE(invalid_ttls); i++) {
r = uv_udp_set_ttl(&h, invalid_ttls[i]);
- ASSERT(r == -1);
- ASSERT(uv_last_error(loop).code == UV_EINVAL);
+ ASSERT(r == UV_EINVAL);
}
r = uv_udp_set_multicast_loop(&h, 1);
/* anything >255 should fail */
r = uv_udp_set_multicast_ttl(&h, 256);
- ASSERT(r == -1);
- ASSERT(uv_last_error(loop).code == UV_EINVAL);
+ ASSERT(r == UV_EINVAL);
/* don't test ttl=-1, it's a valid value on some platforms */
r = uv_run(loop, UV_RUN_DEFAULT);
'type': '<(library)',
'include_dirs': [
'include',
- 'include/uv-private',
'src/',
],
'direct_dependent_settings': {
'sources': [
'common.gypi',
'include/uv.h',
- 'include/uv-private/tree.h',
+ 'include/tree.h',
+ 'include/uv-errno.h',
'src/fs-poll.c',
'src/inet.c',
'src/queue.h',
'_GNU_SOURCE',
],
'sources': [
- 'include/uv-private/uv-win.h',
+ 'include/uv-win.h',
'src/win/async.c',
'src/win/atomicops-inl.h',
'src/win/core.c',
'-Wno-unused-parameter',
],
'sources': [
- 'include/uv-private/uv-unix.h',
- 'include/uv-private/uv-linux.h',
- 'include/uv-private/uv-sunos.h',
- 'include/uv-private/uv-darwin.h',
- 'include/uv-private/uv-bsd.h',
+ 'include/uv-unix.h',
+ 'include/uv-linux.h',
+ 'include/uv-sunos.h',
+ 'include/uv-darwin.h',
+ 'include/uv-bsd.h',
'src/unix/async.c',
'src/unix/core.c',
'src/unix/dl.c',
- 'src/unix/error.c',
'src/unix/fs.c',
'src/unix/getaddrinfo.c',
'src/unix/internal.h',
'test/test-barrier.c',
'test/test-condvar.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-multicast-join.c',
'test/test-dlerror.c',
'test/test-udp-multicast-ttl.c',
+ 'test/test-ip6-addr.c',
],
'conditions': [
[ 'OS=="win"', {