diff options
Diffstat (limited to 'deps')
-rw-r--r-- | deps/uv/Makefile | 2 | ||||
-rw-r--r-- | deps/uv/config-unix.mk | 50 | ||||
-rw-r--r-- | deps/uv/include/uv-private/eio.h (renamed from deps/uv/include/eio.h) | 4 | ||||
-rw-r--r-- | deps/uv/include/uv-private/ev.h (renamed from deps/uv/include/ev.h) | 0 | ||||
-rw-r--r-- | deps/uv/include/uv-private/ngx-queue.h (renamed from deps/uv/include/ngx-queue.h) | 0 | ||||
-rw-r--r-- | deps/uv/include/uv-private/tree.h (renamed from deps/uv/include/tree.h) | 0 | ||||
-rw-r--r-- | deps/uv/include/uv-private/uv-unix.h (renamed from deps/uv/include/uv-unix.h) | 10 | ||||
-rw-r--r-- | deps/uv/include/uv-private/uv-win.h (renamed from deps/uv/include/uv-win.h) | 40 | ||||
-rw-r--r-- | deps/uv/include/uv.h | 160 | ||||
-rw-r--r-- | deps/uv/src/unix/cygwin.c (renamed from deps/uv/src/uv-cygwin.c) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/darwin.c (renamed from deps/uv/src/uv-darwin.c) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/eio/Changes (renamed from deps/uv/src/eio/Changes) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/eio/LICENSE (renamed from deps/uv/src/eio/LICENSE) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/eio/Makefile.am (renamed from deps/uv/src/eio/Makefile.am) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/eio/aclocal.m4 (renamed from deps/uv/src/eio/aclocal.m4) | 0 | ||||
-rwxr-xr-x | deps/uv/src/unix/eio/autogen.sh (renamed from deps/uv/src/eio/autogen.sh) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/eio/config.h.in (renamed from deps/uv/src/eio/config.h.in) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/eio/config_cygwin.h (renamed from deps/uv/src/eio/config_cygwin.h) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/eio/config_darwin.h (renamed from deps/uv/src/eio/config_darwin.h) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/eio/config_freebsd.h (renamed from deps/uv/src/eio/config_freebsd.h) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/eio/config_linux.h (renamed from deps/uv/src/eio/config_linux.h) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/eio/config_sunos.h (renamed from deps/uv/src/eio/config_sunos.h) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/eio/configure.ac (renamed from deps/uv/src/eio/configure.ac) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/eio/demo.c (renamed from deps/uv/src/eio/demo.c) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/eio/ecb.h (renamed from deps/uv/src/eio/ecb.h) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/eio/eio.3 (renamed from deps/uv/src/eio/eio.3) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/eio/eio.c (renamed from deps/uv/src/eio/eio.c) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/eio/eio.pod (renamed from deps/uv/src/eio/eio.pod) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/eio/libeio.m4 (renamed from deps/uv/src/eio/libeio.m4) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/eio/xthread.h (renamed from deps/uv/src/eio/xthread.h) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/Changes (renamed from deps/uv/src/ev/Changes) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/LICENSE (renamed from deps/uv/src/ev/LICENSE) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/Makefile.am (renamed from deps/uv/src/ev/Makefile.am) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/Makefile.in (renamed from deps/uv/src/ev/Makefile.in) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/README (renamed from deps/uv/src/ev/README) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/aclocal.m4 (renamed from deps/uv/src/ev/aclocal.m4) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/autogen.sh (renamed from deps/uv/src/ev/autogen.sh) | 0 | ||||
-rwxr-xr-x | deps/uv/src/unix/ev/config.guess (renamed from deps/uv/src/ev/config.guess) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/config.h.in (renamed from deps/uv/src/ev/config.h.in) | 0 | ||||
-rwxr-xr-x | deps/uv/src/unix/ev/config.sub (renamed from deps/uv/src/ev/config.sub) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/config_cygwin.h (renamed from deps/uv/src/ev/config_cygwin.h) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/config_darwin.h (renamed from deps/uv/src/ev/config_darwin.h) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/config_freebsd.h (renamed from deps/uv/src/ev/config_freebsd.h) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/config_linux.h (renamed from deps/uv/src/ev/config_linux.h) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/config_sunos.h (renamed from deps/uv/src/ev/config_sunos.h) | 0 | ||||
-rwxr-xr-x | deps/uv/src/unix/ev/configure (renamed from deps/uv/src/ev/configure) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/configure.ac (renamed from deps/uv/src/ev/configure.ac) | 0 | ||||
-rwxr-xr-x | deps/uv/src/unix/ev/depcomp (renamed from deps/uv/src/ev/depcomp) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/ev++.h (renamed from deps/uv/src/ev/ev++.h) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/ev.3 (renamed from deps/uv/src/ev/ev.3) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/ev.c (renamed from deps/uv/src/ev/ev.c) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/ev.pod (renamed from deps/uv/src/ev/ev.pod) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/ev_epoll.c (renamed from deps/uv/src/ev/ev_epoll.c) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/ev_kqueue.c (renamed from deps/uv/src/ev/ev_kqueue.c) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/ev_poll.c (renamed from deps/uv/src/ev/ev_poll.c) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/ev_port.c (renamed from deps/uv/src/ev/ev_port.c) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/ev_select.c (renamed from deps/uv/src/ev/ev_select.c) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/ev_vars.h (renamed from deps/uv/src/ev/ev_vars.h) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/ev_win32.c (renamed from deps/uv/src/ev/ev_win32.c) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/ev_wrap.h (renamed from deps/uv/src/ev/ev_wrap.h) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/event.c (renamed from deps/uv/src/ev/event.c) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/event.h (renamed from deps/uv/src/ev/event.h) | 0 | ||||
-rwxr-xr-x | deps/uv/src/unix/ev/install-sh (renamed from deps/uv/src/ev/install-sh) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/libev.m4 (renamed from deps/uv/src/ev/libev.m4) | 0 | ||||
-rwxr-xr-x | deps/uv/src/unix/ev/ltmain.sh (renamed from deps/uv/src/ev/ltmain.sh) | 0 | ||||
-rwxr-xr-x | deps/uv/src/unix/ev/missing (renamed from deps/uv/src/ev/missing) | 0 | ||||
-rwxr-xr-x | deps/uv/src/unix/ev/mkinstalldirs (renamed from deps/uv/src/ev/mkinstalldirs) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/freebsd.c (renamed from deps/uv/src/uv-freebsd.c) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/fs.c | 210 | ||||
-rw-r--r-- | deps/uv/src/unix/internal.h | 2 | ||||
-rw-r--r-- | deps/uv/src/unix/linux.c (renamed from deps/uv/src/uv-linux.c) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/sunos.c (renamed from deps/uv/src/uv-sunos.c) | 0 | ||||
-rw-r--r-- | deps/uv/src/unix/uv-eio.c (renamed from deps/uv/src/uv-eio.c) | 75 | ||||
-rw-r--r-- | deps/uv/src/unix/uv-eio.h (renamed from deps/uv/src/uv-eio.h) | 2 | ||||
-rw-r--r-- | deps/uv/src/uv-common.c | 30 | ||||
-rw-r--r-- | deps/uv/src/uv-common.h | 14 | ||||
-rw-r--r-- | deps/uv/src/uv-unix.c | 468 | ||||
-rw-r--r-- | deps/uv/src/win/async.c | 24 | ||||
-rw-r--r-- | deps/uv/src/win/cares.c | 128 | ||||
-rw-r--r-- | deps/uv/src/win/core.c | 108 | ||||
-rw-r--r-- | deps/uv/src/win/error.c | 30 | ||||
-rw-r--r-- | deps/uv/src/win/fs.c | 240 | ||||
-rw-r--r-- | deps/uv/src/win/getaddrinfo.c | 97 | ||||
-rw-r--r-- | deps/uv/src/win/handle.c | 56 | ||||
-rw-r--r-- | deps/uv/src/win/internal.h | 166 | ||||
-rw-r--r-- | deps/uv/src/win/loop-watcher.c | 38 | ||||
-rw-r--r-- | deps/uv/src/win/pipe.c | 248 | ||||
-rw-r--r-- | deps/uv/src/win/process.c | 111 | ||||
-rw-r--r-- | deps/uv/src/win/req.c | 75 | ||||
-rw-r--r-- | deps/uv/src/win/stdio.c | 10 | ||||
-rw-r--r-- | deps/uv/src/win/stream.c | 32 | ||||
-rw-r--r-- | deps/uv/src/win/tcp.c | 194 | ||||
-rw-r--r-- | deps/uv/src/win/threadpool.c | 22 | ||||
-rw-r--r-- | deps/uv/src/win/timer.c | 80 | ||||
-rw-r--r-- | deps/uv/src/win/udp.c | 117 | ||||
-rw-r--r-- | deps/uv/src/win/util.c | 26 | ||||
-rw-r--r-- | deps/uv/test/benchmark-ares.c | 16 | ||||
-rw-r--r-- | deps/uv/test/benchmark-getaddrinfo.c | 17 | ||||
-rw-r--r-- | deps/uv/test/benchmark-ping-pongs.c | 14 | ||||
-rw-r--r-- | deps/uv/test/benchmark-pound.c | 25 | ||||
-rw-r--r-- | deps/uv/test/benchmark-pump.c | 48 | ||||
-rw-r--r-- | deps/uv/test/benchmark-spawn.c | 19 | ||||
-rw-r--r-- | deps/uv/test/benchmark-udp-packet-storm.c | 15 | ||||
-rw-r--r-- | deps/uv/test/dns-server.c | 15 | ||||
-rw-r--r-- | deps/uv/test/echo-server.c | 42 | ||||
-rw-r--r-- | deps/uv/test/test-async.c | 6 | ||||
-rw-r--r-- | deps/uv/test/test-callback-stack.c | 10 | ||||
-rw-r--r-- | deps/uv/test/test-connection-fail.c | 11 | ||||
-rw-r--r-- | deps/uv/test/test-delayed-accept.c | 24 | ||||
-rw-r--r-- | deps/uv/test/test-fs.c | 143 | ||||
-rw-r--r-- | deps/uv/test/test-getaddrinfo.c | 19 | ||||
-rw-r--r-- | deps/uv/test/test-gethostbyname.c | 16 | ||||
-rw-r--r-- | deps/uv/test/test-getsockname.c | 37 | ||||
-rw-r--r-- | deps/uv/test/test-idle.c | 7 | ||||
-rw-r--r-- | deps/uv/test/test-loop-handles.c | 17 | ||||
-rw-r--r-- | deps/uv/test/test-ping-pong.c | 14 | ||||
-rw-r--r-- | deps/uv/test/test-pipe-bind-error.c | 32 | ||||
-rw-r--r-- | deps/uv/test/test-ref.c | 33 | ||||
-rw-r--r-- | deps/uv/test/test-shutdown-eof.c | 8 | ||||
-rw-r--r-- | deps/uv/test/test-spawn.c | 32 | ||||
-rw-r--r-- | deps/uv/test/test-tcp-bind-error.c | 42 | ||||
-rw-r--r-- | deps/uv/test/test-tcp-bind6-error.c | 33 | ||||
-rw-r--r-- | deps/uv/test/test-tcp-writealot.c | 9 | ||||
-rw-r--r-- | deps/uv/test/test-threadpool.c | 4 | ||||
-rw-r--r-- | deps/uv/test/test-timer-again.c | 27 | ||||
-rw-r--r-- | deps/uv/test/test-timer.c | 16 | ||||
-rw-r--r-- | deps/uv/test/test-udp-dgram-too-big.c | 6 | ||||
-rw-r--r-- | deps/uv/test/test-udp-ipv6.c | 8 | ||||
-rw-r--r-- | deps/uv/test/test-udp-send-and-recv.c | 6 | ||||
-rw-r--r-- | deps/uv/uv.gyp | 57 |
130 files changed, 2080 insertions, 1617 deletions
diff --git a/deps/uv/Makefile b/deps/uv/Makefile index b106ad4c8..d12527168 100644 --- a/deps/uv/Makefile +++ b/deps/uv/Makefile @@ -24,7 +24,7 @@ ifdef MSVC uname_S := MINGW endif -CPPFLAGS += -Iinclude +CPPFLAGS += -Iinclude -Iinclude/uv-private CARES_OBJS = CARES_OBJS += src/ares/ares__close_sockets.o diff --git a/deps/uv/config-unix.mk b/deps/uv/config-unix.mk index 24e8f2dc9..372085193 100644 --- a/deps/uv/config-unix.mk +++ b/deps/uv/config-unix.mk @@ -23,7 +23,7 @@ AR = $(PREFIX)ar E= CSTDFLAG=--std=c89 -pedantic -Wall -Wextra -Wno-unused-parameter CFLAGS=-g -CPPFLAGS += -Isrc/ev +CPPFLAGS += -Isrc/unix/ev LINKFLAGS=-lm CPPFLAGS += -D_LARGEFILE_SOURCE @@ -34,7 +34,7 @@ EV_CONFIG=config_sunos.h EIO_CONFIG=config_sunos.h CPPFLAGS += -Isrc/ares/config_sunos -D__EXTENSIONS__ -D_XOPEN_SOURCE=500 LINKFLAGS+=-lsocket -lnsl -UV_OS_FILE=uv-sunos.c +UV_OS_FILE=sunos.c endif ifeq (Darwin,$(uname_S)) @@ -42,7 +42,7 @@ EV_CONFIG=config_darwin.h EIO_CONFIG=config_darwin.h CPPFLAGS += -Isrc/ares/config_darwin LINKFLAGS+=-framework CoreServices -UV_OS_FILE=uv-darwin.c +UV_OS_FILE=darwin.c endif ifeq (Linux,$(uname_S)) @@ -51,7 +51,7 @@ EIO_CONFIG=config_linux.h CSTDFLAG += -D_XOPEN_SOURCE=600 CPPFLAGS += -Isrc/ares/config_linux LINKFLAGS+=-lrt -UV_OS_FILE=uv-linux.c +UV_OS_FILE=linux.c endif ifeq (FreeBSD,$(uname_S)) @@ -59,7 +59,7 @@ EV_CONFIG=config_freebsd.h EIO_CONFIG=config_freebsd.h CPPFLAGS += -Isrc/ares/config_freebsd LINKFLAGS+= -UV_OS_FILE=uv-freebsd.c +UV_OS_FILE=freebsd.c endif ifneq (,$(findstring CYGWIN,$(uname_S))) @@ -69,7 +69,7 @@ EIO_CONFIG=config_cygwin.h CSTDFLAG = -D_GNU_SOURCE CPPFLAGS += -Isrc/ares/config_cygwin LINKFLAGS+= -UV_OS_FILE=uv-cygwin.c +UV_OS_FILE=cygwin.c endif # Need _GNU_SOURCE for strdup? @@ -85,24 +85,24 @@ endif RUNNER_LIBS= RUNNER_SRC=test/runner-unix.c -uv.a: src/uv-unix.o src/unix/fs.o src/uv-common.o src/uv-platform.o src/ev/ev.o src/uv-eio.o src/eio/eio.o $(CARES_OBJS) - $(AR) rcs uv.a src/uv-unix.o src/unix/fs.o src/uv-platform.o src/uv-common.o src/uv-eio.o src/ev/ev.o \ - src/eio/eio.o $(CARES_OBJS) +uv.a: src/uv-unix.o src/unix/fs.o src/uv-common.o src/uv-platform.o src/unix/ev/ev.o src/unix/uv-eio.o src/unix/eio/eio.o $(CARES_OBJS) + $(AR) rcs uv.a src/uv-unix.o src/unix/fs.o src/uv-platform.o src/uv-common.o src/unix/uv-eio.o src/unix/ev/ev.o \ + src/unix/eio/eio.o $(CARES_OBJS) -src/uv-platform.o: src/$(UV_OS_FILE) include/uv.h include/uv-unix.h - $(CC) $(CSTDFLAG) $(CPPFLAGS) $(CFLAGS) -c src/$(UV_OS_FILE) -o src/uv-platform.o +src/uv-platform.o: src/unix/$(UV_OS_FILE) include/uv.h include/uv-private/uv-unix.h + $(CC) $(CSTDFLAG) $(CPPFLAGS) $(CFLAGS) -c src/unix/$(UV_OS_FILE) -o src/uv-platform.o -src/uv-unix.o: src/uv-unix.c include/uv.h include/uv-unix.h src/unix/internal.h +src/uv-unix.o: src/uv-unix.c include/uv.h include/uv-private/uv-unix.h src/unix/internal.h $(CC) $(CSTDFLAG) $(CPPFLAGS) -Isrc $(CFLAGS) -c src/uv-unix.c -o src/uv-unix.o -src/unix/fs.o: src/unix/fs.c include/uv.h include/uv-unix.h src/unix/internal.h +src/unix/fs.o: src/unix/fs.c include/uv.h include/uv-private/uv-unix.h src/unix/internal.h $(CC) $(CSTDFLAG) $(CPPFLAGS) -Isrc/ $(CFLAGS) -c src/unix/fs.c -o src/unix/fs.o -src/uv-common.o: src/uv-common.c include/uv.h include/uv-unix.h +src/uv-common.o: src/uv-common.c include/uv.h include/uv-private/uv-unix.h $(CC) $(CSTDFLAG) $(CPPFLAGS) $(CFLAGS) -c src/uv-common.c -o src/uv-common.o -src/ev/ev.o: src/ev/ev.c - $(CC) $(CPPFLAGS) $(CFLAGS) -c src/ev/ev.c -o src/ev/ev.o -DEV_CONFIG_H=\"$(EV_CONFIG)\" +src/unix/ev/ev.o: src/unix/ev/ev.c + $(CC) $(CPPFLAGS) $(CFLAGS) -c src/unix/ev/ev.c -o src/unix/ev/ev.o -DEV_CONFIG_H=\"$(EV_CONFIG)\" EIO_CPPFLAGS += $(CPPFLAGS) @@ -110,21 +110,23 @@ EIO_CPPFLAGS += -DEIO_CONFIG_H=\"$(EIO_CONFIG)\" EIO_CPPFLAGS += -DEIO_STACKSIZE=262144 EIO_CPPFLAGS += -D_GNU_SOURCE -src/eio/eio.o: src/eio/eio.c - $(CC) $(EIO_CPPFLAGS) $(CFLAGS) -c src/eio/eio.c -o src/eio/eio.o +src/unix/eio/eio.o: src/unix/eio/eio.c + $(CC) $(EIO_CPPFLAGS) $(CFLAGS) -c src/unix/eio/eio.c -o src/unix/eio/eio.o -src/uv-eio.o: src/uv-eio.c - $(CC) $(CPPFLAGS) -Isrc/eio/ $(CSTDFLAG) $(CFLAGS) -c src/uv-eio.c -o src/uv-eio.o +src/unix/uv-eio.o: src/unix/uv-eio.c + $(CC) $(CPPFLAGS) -Isrc/unix/eio/ $(CSTDFLAG) $(CFLAGS) -c src/unix/uv-eio.c -o src/unix/uv-eio.o clean-platform: -rm -f src/ares/*.o - -rm -f src/ev/*.o - -rm -f src/eio/*.o + -rm -f src/unix/ev/*.o + -rm -f src/unix/eio/*.o + -rm -f src/unix/*.o -rm -rf test/run-tests.dSYM run-benchmarks.dSYM distclean-platform: -rm -f src/ares/*.o - -rm -f src/ev/*.o - -rm -f src/eio/*.o + -rm -f src/unix/ev/*.o + -rm -f src/unix/*.o + -rm -f src/unix/eio/*.o -rm -rf test/run-tests.dSYM run-benchmarks.dSYM diff --git a/deps/uv/include/eio.h b/deps/uv/include/uv-private/eio.h index 380048c0c..450df6ba2 100644 --- a/deps/uv/include/eio.h +++ b/deps/uv/include/uv-private/eio.h @@ -195,7 +195,7 @@ enum enum { EIO_MCL_CURRENT = 1, - EIO_MCL_FUTURE = 2, + EIO_MCL_FUTURE = 2 }; /* request priorities */ @@ -203,7 +203,7 @@ enum enum { EIO_PRI_MIN = -4, EIO_PRI_MAX = 4, - EIO_PRI_DEFAULT = 0, + EIO_PRI_DEFAULT = 0 }; /* eio request structure */ diff --git a/deps/uv/include/ev.h b/deps/uv/include/uv-private/ev.h index 1db1e2664..1db1e2664 100644 --- a/deps/uv/include/ev.h +++ b/deps/uv/include/uv-private/ev.h diff --git a/deps/uv/include/ngx-queue.h b/deps/uv/include/uv-private/ngx-queue.h index f8576d67d..f8576d67d 100644 --- a/deps/uv/include/ngx-queue.h +++ b/deps/uv/include/uv-private/ngx-queue.h diff --git a/deps/uv/include/tree.h b/deps/uv/include/uv-private/tree.h index 37966d353..37966d353 100644 --- a/deps/uv/include/tree.h +++ b/deps/uv/include/uv-private/tree.h diff --git a/deps/uv/include/uv-unix.h b/deps/uv/include/uv-private/uv-unix.h index 31335a92a..b7f01ae77 100644 --- a/deps/uv/include/uv-unix.h +++ b/deps/uv/include/uv-private/uv-unix.h @@ -42,6 +42,16 @@ typedef struct { typedef int uv_file; +#define UV_LOOP_PRIVATE_FIELDS \ + ares_channel channel; \ + /* \ + * While the channel is active this timer is called once per second to be \ + * sure that we're always calling ares_process. See the warning above the \ + * definition of ares_timeout(). \ + */ \ + ev_timer timer; \ + struct ev_loop* ev; + #define UV_REQ_BUFSML_SIZE (4) #define UV_REQ_PRIVATE_FIELDS /* empty */ diff --git a/deps/uv/include/uv-win.h b/deps/uv/include/uv-private/uv-win.h index 438b18fce..cd15705ea 100644 --- a/deps/uv/include/uv-win.h +++ b/deps/uv/include/uv-private/uv-win.h @@ -44,6 +44,40 @@ typedef struct uv_buf_t { typedef int uv_file; +RB_HEAD(uv_timer_tree_s, uv_timer_s); + +#define UV_LOOP_PRIVATE_FIELDS \ + /* The loop's I/O completion port */ \ + HANDLE iocp; \ + /* Reference count that keeps the event loop alive */ \ + int refs; \ + /* The current time according to the event loop. in msecs. */ \ + int64_t time; \ + /* Tail of a single-linked circular queue of pending reqs. If the queue */ \ + /* is empty, tail_ is NULL. If there is only one item, */ \ + /* tail_->next_req == tail_ */ \ + uv_req_t* pending_reqs_tail; \ + /* Head of a single-linked list of closed handles */ \ + uv_handle_t* endgame_handles; \ + /* The head of the timers tree */ \ + struct uv_timer_tree_s timers; \ + /* Lists of active loop (prepare / check / idle) watchers */ \ + uv_prepare_t* prepare_handles; \ + uv_check_t* check_handles; \ + uv_idle_t* idle_handles; \ + /* This pointer will refer to the prepare/check/idle handle whose */ \ + /* callback is scheduled to be called next. This is needed to allow */ \ + /* safe removal from one of the lists above while that list being */ \ + /* iterated over. */ \ + uv_prepare_t* next_prepare_handle; \ + uv_check_t* next_check_handle; \ + uv_idle_t* next_idle_handle; \ + ares_channel ares_channel; \ + int ares_active_sockets; \ + uv_timer_t ares_polling_timer; \ + /* Last error code */ \ + uv_err_t last_error; + #define UV_REQ_TYPE_PRIVATE \ /* TODO: remove the req suffix */ \ UV_ARES_EVENT_REQ, \ @@ -227,5 +261,7 @@ typedef int uv_file; #define UV_WORK_PRIVATE_FIELDS \ -int uv_utf16_to_utf8(const wchar_t* utf16Buffer, size_t utf16Size, char* utf8Buffer, size_t utf8Size); -int uv_utf8_to_utf16(const char* utf8Buffer, wchar_t* utf16Buffer, size_t utf16Size); +int uv_utf16_to_utf8(const wchar_t* utf16Buffer, size_t utf16Size, + char* utf8Buffer, size_t utf8Size); +int uv_utf8_to_utf16(const char* utf8Buffer, wchar_t* utf16Buffer, + size_t utf16Size); diff --git a/deps/uv/include/uv.h b/deps/uv/include/uv.h index 63d93d12e..a64f18e70 100644 --- a/deps/uv/include/uv.h +++ b/deps/uv/include/uv.h @@ -19,7 +19,7 @@ * IN THE SOFTWARE. */ -/* See uv_init for an introduction. */ +/* See uv_loop_new for an introduction. */ #ifndef UV_H #define UV_H @@ -41,6 +41,8 @@ extern "C" { typedef intptr_t ssize_t; #endif +typedef struct uv_loop_s uv_loop_t; +typedef struct uv_ares_task_s uv_ares_task_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; @@ -54,6 +56,7 @@ typedef struct uv_idle_s uv_idle_t; typedef struct uv_async_s uv_async_t; typedef struct uv_getaddrinfo_s uv_getaddrinfo_t; typedef struct uv_process_s uv_process_t; +typedef struct uv_counters_s uv_counters_t; /* Request types */ typedef struct uv_req_s uv_req_t; typedef struct uv_shutdown_s uv_shutdown_t; @@ -64,41 +67,45 @@ typedef struct uv_fs_s uv_fs_t; typedef struct uv_work_s uv_work_t; #if defined(__unix__) || defined(__POSIX__) || defined(__APPLE__) -# include "uv-unix.h" +# include "uv-private/uv-unix.h" #else -# include "uv-win.h" +# include "uv-private/uv-win.h" #endif /* * This function must be called before any other functions in libuv. * - * At the moment libuv is single threaded but this will likely change in the - * near future. Basically it will change by uv_init() taking a 'loop' - * argument and all other _init having a first argument as the the 'loop'. - * * All functions besides uv_run() are non-blocking. * * All callbacks in libuv are made asynchronously. That is they are never * made by the function that takes them as a parameter. */ void uv_init(); +uv_loop_t* uv_loop_new(); + +void uv_loop_delete(uv_loop_t*); + +/* + * Returns the default loop. + */ +uv_loop_t* uv_default_loop(); /* * This function starts the event loop. It blocks until the reference count * of the loop drops to zero. */ -int uv_run(); +int uv_run(uv_loop_t*); /* * Manually modify the event loop's reference count. Useful if the user wants * to have a handle or timeout that doesn't keep the loop alive. */ -void uv_ref(); -void uv_unref(); +void uv_ref(uv_loop_t*); +void uv_unref(uv_loop_t*); -void uv_update_time(); -int64_t uv_now(); +void uv_update_time(uv_loop_t*); +int64_t uv_now(uv_loop_t*); /* @@ -123,7 +130,8 @@ typedef void (*uv_async_cb)(uv_async_t* handle, int status); typedef void (*uv_prepare_cb)(uv_prepare_t* handle, int status); typedef void (*uv_check_cb)(uv_check_t* handle, int status); typedef void (*uv_idle_cb)(uv_idle_t* handle, int status); -typedef void (*uv_getaddrinfo_cb)(uv_getaddrinfo_t* handle, int status, struct addrinfo* res); +typedef void (*uv_getaddrinfo_cb)(uv_getaddrinfo_t* handle, int status, + struct addrinfo* res); typedef void (*uv_exit_cb)(uv_process_t*, int exit_status, int term_signal); typedef void (*uv_fs_cb)(uv_fs_t* req); typedef void (*uv_work_cb)(uv_work_t* req); @@ -223,7 +231,7 @@ struct uv_err_s { * On error the user should then call uv_last_error() to determine * the error code. */ -uv_err_t uv_last_error(); +uv_err_t uv_last_error(uv_loop_t*); char* uv_strerror(uv_err_t err); const char* uv_err_name(uv_err_t err); @@ -266,6 +274,7 @@ struct uv_shutdown_s { #define UV_HANDLE_FIELDS \ /* read-only */ \ + uv_loop_t* loop; \ uv_handle_type type; \ /* public */ \ uv_close_cb close_cb; \ @@ -358,7 +367,7 @@ typedef enum { UV_STDERR } uv_std_type; -uv_stream_t* uv_std_handle(uv_std_type type); +uv_stream_t* uv_std_handle(uv_loop_t*, uv_std_type type); /* * Write data to stream. Buffers are written in order. Example: @@ -402,7 +411,7 @@ struct uv_tcp_s { UV_TCP_PRIVATE_FIELDS }; -int uv_tcp_init(uv_tcp_t* handle); +int uv_tcp_init(uv_loop_t*, uv_tcp_t* handle); int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr_in); int uv_tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6); @@ -485,7 +494,7 @@ struct uv_udp_send_s { * Initialize a new UDP handle. The actual socket is created lazily. * Returns 0 on success. */ -int uv_udp_init(uv_udp_t* handle); +int uv_udp_init(uv_loop_t*, uv_udp_t* handle); /* * Bind to a IPv4 address and port. @@ -590,7 +599,7 @@ struct uv_pipe_s { UV_PIPE_PRIVATE_FIELDS }; -int uv_pipe_init(uv_pipe_t* handle); +int uv_pipe_init(uv_loop_t*, uv_pipe_t* handle); int uv_pipe_bind(uv_pipe_t* handle, const char* name); @@ -610,7 +619,7 @@ struct uv_prepare_s { UV_PREPARE_PRIVATE_FIELDS }; -int uv_prepare_init(uv_prepare_t* prepare); +int uv_prepare_init(uv_loop_t*, uv_prepare_t* prepare); int uv_prepare_start(uv_prepare_t* prepare, uv_prepare_cb cb); @@ -628,7 +637,7 @@ struct uv_check_s { UV_CHECK_PRIVATE_FIELDS }; -int uv_check_init(uv_check_t* check); +int uv_check_init(uv_loop_t*, uv_check_t* check); int uv_check_start(uv_check_t* check, uv_check_cb cb); @@ -648,7 +657,7 @@ struct uv_idle_s { UV_IDLE_PRIVATE_FIELDS }; -int uv_idle_init(uv_idle_t* idle); +int uv_idle_init(uv_loop_t*, uv_idle_t* idle); int uv_idle_start(uv_idle_t* idle, uv_idle_cb cb); @@ -670,7 +679,7 @@ struct uv_async_s { UV_ASYNC_PRIVATE_FIELDS }; -int uv_async_init(uv_async_t* async, uv_async_cb async_cb); +int uv_async_init(uv_loop_t*, uv_async_t* async, uv_async_cb async_cb); /* * This can be called from other threads to wake up a libuv thread. @@ -691,7 +700,7 @@ struct uv_timer_s { UV_TIMER_PRIVATE_FIELDS }; -int uv_timer_init(uv_timer_t* timer); +int uv_timer_init(uv_loop_t*, uv_timer_t* timer); int uv_timer_start(uv_timer_t* timer, uv_timer_cb cb, int64_t timeout, int64_t repeat); @@ -717,11 +726,13 @@ int64_t uv_timer_get_repeat(uv_timer_t* timer); /* c-ares integration initialize and terminate */ -int uv_ares_init_options(ares_channel *channelptr, +int uv_ares_init_options(uv_loop_t*, + ares_channel *channelptr, struct ares_options *options, int optmask); -void uv_ares_destroy(ares_channel channel); +/* TODO remove the loop argument from this function? */ +void uv_ares_destroy(uv_loop_t*, ares_channel channel); /* @@ -745,7 +756,8 @@ struct uv_getaddrinfo_s { * Input arguments may be released after return from this call. Callback * must not call freeaddrinfo. */ - int uv_getaddrinfo(uv_getaddrinfo_t* handle, + int uv_getaddrinfo(uv_loop_t*, + uv_getaddrinfo_t* handle, uv_getaddrinfo_cb getaddrinfo_cb, const char* node, const char* service, @@ -799,7 +811,7 @@ struct uv_process_s { }; /* Initializes uv_process_t and starts the process. */ -int uv_spawn(uv_process_t*, uv_process_options_t options); +int uv_spawn(uv_loop_t*, uv_process_t*, uv_process_options_t options); /* * Kills the process with the specified signal. The user must still @@ -813,13 +825,14 @@ int uv_process_kill(uv_process_t*, int signum); */ struct uv_work_s { UV_REQ_FIELDS + uv_loop_t* loop; uv_work_cb work_cb; uv_after_work_cb after_work_cb; UV_WORK_PRIVATE_FIELDS }; /* Queues a work request to execute asynchronously on the thread pool. */ -int uv_queue_work(uv_work_t* req, uv_work_cb work_cb, +int uv_queue_work(uv_loop_t* loop, uv_work_t* req, uv_work_cb work_cb, uv_after_work_cb after_work_cb); @@ -858,6 +871,7 @@ typedef enum { */ struct uv_fs_s { UV_REQ_FIELDS + uv_loop_t* loop; uv_fs_type fs_type; uv_fs_cb cb; ssize_t result; @@ -867,31 +881,48 @@ struct uv_fs_s { }; void uv_fs_req_cleanup(uv_fs_t* req); -int uv_fs_close(uv_fs_t* req, uv_file file, uv_fs_cb cb); -int uv_fs_open(uv_fs_t* req, const char* path, int flags, int mode, uv_fs_cb cb); -int uv_fs_read(uv_fs_t* req, uv_file file, void* buf, size_t length, off_t offset, uv_fs_cb cb); -int uv_fs_unlink(uv_fs_t* req, const char* path, uv_fs_cb cb); -int uv_fs_write(uv_fs_t* req, uv_file file, void* buf, size_t length, off_t offset, uv_fs_cb cb); -int uv_fs_mkdir(uv_fs_t* req, const char* path, int mode, uv_fs_cb cb); -int uv_fs_rmdir(uv_fs_t* req, const char* path, uv_fs_cb cb); -int uv_fs_readdir(uv_fs_t* req, const char* path, int flags, uv_fs_cb cb); -int uv_fs_stat(uv_fs_t* req, const char* path, uv_fs_cb cb); -int uv_fs_fstat(uv_fs_t* req, uv_file file, uv_fs_cb cb); -int uv_fs_rename(uv_fs_t* req, const char* path, const char* new_path, uv_fs_cb cb); -int uv_fs_fsync(uv_fs_t* req, uv_file file, uv_fs_cb cb); -int uv_fs_fdatasync(uv_fs_t* req, uv_file file, uv_fs_cb cb); -int uv_fs_ftruncate(uv_fs_t* req, uv_file file, off_t offset, uv_fs_cb cb); -int uv_fs_sendfile(uv_fs_t* req, uv_file out_fd, uv_file in_fd, off_t in_offset, size_t length, uv_fs_cb cb); -int uv_fs_chmod(uv_fs_t* req, const char* path, int mode, uv_fs_cb cb); -int uv_fs_utime(uv_fs_t* req, const char* path, double atime, double mtime, uv_fs_cb cb); -int uv_fs_futime(uv_fs_t* req, uv_file file, double atime, double mtime, uv_fs_cb cb); -int uv_fs_lstat(uv_fs_t* req, const char* path, uv_fs_cb cb); -int uv_fs_link(uv_fs_t* req, const char* path, const char* new_path, uv_fs_cb cb); -int uv_fs_symlink(uv_fs_t* req, const char* path, const char* new_path, uv_fs_cb cb); -int uv_fs_readlink(uv_fs_t* req, const char* path, uv_fs_cb cb); -int uv_fs_fchmod(uv_fs_t* req, uv_file file, int mode, uv_fs_cb cb); -int uv_fs_chown(uv_fs_t* req, const char* path, int uid, int gid, uv_fs_cb cb); -int uv_fs_fchown(uv_fs_t* req, uv_file file, int uid, int gid, uv_fs_cb cb); +int uv_fs_close(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb); +int uv_fs_open(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, + int mode, uv_fs_cb cb); +int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, uv_file file, void* buf, + size_t length, off_t offset, uv_fs_cb cb); +int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb); +int uv_fs_write(uv_loop_t* loop, uv_fs_t* req, uv_file file, void* buf, + size_t length, off_t offset, uv_fs_cb cb); +int uv_fs_mkdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode, + uv_fs_cb cb); +int uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb); +int uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, + uv_fs_cb cb); +int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb); +int uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb); +int uv_fs_rename(uv_loop_t* loop, uv_fs_t* req, const char* path, + const char* new_path, uv_fs_cb cb); +int uv_fs_fsync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb); +int uv_fs_fdatasync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb); +int uv_fs_ftruncate(uv_loop_t* loop, uv_fs_t* req, uv_file file, + off_t offset, uv_fs_cb cb); +int uv_fs_sendfile(uv_loop_t* loop, uv_fs_t* req, uv_file out_fd, + uv_file in_fd, off_t in_offset, size_t length, uv_fs_cb cb); +int uv_fs_chmod(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode, + uv_fs_cb cb); +int uv_fs_utime(uv_loop_t* loop, uv_fs_t* req, const char* path, double atime, + double mtime, uv_fs_cb cb); +int uv_fs_futime(uv_loop_t* loop, uv_fs_t* req, uv_file file, double atime, + double mtime, uv_fs_cb cb); +int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb); +int uv_fs_link(uv_loop_t* loop, uv_fs_t* req, const char* path, + const char* new_path, uv_fs_cb cb); +int uv_fs_symlink(uv_loop_t* loop, uv_fs_t* req, const char* path, + const char* new_path, uv_fs_cb cb); +int uv_fs_readlink(uv_loop_t* loop, uv_fs_t* req, const char* path, + uv_fs_cb cb); +int uv_fs_fchmod(uv_loop_t* loop, uv_fs_t* req, uv_file file, int mode, + uv_fs_cb cb); +int uv_fs_chown(uv_loop_t* loop, uv_fs_t* req, const char* path, int uid, + int gid, uv_fs_cb cb); +int uv_fs_fchown(uv_loop_t* loop, uv_fs_t* req, uv_file file, int uid, + int gid, uv_fs_cb cb); /* Utility */ @@ -941,8 +972,8 @@ union uv_any_req { }; -/* Diagnostic counters */ -typedef struct { +struct uv_counters_s { + uint64_t eio_init; uint64_t req_init; uint64_t handle_init; uint64_t stream_init; @@ -955,9 +986,24 @@ typedef struct { uint64_t async_init; uint64_t timer_init; uint64_t process_init; -} uv_counters_t; +}; -uv_counters_t* uv_counters(); + +struct uv_loop_s { + UV_LOOP_PRIVATE_FIELDS + /* list used for ares task handles */ + uv_ares_task_t* uv_ares_handles_; + /* Various thing for libeio. */ + uv_async_t uv_eio_want_poll_notifier; + uv_async_t uv_eio_done_poll_notifier; + uv_idle_t uv_eio_poller; + /* Diagnostic counters */ + uv_counters_t counters; + /* The last error */ + uv_err_t last_err; + /* User data - use this for whatever. */ + void* data; +}; /* Don't export the private CPP symbols. */ diff --git a/deps/uv/src/uv-cygwin.c b/deps/uv/src/unix/cygwin.c index d56a8e839..d56a8e839 100644 --- a/deps/uv/src/uv-cygwin.c +++ b/deps/uv/src/unix/cygwin.c diff --git a/deps/uv/src/uv-darwin.c b/deps/uv/src/unix/darwin.c index fa2948cd2..fa2948cd2 100644 --- a/deps/uv/src/uv-darwin.c +++ b/deps/uv/src/unix/darwin.c diff --git a/deps/uv/src/eio/Changes b/deps/uv/src/unix/eio/Changes index 9d3e3231c..9d3e3231c 100644 --- a/deps/uv/src/eio/Changes +++ b/deps/uv/src/unix/eio/Changes diff --git a/deps/uv/src/eio/LICENSE b/deps/uv/src/unix/eio/LICENSE index 1ed1324d3..1ed1324d3 100644 --- a/deps/uv/src/eio/LICENSE +++ b/deps/uv/src/unix/eio/LICENSE diff --git a/deps/uv/src/eio/Makefile.am b/deps/uv/src/unix/eio/Makefile.am index e9866c0d5..e9866c0d5 100644 --- a/deps/uv/src/eio/Makefile.am +++ b/deps/uv/src/unix/eio/Makefile.am diff --git a/deps/uv/src/eio/aclocal.m4 b/deps/uv/src/unix/eio/aclocal.m4 index 18abb7368..18abb7368 100644 --- a/deps/uv/src/eio/aclocal.m4 +++ b/deps/uv/src/unix/eio/aclocal.m4 diff --git a/deps/uv/src/eio/autogen.sh b/deps/uv/src/unix/eio/autogen.sh index 8056ee7f9..8056ee7f9 100755 --- a/deps/uv/src/eio/autogen.sh +++ b/deps/uv/src/unix/eio/autogen.sh diff --git a/deps/uv/src/eio/config.h.in b/deps/uv/src/unix/eio/config.h.in index 73e9dd07d..73e9dd07d 100644 --- a/deps/uv/src/eio/config.h.in +++ b/deps/uv/src/unix/eio/config.h.in diff --git a/deps/uv/src/eio/config_cygwin.h b/deps/uv/src/unix/eio/config_cygwin.h index f64e7fe44..f64e7fe44 100644 --- a/deps/uv/src/eio/config_cygwin.h +++ b/deps/uv/src/unix/eio/config_cygwin.h diff --git a/deps/uv/src/eio/config_darwin.h b/deps/uv/src/unix/eio/config_darwin.h index f406759e0..f406759e0 100644 --- a/deps/uv/src/eio/config_darwin.h +++ b/deps/uv/src/unix/eio/config_darwin.h diff --git a/deps/uv/src/eio/config_freebsd.h b/deps/uv/src/unix/eio/config_freebsd.h index 3c93d260f..3c93d260f 100644 --- a/deps/uv/src/eio/config_freebsd.h +++ b/deps/uv/src/unix/eio/config_freebsd.h diff --git a/deps/uv/src/eio/config_linux.h b/deps/uv/src/unix/eio/config_linux.h index 606301faf..606301faf 100644 --- a/deps/uv/src/eio/config_linux.h +++ b/deps/uv/src/unix/eio/config_linux.h diff --git a/deps/uv/src/eio/config_sunos.h b/deps/uv/src/unix/eio/config_sunos.h index 01d049c3e..01d049c3e 100644 --- a/deps/uv/src/eio/config_sunos.h +++ b/deps/uv/src/unix/eio/config_sunos.h diff --git a/deps/uv/src/eio/configure.ac b/deps/uv/src/unix/eio/configure.ac index 9faffad53..9faffad53 100644 --- a/deps/uv/src/eio/configure.ac +++ b/deps/uv/src/unix/eio/configure.ac diff --git a/deps/uv/src/eio/demo.c b/deps/uv/src/unix/eio/demo.c index cbef59557..cbef59557 100644 --- a/deps/uv/src/eio/demo.c +++ b/deps/uv/src/unix/eio/demo.c diff --git a/deps/uv/src/eio/ecb.h b/deps/uv/src/unix/eio/ecb.h index a4aabc109..a4aabc109 100644 --- a/deps/uv/src/eio/ecb.h +++ b/deps/uv/src/unix/eio/ecb.h diff --git a/deps/uv/src/eio/eio.3 b/deps/uv/src/unix/eio/eio.3 index ec5bde33e..ec5bde33e 100644 --- a/deps/uv/src/eio/eio.3 +++ b/deps/uv/src/unix/eio/eio.3 diff --git a/deps/uv/src/eio/eio.c b/deps/uv/src/unix/eio/eio.c index a005db5d3..a005db5d3 100644 --- a/deps/uv/src/eio/eio.c +++ b/deps/uv/src/unix/eio/eio.c diff --git a/deps/uv/src/eio/eio.pod b/deps/uv/src/unix/eio/eio.pod index da5f33c01..da5f33c01 100644 --- a/deps/uv/src/eio/eio.pod +++ b/deps/uv/src/unix/eio/eio.pod diff --git a/deps/uv/src/eio/libeio.m4 b/deps/uv/src/unix/eio/libeio.m4 index 59151f534..59151f534 100644 --- a/deps/uv/src/eio/libeio.m4 +++ b/deps/uv/src/unix/eio/libeio.m4 diff --git a/deps/uv/src/eio/xthread.h b/deps/uv/src/unix/eio/xthread.h index 7184c7bb7..7184c7bb7 100644 --- a/deps/uv/src/eio/xthread.h +++ b/deps/uv/src/unix/eio/xthread.h diff --git a/deps/uv/src/ev/Changes b/deps/uv/src/unix/ev/Changes index d6fca2f67..d6fca2f67 100644 --- a/deps/uv/src/ev/Changes +++ b/deps/uv/src/unix/ev/Changes diff --git a/deps/uv/src/ev/LICENSE b/deps/uv/src/unix/ev/LICENSE index 7fa0e9f84..7fa0e9f84 100644 --- a/deps/uv/src/ev/LICENSE +++ b/deps/uv/src/unix/ev/LICENSE diff --git a/deps/uv/src/ev/Makefile.am b/deps/uv/src/unix/ev/Makefile.am index 058c2cb0c..058c2cb0c 100644 --- a/deps/uv/src/ev/Makefile.am +++ b/deps/uv/src/unix/ev/Makefile.am diff --git a/deps/uv/src/ev/Makefile.in b/deps/uv/src/unix/ev/Makefile.in index 9817a7ebd..9817a7ebd 100644 --- a/deps/uv/src/ev/Makefile.in +++ b/deps/uv/src/unix/ev/Makefile.in diff --git a/deps/uv/src/ev/README b/deps/uv/src/unix/ev/README index ca403c6f4..ca403c6f4 100644 --- a/deps/uv/src/ev/README +++ b/deps/uv/src/unix/ev/README diff --git a/deps/uv/src/ev/aclocal.m4 b/deps/uv/src/unix/ev/aclocal.m4 index 18abb7368..18abb7368 100644 --- a/deps/uv/src/ev/aclocal.m4 +++ b/deps/uv/src/unix/ev/aclocal.m4 diff --git a/deps/uv/src/ev/autogen.sh b/deps/uv/src/unix/ev/autogen.sh index 087d2aa4e..087d2aa4e 100644 --- a/deps/uv/src/ev/autogen.sh +++ b/deps/uv/src/unix/ev/autogen.sh diff --git a/deps/uv/src/ev/config.guess b/deps/uv/src/unix/ev/config.guess index f32079abd..f32079abd 100755 --- a/deps/uv/src/ev/config.guess +++ b/deps/uv/src/unix/ev/config.guess diff --git a/deps/uv/src/ev/config.h.in b/deps/uv/src/unix/ev/config.h.in index 75da15cce..75da15cce 100644 --- a/deps/uv/src/ev/config.h.in +++ b/deps/uv/src/unix/ev/config.h.in diff --git a/deps/uv/src/ev/config.sub b/deps/uv/src/unix/ev/config.sub index 6759825a5..6759825a5 100755 --- a/deps/uv/src/ev/config.sub +++ b/deps/uv/src/unix/ev/config.sub diff --git a/deps/uv/src/ev/config_cygwin.h b/deps/uv/src/unix/ev/config_cygwin.h index 1f6f6d98c..1f6f6d98c 100644 --- a/deps/uv/src/ev/config_cygwin.h +++ b/deps/uv/src/unix/ev/config_cygwin.h diff --git a/deps/uv/src/ev/config_darwin.h b/deps/uv/src/unix/ev/config_darwin.h index 03e3b219e..03e3b219e 100644 --- a/deps/uv/src/ev/config_darwin.h +++ b/deps/uv/src/unix/ev/config_darwin.h diff --git a/deps/uv/src/ev/config_freebsd.h b/deps/uv/src/unix/ev/config_freebsd.h index ebebd4156..ebebd4156 100644 --- a/deps/uv/src/ev/config_freebsd.h +++ b/deps/uv/src/unix/ev/config_freebsd.h diff --git a/deps/uv/src/ev/config_linux.h b/deps/uv/src/unix/ev/config_linux.h index a13b179f2..a13b179f2 100644 --- a/deps/uv/src/ev/config_linux.h +++ b/deps/uv/src/unix/ev/config_linux.h diff --git a/deps/uv/src/ev/config_sunos.h b/deps/uv/src/unix/ev/config_sunos.h index 9f8861d8a..9f8861d8a 100644 --- a/deps/uv/src/ev/config_sunos.h +++ b/deps/uv/src/unix/ev/config_sunos.h diff --git a/deps/uv/src/ev/configure b/deps/uv/src/unix/ev/configure index 98f102f1e..98f102f1e 100755 --- a/deps/uv/src/ev/configure +++ b/deps/uv/src/unix/ev/configure diff --git a/deps/uv/src/ev/configure.ac b/deps/uv/src/unix/ev/configure.ac index 03a784f2e..03a784f2e 100644 --- a/deps/uv/src/ev/configure.ac +++ b/deps/uv/src/unix/ev/configure.ac diff --git a/deps/uv/src/ev/depcomp b/deps/uv/src/unix/ev/depcomp index df8eea7e4..df8eea7e4 100755 --- a/deps/uv/src/ev/depcomp +++ b/deps/uv/src/unix/ev/depcomp diff --git a/deps/uv/src/ev/ev++.h b/deps/uv/src/unix/ev/ev++.h index ce42b5f2d..ce42b5f2d 100644 --- a/deps/uv/src/ev/ev++.h +++ b/deps/uv/src/unix/ev/ev++.h diff --git a/deps/uv/src/ev/ev.3 b/deps/uv/src/unix/ev/ev.3 index f2a451458..f2a451458 100644 --- a/deps/uv/src/ev/ev.3 +++ b/deps/uv/src/unix/ev/ev.3 diff --git a/deps/uv/src/ev/ev.c b/deps/uv/src/unix/ev/ev.c index 5e616c254..5e616c254 100644 --- a/deps/uv/src/ev/ev.c +++ b/deps/uv/src/unix/ev/ev.c diff --git a/deps/uv/src/ev/ev.pod b/deps/uv/src/unix/ev/ev.pod index 4bbef1fcf..4bbef1fcf 100644 --- a/deps/uv/src/ev/ev.pod +++ b/deps/uv/src/unix/ev/ev.pod diff --git a/deps/uv/src/ev/ev_epoll.c b/deps/uv/src/unix/ev/ev_epoll.c index 5deb65211..5deb65211 100644 --- a/deps/uv/src/ev/ev_epoll.c +++ b/deps/uv/src/unix/ev/ev_epoll.c diff --git a/deps/uv/src/ev/ev_kqueue.c b/deps/uv/src/unix/ev/ev_kqueue.c index 1b526d1c7..1b526d1c7 100644 --- a/deps/uv/src/ev/ev_kqueue.c +++ b/deps/uv/src/unix/ev/ev_kqueue.c diff --git a/deps/uv/src/ev/ev_poll.c b/deps/uv/src/unix/ev/ev_poll.c index e53ae0de9..e53ae0de9 100644 --- a/deps/uv/src/ev/ev_poll.c +++ b/deps/uv/src/unix/ev/ev_poll.c diff --git a/deps/uv/src/ev/ev_port.c b/deps/uv/src/unix/ev/ev_port.c index 0ffebc372..0ffebc372 100644 --- a/deps/uv/src/ev/ev_port.c +++ b/deps/uv/src/unix/ev/ev_port.c diff --git a/deps/uv/src/ev/ev_select.c b/deps/uv/src/unix/ev/ev_select.c index 0ea9467e4..0ea9467e4 100644 --- a/deps/uv/src/ev/ev_select.c +++ b/deps/uv/src/unix/ev/ev_select.c diff --git a/deps/uv/src/ev/ev_vars.h b/deps/uv/src/unix/ev/ev_vars.h index 5ee3ed1b2..5ee3ed1b2 100644 --- a/deps/uv/src/ev/ev_vars.h +++ b/deps/uv/src/unix/ev/ev_vars.h diff --git a/deps/uv/src/ev/ev_win32.c b/deps/uv/src/unix/ev/ev_win32.c index 338886efe..338886efe 100644 --- a/deps/uv/src/ev/ev_win32.c +++ b/deps/uv/src/unix/ev/ev_win32.c diff --git a/deps/uv/src/ev/ev_wrap.h b/deps/uv/src/unix/ev/ev_wrap.h index 2c195c5db..2c195c5db 100644 --- a/deps/uv/src/ev/ev_wrap.h +++ b/deps/uv/src/unix/ev/ev_wrap.h diff --git a/deps/uv/src/ev/event.c b/deps/uv/src/unix/ev/event.c index aaf6d534c..aaf6d534c 100644 --- a/deps/uv/src/ev/event.c +++ b/deps/uv/src/unix/ev/event.c diff --git a/deps/uv/src/ev/event.h b/deps/uv/src/unix/ev/event.h index 10ff05a3c..10ff05a3c 100644 --- a/deps/uv/src/ev/event.h +++ b/deps/uv/src/unix/ev/event.h diff --git a/deps/uv/src/ev/install-sh b/deps/uv/src/unix/ev/install-sh index 6ce63b9f7..6ce63b9f7 100755 --- a/deps/uv/src/ev/install-sh +++ b/deps/uv/src/unix/ev/install-sh diff --git a/deps/uv/src/ev/libev.m4 b/deps/uv/src/unix/ev/libev.m4 index e3f4c81b2..e3f4c81b2 100644 --- a/deps/uv/src/ev/libev.m4 +++ b/deps/uv/src/unix/ev/libev.m4 diff --git a/deps/uv/src/ev/ltmain.sh b/deps/uv/src/unix/ev/ltmain.sh index d88da2c26..d88da2c26 100755 --- a/deps/uv/src/ev/ltmain.sh +++ b/deps/uv/src/unix/ev/ltmain.sh diff --git a/deps/uv/src/ev/missing b/deps/uv/src/unix/ev/missing index fc54c64ec..fc54c64ec 100755 --- a/deps/uv/src/ev/missing +++ b/deps/uv/src/unix/ev/missing diff --git a/deps/uv/src/ev/mkinstalldirs b/deps/uv/src/unix/ev/mkinstalldirs index d2d5f21b6..d2d5f21b6 100755 --- a/deps/uv/src/ev/mkinstalldirs +++ b/deps/uv/src/unix/ev/mkinstalldirs diff --git a/deps/uv/src/uv-freebsd.c b/deps/uv/src/unix/freebsd.c index 6766538f0..6766538f0 100644 --- a/deps/uv/src/uv-freebsd.c +++ b/deps/uv/src/unix/freebsd.c diff --git a/deps/uv/src/unix/fs.c b/deps/uv/src/unix/fs.c index 4d26935a4..8987fd0cb 100644 --- a/deps/uv/src/unix/fs.c +++ b/deps/uv/src/unix/fs.c @@ -33,12 +33,14 @@ #include <unistd.h> -static void uv_fs_req_init(uv_fs_t* req, uv_fs_type fs_type, uv_fs_cb cb) { +static void uv_fs_req_init(uv_loop_t* loop, uv_fs_t* req, uv_fs_type fs_type, + uv_fs_cb cb) { /* Make sure the thread pool is initialized. */ - uv_eio_init(); + uv_eio_init(loop); uv__req_init((uv_req_t*) req); req->type = UV_FS; + req->loop = loop; req->fs_type = fs_type; req->cb = cb; req->result = 0; @@ -103,7 +105,7 @@ static int uv__fs_after(eio_req* eio) { req->ptr = req->eio->ptr2; } - uv_unref(); + uv_unref(req->loop); req->eio = NULL; /* Freed by libeio */ req->cb(req); @@ -111,20 +113,20 @@ static int uv__fs_after(eio_req* eio) { } -int uv_fs_close(uv_fs_t* req, uv_file file, uv_fs_cb cb) { - uv_fs_req_init(req, UV_FS_CLOSE, cb); +int uv_fs_close(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { + uv_fs_req_init(loop, req, UV_FS_CLOSE, cb); if (cb) { /* async */ - uv_ref(); + uv_ref(loop); req->eio = eio_close(file, EIO_PRI_DEFAULT, uv__fs_after, req); if (!req->eio) { - uv_err_new(NULL, ENOMEM); + uv_err_new(loop, ENOMEM); return -1; } } else { /* sync */ if ((req->result = uv__close(file))) { - uv_err_new(NULL, errno); + uv_err_new(loop, errno); return -1; } } @@ -133,16 +135,16 @@ int uv_fs_close(uv_fs_t* req, uv_file file, uv_fs_cb cb) { } -int uv_fs_open(uv_fs_t* req, const char* path, int flags, int mode, - uv_fs_cb cb) { - uv_fs_req_init(req, UV_FS_OPEN, cb); +int uv_fs_open(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, + int mode, uv_fs_cb cb) { + uv_fs_req_init(loop, req, UV_FS_OPEN, cb); if (cb) { /* async */ - uv_ref(); + uv_ref(loop); req->eio = eio_open(path, flags, mode, EIO_PRI_DEFAULT, uv__fs_after, req); if (!req->eio) { - uv_err_new(NULL, ENOMEM); + uv_err_new(loop, ENOMEM); return -1; } @@ -150,7 +152,7 @@ int uv_fs_open(uv_fs_t* req, const char* path, int flags, int mode, /* sync */ req->result = open(path, flags, mode); if (req->result < 0) { - uv_err_new(NULL, errno); + uv_err_new(loop, errno); return -1; } @@ -161,18 +163,18 @@ int uv_fs_open(uv_fs_t* req, const char* path, int flags, int mode, } -int uv_fs_read(uv_fs_t* req, uv_file fd, void* buf, size_t length, - off_t offset, uv_fs_cb cb) { - uv_fs_req_init(req, UV_FS_READ, cb); +int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, uv_file fd, void* buf, + size_t length, off_t offset, uv_fs_cb cb) { + uv_fs_req_init(loop, req, UV_FS_READ, cb); if (cb) { /* async */ - uv_ref(); + uv_ref(loop); req->eio = eio_read(fd, buf, length, offset, EIO_PRI_DEFAULT, uv__fs_after, req); if (!req->eio) { - uv_err_new(NULL, ENOMEM); + uv_err_new(loop, ENOMEM); return -1; } @@ -183,7 +185,7 @@ int uv_fs_read(uv_fs_t* req, uv_file fd, void* buf, size_t length, pread(fd, buf, length, offset); if (req->result < 0) { - uv_err_new(NULL, errno); + uv_err_new(loop, errno); return -1; } } @@ -192,15 +194,15 @@ int uv_fs_read(uv_fs_t* req, uv_file fd, void* buf, size_t length, } -int uv_fs_unlink(uv_fs_t* req, const char* path, uv_fs_cb cb) { - uv_fs_req_init(req, UV_FS_UNLINK, cb); +int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { + uv_fs_req_init(loop, req, UV_FS_UNLINK, cb); if (cb) { /* async */ - uv_ref(); + uv_ref(loop); req->eio = eio_unlink(path, EIO_PRI_DEFAULT, uv__fs_after, req); if (!req->eio) { - uv_err_new(NULL, ENOMEM); + uv_err_new(loop, ENOMEM); return -1; } @@ -209,7 +211,7 @@ int uv_fs_unlink(uv_fs_t* req, const char* path, uv_fs_cb cb) { req->result = unlink(path); if (req->result) { - uv_err_new(NULL, errno); + uv_err_new(loop, errno); return -1; } } @@ -218,17 +220,17 @@ int uv_fs_unlink(uv_fs_t* req, const char* path, uv_fs_cb cb) { } -int uv_fs_write(uv_fs_t* req, uv_file file, void* buf, size_t length, - off_t offset, uv_fs_cb cb) { - uv_fs_req_init(req, UV_FS_WRITE, cb); +int uv_fs_write(uv_loop_t* loop, uv_fs_t* req, uv_file file, void* buf, + size_t length, off_t offset, uv_fs_cb cb) { + uv_fs_req_init(loop, req, UV_FS_WRITE, cb); if (cb) { /* async */ - uv_ref(); + uv_ref(loop); req->eio = eio_write(file, buf, length, offset, EIO_PRI_DEFAULT, uv__fs_after, req); if (!req->eio) { - uv_err_new(NULL, ENOMEM); + uv_err_new(loop, ENOMEM); return -1; } @@ -239,7 +241,7 @@ int uv_fs_write(uv_fs_t* req, uv_file file, void* buf, size_t length, pwrite(file, buf, length, offset); if (req->result < 0) { - uv_err_new(NULL, errno); + uv_err_new(loop, errno); return -1; } } @@ -248,15 +250,16 @@ int uv_fs_write(uv_fs_t* req, uv_file file, void* buf, size_t length, } -int uv_fs_mkdir(uv_fs_t* req, const char* path, int mode, uv_fs_cb cb) { - uv_fs_req_init(req, UV_FS_MKDIR, cb); +int uv_fs_mkdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode, + uv_fs_cb cb) { + uv_fs_req_init(loop, req, UV_FS_MKDIR, cb); if (cb) { /* async */ - uv_ref(); + uv_ref(loop); req->eio = eio_mkdir(path, mode, EIO_PRI_DEFAULT, uv__fs_after, req); if (!req->eio) { - uv_err_new(NULL, ENOMEM); + uv_err_new(loop, ENOMEM); return -1; } @@ -265,7 +268,7 @@ int uv_fs_mkdir(uv_fs_t* req, const char* path, int mode, uv_fs_cb cb) { req->result = mkdir(path, mode); if (req->result < 0) { - uv_err_new(NULL, errno); + uv_err_new(loop, errno); return -1; } } @@ -274,15 +277,15 @@ int uv_fs_mkdir(uv_fs_t* req, const char* path, int mode, uv_fs_cb cb) { } -int uv_fs_rmdir(uv_fs_t* req, const char* path, uv_fs_cb cb) { - uv_fs_req_init(req, UV_FS_RMDIR, cb); +int uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { + uv_fs_req_init(loop, req, UV_FS_RMDIR, cb); if (cb) { /* async */ - uv_ref(); + uv_ref(loop); req->eio = eio_rmdir(path, EIO_PRI_DEFAULT, uv__fs_after, req); if (!req->eio) { - uv_err_new(NULL, ENOMEM); + uv_err_new(loop, ENOMEM); return -1; } @@ -291,7 +294,7 @@ int uv_fs_rmdir(uv_fs_t* req, const char* path, uv_fs_cb cb) { req->result = rmdir(path); if (req->result < 0) { - uv_err_new(NULL, errno); + uv_err_new(loop, errno); return -1; } } @@ -300,20 +303,21 @@ int uv_fs_rmdir(uv_fs_t* req, const char* path, uv_fs_cb cb) { } -int uv_fs_readdir(uv_fs_t* req, const char* path, int flags, uv_fs_cb cb) { +int uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, + uv_fs_cb cb) { int r; struct dirent* entry; size_t size = 0; size_t d_namlen = 0; - uv_fs_req_init(req, UV_FS_READDIR, cb); + uv_fs_req_init(loop, req, UV_FS_READDIR, cb); if (cb) { /* async */ - uv_ref(); + uv_ref(loop); req->eio = eio_readdir(path, flags, EIO_PRI_DEFAULT, uv__fs_after, req); if (!req->eio) { - uv_err_new(NULL, ENOMEM); + uv_err_new(loop, ENOMEM); return -1; } @@ -321,7 +325,7 @@ int uv_fs_readdir(uv_fs_t* req, const char* path, int flags, uv_fs_cb cb) { /* sync */ DIR* dir = opendir(path); if (!dir) { - uv_err_new(NULL, errno); + uv_err_new(loop, errno); return -1; } @@ -338,7 +342,7 @@ int uv_fs_readdir(uv_fs_t* req, const char* path, int flags, uv_fs_cb cb) { r = closedir(dir); if (r) { - uv_err_new(NULL, errno); + uv_err_new(loop, errno); return -1; } } @@ -347,11 +351,11 @@ int uv_fs_readdir(uv_fs_t* req, const char* path, int flags, uv_fs_cb cb) { } -int uv_fs_stat(uv_fs_t* req, const char* path, uv_fs_cb cb) { +int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { char* pathdup = path; int pathlen; - uv_fs_req_init(req, UV_FS_STAT, cb); + uv_fs_req_init(loop, req, UV_FS_STAT, cb); /* TODO do this without duplicating the string. */ /* TODO security */ @@ -365,13 +369,13 @@ int uv_fs_stat(uv_fs_t* req, const char* path, uv_fs_cb cb) { if (cb) { /* async */ - uv_ref(); + uv_ref(loop); req->eio = eio_stat(pathdup, EIO_PRI_DEFAULT, uv__fs_after, req); free(pathdup); if (!req->eio) { - uv_err_new(NULL, ENOMEM); + uv_err_new(loop, ENOMEM); return -1; } @@ -382,7 +386,7 @@ int uv_fs_stat(uv_fs_t* req, const char* path, uv_fs_cb cb) { free(pathdup); if (req->result < 0) { - uv_err_new(NULL, errno); + uv_err_new(loop, errno); return -1; } @@ -393,22 +397,22 @@ int uv_fs_stat(uv_fs_t* req, const char* path, uv_fs_cb cb) { } -int uv_fs_fstat(uv_fs_t* req, uv_file file, uv_fs_cb cb) { +int uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { assert(0 && "implement me"); return -1; } -int uv_fs_rename(uv_fs_t* req, const char* path, const char* new_path, +int uv_fs_rename(uv_loop_t* loop, uv_fs_t* req, const char* path, const char* new_path, uv_fs_cb cb) { - uv_fs_req_init(req, UV_FS_RENAME, cb); + uv_fs_req_init(loop, req, UV_FS_RENAME, cb); if (cb) { /* async */ - uv_ref(); + uv_ref(loop); req->eio = eio_rename(path, new_path, EIO_PRI_DEFAULT, uv__fs_after, req); if (!req->eio) { - uv_err_new(NULL, ENOMEM); + uv_err_new(loop, ENOMEM); return -1; } @@ -417,7 +421,7 @@ int uv_fs_rename(uv_fs_t* req, const char* path, const char* new_path, req->result = rename(path, new_path); if (req->result) { - uv_err_new(NULL, errno); + uv_err_new(loop, errno); return -1; } } @@ -426,15 +430,15 @@ int uv_fs_rename(uv_fs_t* req, const char* path, const char* new_path, } -int uv_fs_fsync(uv_fs_t* req, uv_file file, uv_fs_cb cb) { - uv_fs_req_init(req, UV_FS_FSYNC, cb); +int uv_fs_fsync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { + uv_fs_req_init(loop, req, UV_FS_FSYNC, cb); if (cb) { /* async */ - uv_ref(); + uv_ref(loop); req->eio = eio_fsync(file, EIO_PRI_DEFAULT, uv__fs_after, req); if (!req->eio) { - uv_err_new(NULL, ENOMEM); + uv_err_new(loop, ENOMEM); return -1; } @@ -443,7 +447,7 @@ int uv_fs_fsync(uv_fs_t* req, uv_file file, uv_fs_cb cb) { req->result = fsync(file); if (req->result) { - uv_err_new(NULL, errno); + uv_err_new(loop, errno); return -1; } } @@ -452,15 +456,15 @@ int uv_fs_fsync(uv_fs_t* req, uv_file file, uv_fs_cb cb) { } -int uv_fs_fdatasync(uv_fs_t* req, uv_file file, uv_fs_cb cb) { - uv_fs_req_init(req, UV_FS_FDATASYNC, cb); +int uv_fs_fdatasync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { + uv_fs_req_init(loop, req, UV_FS_FDATASYNC, cb); if (cb) { /* async */ - uv_ref(); + uv_ref(loop); req->eio = eio_fdatasync(file, EIO_PRI_DEFAULT, uv__fs_after, req); if (!req->eio) { - uv_err_new(NULL, ENOMEM); + uv_err_new(loop, ENOMEM); return -1; } @@ -469,7 +473,7 @@ int uv_fs_fdatasync(uv_fs_t* req, uv_file file, uv_fs_cb cb) { req->result = fdatasync(file); if (req->result) { - uv_err_new(NULL, errno); + uv_err_new(loop, errno); return -1; } } @@ -478,15 +482,16 @@ int uv_fs_fdatasync(uv_fs_t* req, uv_file file, uv_fs_cb cb) { } -int uv_fs_ftruncate(uv_fs_t* req, uv_file file, off_t offset, uv_fs_cb cb) { - uv_fs_req_init(req, UV_FS_FTRUNCATE, cb); +int uv_fs_ftruncate(uv_loop_t* loop, uv_fs_t* req, uv_file file, off_t offset, + uv_fs_cb cb) { + uv_fs_req_init(loop, req, UV_FS_FTRUNCATE, cb); if (cb) { /* async */ - uv_ref(); + uv_ref(loop); req->eio = eio_ftruncate(file, offset, EIO_PRI_DEFAULT, uv__fs_after, req); if (!req->eio) { - uv_err_new(NULL, ENOMEM); + uv_err_new(loop, ENOMEM); return -1; } @@ -495,7 +500,7 @@ int uv_fs_ftruncate(uv_fs_t* req, uv_file file, off_t offset, uv_fs_cb cb) { req->result = ftruncate(file, offset); if (req->result) { - uv_err_new(NULL, errno); + uv_err_new(loop, errno); return -1; } } @@ -504,17 +509,17 @@ int uv_fs_ftruncate(uv_fs_t* req, uv_file file, off_t offset, uv_fs_cb cb) { } -int uv_fs_sendfile(uv_fs_t* req, uv_file out_fd, uv_file in_fd, +int uv_fs_sendfile(uv_loop_t* loop, uv_fs_t* req, uv_file out_fd, uv_file in_fd, off_t in_offset, size_t length, uv_fs_cb cb) { - uv_fs_req_init(req, UV_FS_SENDFILE, cb); + uv_fs_req_init(loop, req, UV_FS_SENDFILE, cb); if (cb) { /* async */ - uv_ref(); + uv_ref(loop); req->eio = eio_sendfile(out_fd, in_fd, in_offset, length, EIO_PRI_DEFAULT, uv__fs_after, req); if (!req->eio) { - uv_err_new(NULL, ENOMEM); + uv_err_new(loop, ENOMEM); return -1; } @@ -523,7 +528,7 @@ int uv_fs_sendfile(uv_fs_t* req, uv_file out_fd, uv_file in_fd, req->result = eio_sendfile_sync(out_fd, in_fd, in_offset, length); if (req->result) { - uv_err_new(NULL, errno); + uv_err_new(loop, errno); return -1; } } @@ -532,29 +537,32 @@ int uv_fs_sendfile(uv_fs_t* req, uv_file out_fd, uv_file in_fd, } -int uv_fs_chmod(uv_fs_t* req, const char* path, int mode, uv_fs_cb cb) { +int uv_fs_chmod(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode, + uv_fs_cb cb) { assert(0 && "implement me"); return -1; } -int uv_fs_utime(uv_fs_t* req, const char* path, double atime, double mtime, uv_fs_cb cb) { +int uv_fs_utime(uv_loop_t* loop, uv_fs_t* req, const char* path, double atime, + double mtime, uv_fs_cb cb) { assert(0 && "implement me"); return -1; } -int uv_fs_futime(uv_fs_t* req, uv_file file, double atime, double mtime, uv_fs_cb cb) { +int uv_fs_futime(uv_loop_t* loop, uv_fs_t* req, uv_file file, double atime, + double mtime, uv_fs_cb cb) { assert(0 && "implement me"); return -1; } -int uv_fs_lstat(uv_fs_t* req, const char* path, uv_fs_cb cb) { +int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { char* pathdup = path; int pathlen; - uv_fs_req_init(req, UV_FS_LSTAT, cb); + uv_fs_req_init(loop, req, UV_FS_LSTAT, cb); /* TODO do this without duplicating the string. */ /* TODO security */ @@ -568,13 +576,13 @@ int uv_fs_lstat(uv_fs_t* req, const char* path, uv_fs_cb cb) { if (cb) { /* async */ - uv_ref(); + uv_ref(loop); req->eio = eio_lstat(pathdup, EIO_PRI_DEFAULT, uv__fs_after, req); free(pathdup); if (!req->eio) { - uv_err_new(NULL, ENOMEM); + uv_err_new(loop, ENOMEM); return -1; } @@ -585,7 +593,7 @@ int uv_fs_lstat(uv_fs_t* req, const char* path, uv_fs_cb cb) { free(pathdup); if (req->result < 0) { - uv_err_new(NULL, errno); + uv_err_new(loop, errno); return -1; } @@ -596,38 +604,43 @@ int uv_fs_lstat(uv_fs_t* req, const char* path, uv_fs_cb cb) { } -int uv_fs_link(uv_fs_t* req, const char* path, const char* new_path, - uv_fs_cb cb) { +int uv_fs_link(uv_loop_t* loop, uv_fs_t* req, const char* path, + const char* new_path, uv_fs_cb cb) { assert(0 && "implement me"); return -1; } -int uv_fs_symlink(uv_fs_t* req, const char* path, const char* new_path, uv_fs_cb cb) { +int uv_fs_symlink(uv_loop_t* loop, uv_fs_t* req, const char* path, + const char* new_path, uv_fs_cb cb) { assert(0 && "implement me"); return -1; } -int uv_fs_readlink(uv_fs_t* req, const char* path, uv_fs_cb cb) { +int uv_fs_readlink(uv_loop_t* loop, uv_fs_t* req, const char* path, + uv_fs_cb cb) { assert(0 && "implement me"); return -1; } -int uv_fs_fchmod(uv_fs_t* req, uv_file file, int mode, uv_fs_cb cb) { +int uv_fs_fchmod(uv_loop_t* loop, uv_fs_t* req, uv_file file, int mode, + uv_fs_cb cb) { assert(0 && "implement me"); return -1; } -int uv_fs_chown(uv_fs_t* req, const char* path, int uid, int gid, uv_fs_cb cb) { +int uv_fs_chown(uv_loop_t* loop, uv_fs_t* req, const char* path, int uid, + int gid, uv_fs_cb cb) { assert(0 && "implement me"); return -1; } -int uv_fs_fchown(uv_fs_t* req, uv_file file, int uid, int gid, uv_fs_cb cb) { +int uv_fs_fchown(uv_loop_t* loop, uv_fs_t* req, uv_file file, int uid, int gid, + uv_fs_cb cb) { assert(0 && "implement me"); return -1; } @@ -643,7 +656,7 @@ static void uv__work(eio_req* eio) { static int uv__after_work(eio_req *eio) { uv_work_t* req = eio->data; - uv_unref(); + uv_unref(req->loop); if (req->after_work_cb) { req->after_work_cb(req); } @@ -651,14 +664,15 @@ static int uv__after_work(eio_req *eio) { } -int uv_queue_work(uv_work_t* req, uv_work_cb work_cb, +int uv_queue_work(uv_loop_t* loop, uv_work_t* req, uv_work_cb work_cb, uv_after_work_cb after_work_cb) { void* data = req->data; - uv_eio_init(); + uv_eio_init(loop); uv__req_init((uv_req_t*) req); - uv_ref(); + uv_ref(loop); + req->loop = loop; req->data = data; req->work_cb = work_cb; req->after_work_cb = after_work_cb; @@ -666,7 +680,7 @@ int uv_queue_work(uv_work_t* req, uv_work_cb work_cb, req->eio = eio_custom(uv__work, EIO_PRI_DEFAULT, uv__after_work, req); if (!req->eio) { - uv_err_new(NULL, ENOMEM); + uv_err_new(loop, ENOMEM); return -1; } diff --git a/deps/uv/src/unix/internal.h b/deps/uv/src/unix/internal.h index 87ea7fb6b..b1b888700 100644 --- a/deps/uv/src/unix/internal.h +++ b/deps/uv/src/unix/internal.h @@ -27,7 +27,7 @@ int uv__close(int fd); void uv__req_init(uv_req_t*); -uv_err_t uv_err_new(uv_handle_t* handle, int sys_error); +uv_err_t uv_err_new(uv_loop_t* loop, int sys_error); int uv__nonblock(int fd, int set) __attribute__((unused)); int uv__cloexec(int fd, int set) __attribute__((unused)); diff --git a/deps/uv/src/uv-linux.c b/deps/uv/src/unix/linux.c index 03396e9cd..03396e9cd 100644 --- a/deps/uv/src/uv-linux.c +++ b/deps/uv/src/unix/linux.c diff --git a/deps/uv/src/uv-sunos.c b/deps/uv/src/unix/sunos.c index 9ee6a3103..9ee6a3103 100644 --- a/deps/uv/src/uv-sunos.c +++ b/deps/uv/src/unix/sunos.c diff --git a/deps/uv/src/uv-eio.c b/deps/uv/src/unix/uv-eio.c index b07735cad..84afe09b7 100644 --- a/deps/uv/src/uv-eio.c +++ b/deps/uv/src/unix/uv-eio.c @@ -22,51 +22,55 @@ #include "uv.h" #include "eio.h" + #include <assert.h> +#include <stdio.h> -static uv_async_t uv_eio_want_poll_notifier; -static uv_async_t uv_eio_done_poll_notifier; -static uv_idle_t uv_eio_poller; -static int uv_eio_init_count; +/* TODO remove me! */ +static uv_loop_t* main_loop; static void uv_eio_do_poll(uv_idle_t* watcher, int status) { - assert(watcher == &uv_eio_poller); + assert(watcher == &(watcher->loop->uv_eio_poller)); /* printf("uv_eio_poller\n"); */ - if (eio_poll() != -1 && uv_is_active((uv_handle_t*) &uv_eio_poller)) { + if (eio_poll() != -1 && uv_is_active((uv_handle_t*) watcher)) { /* printf("uv_eio_poller stop\n"); */ - uv_idle_stop(&uv_eio_poller); - uv_unref(); + uv_idle_stop(watcher); + uv_unref(watcher->loop); } } /* Called from the main thread. */ static void uv_eio_want_poll_notifier_cb(uv_async_t* watcher, int status) { - assert(watcher == &uv_eio_want_poll_notifier); + uv_loop_t* loop = watcher->loop; + + assert(watcher == &loop->uv_eio_want_poll_notifier); /* printf("want poll notifier\n"); */ - if (eio_poll() == -1 && !uv_is_active((uv_handle_t*) &uv_eio_poller)) { + if (eio_poll() == -1 && !uv_is_active((uv_handle_t*) &loop->uv_eio_poller)) { /* printf("uv_eio_poller start\n"); */ - uv_idle_start(&uv_eio_poller, uv_eio_do_poll); - uv_ref(); + uv_idle_start(&loop->uv_eio_poller, uv_eio_do_poll); + uv_ref(loop); } } static void uv_eio_done_poll_notifier_cb(uv_async_t* watcher, int revents) { - assert(watcher == &uv_eio_done_poll_notifier); + uv_loop_t* loop = watcher->loop; + + assert(watcher == &loop->uv_eio_done_poll_notifier); /* printf("done poll notifier\n"); */ - if (eio_poll() != -1 && uv_is_active((uv_handle_t*) &uv_eio_poller)) { + if (eio_poll() != -1 && uv_is_active((uv_handle_t*) &loop->uv_eio_poller)) { /* printf("uv_eio_poller stop\n"); */ - uv_idle_stop(&uv_eio_poller); - uv_unref(); + uv_idle_stop(&loop->uv_eio_poller); + uv_unref(loop); } } @@ -77,7 +81,13 @@ static void uv_eio_done_poll_notifier_cb(uv_async_t* watcher, int revents) { */ static void uv_eio_want_poll(void) { /* Signal the main thread that eio_poll need to be processed. */ - uv_async_send(&uv_eio_want_poll_notifier); + + /* + * TODO need to select the correct uv_loop_t and async_send to + * uv_eio_want_poll_notifier. + */ + + uv_async_send(&main_loop->uv_eio_want_poll_notifier); } @@ -86,22 +96,27 @@ static void uv_eio_done_poll(void) { * Signal the main thread that we should stop calling eio_poll(). * from the idle watcher. */ - uv_async_send(&uv_eio_done_poll_notifier); + uv_async_send(&main_loop->uv_eio_done_poll_notifier); } -void uv_eio_init() { - if (uv_eio_init_count == 0) { - uv_eio_init_count++; +void uv_eio_init(uv_loop_t* loop) { + if (loop->counters.eio_init == 0) { + loop->counters.eio_init++; + + main_loop = loop; - uv_idle_init(&uv_eio_poller); - uv_idle_start(&uv_eio_poller, uv_eio_do_poll); + uv_idle_init(loop, &loop->uv_eio_poller); + uv_idle_start(&loop->uv_eio_poller, uv_eio_do_poll); - uv_async_init(&uv_eio_want_poll_notifier, uv_eio_want_poll_notifier_cb); - uv_unref(); + loop->uv_eio_want_poll_notifier.data = loop; + uv_async_init(loop, &loop->uv_eio_want_poll_notifier, + uv_eio_want_poll_notifier_cb); + uv_unref(loop); - uv_async_init(&uv_eio_done_poll_notifier, uv_eio_done_poll_notifier_cb); - uv_unref(); + uv_async_init(loop, &loop->uv_eio_done_poll_notifier, + uv_eio_done_poll_notifier_cb); + uv_unref(loop); eio_init(uv_eio_want_poll, uv_eio_done_poll); /* @@ -109,5 +124,11 @@ void uv_eio_init() { * race conditions. See Node's test/simple/test-eio-race.js */ eio_set_max_poll_reqs(10); + } else { + /* + * If this assertion breaks then Ryan hasn't implemented support for + * receiving thread pool requests back to multiple threads. + */ + assert(main_loop == loop); } } diff --git a/deps/uv/src/uv-eio.h b/deps/uv/src/unix/uv-eio.h index 2f2d3486b..711d0cf28 100644 --- a/deps/uv/src/uv-eio.h +++ b/deps/uv/src/unix/uv-eio.h @@ -9,5 +9,5 @@ * safe to call more than once. * TODO: uv_eio_deinit */ -void uv_eio_init(void); +void uv_eio_init(uv_loop_t*); #endif diff --git a/deps/uv/src/uv-common.c b/deps/uv/src/uv-common.c index 2428fdd30..8e85db27a 100644 --- a/deps/uv/src/uv-common.c +++ b/deps/uv/src/uv-common.c @@ -31,9 +31,6 @@ #include "ares/inet_net_pton.h" #include "ares/inet_ntop.h" -/* list used for ares task handles */ -static uv_ares_task_t* uv_ares_handles_ = NULL; - static uv_counters_t counters; @@ -135,20 +132,23 @@ int uv_ip6_name(struct sockaddr_in6* src, char* dst, size_t size) { /* find matching ares handle in list */ -void uv_add_ares_handle(uv_ares_task_t* handle) { - handle->ares_next = uv_ares_handles_; +void uv_add_ares_handle(uv_loop_t* loop, uv_ares_task_t* handle) { + handle->loop = loop; + handle->ares_next = loop->uv_ares_handles_; handle->ares_prev = NULL; - if (uv_ares_handles_) { - uv_ares_handles_->ares_prev = handle; + if (loop->uv_ares_handles_) { + loop->uv_ares_handles_->ares_prev = handle; } - uv_ares_handles_ = handle; + + loop->uv_ares_handles_ = handle; } /* find matching ares handle in list */ /* TODO: faster lookup */ -uv_ares_task_t* uv_find_ares_handle(ares_socket_t sock) { - uv_ares_task_t* handle = uv_ares_handles_; +uv_ares_task_t* uv_find_ares_handle(uv_loop_t* loop, ares_socket_t sock) { + uv_ares_task_t* handle = loop->uv_ares_handles_; + while (handle != NULL) { if (handle->sock == sock) { break; @@ -161,8 +161,10 @@ uv_ares_task_t* uv_find_ares_handle(ares_socket_t sock) { /* remove ares handle in list */ void uv_remove_ares_handle(uv_ares_task_t* handle) { - if (handle == uv_ares_handles_) { - uv_ares_handles_ = handle->ares_next; + uv_loop_t* loop = handle->loop; + + if (handle == loop->uv_ares_handles_) { + loop->uv_ares_handles_ = handle->ares_next; } if (handle->ares_next) { @@ -176,6 +178,6 @@ void uv_remove_ares_handle(uv_ares_task_t* handle) { /* Returns 1 if the uv_ares_handles_ list is empty. 0 otherwise. */ -int uv_ares_handles_empty() { - return uv_ares_handles_ ? 0 : 1; +int uv_ares_handles_empty(uv_loop_t* loop) { + return loop->uv_ares_handles_ ? 0 : 1; } diff --git a/deps/uv/src/uv-common.h b/deps/uv/src/uv-common.h index a1e74c617..985412d79 100644 --- a/deps/uv/src/uv-common.h +++ b/deps/uv/src/uv-common.h @@ -38,11 +38,6 @@ req->errorno = errno; \ } -/* - * Subclass of uv_handle_t. Used for integration of c-ares. - */ -typedef struct uv_ares_task_s uv_ares_task_t; - struct uv_ares_task_s { UV_HANDLE_FIELDS UV_ARES_TASK_PRIVATE_FIELDS @@ -52,9 +47,12 @@ struct uv_ares_task_s { void uv_remove_ares_handle(uv_ares_task_t* handle); -uv_ares_task_t* uv_find_ares_handle(ares_socket_t sock); -void uv_add_ares_handle(uv_ares_task_t* handle); -int uv_ares_handles_empty(); +uv_ares_task_t* uv_find_ares_handle(uv_loop_t*, ares_socket_t sock); + +/* TODO Rename to uv_ares_task_init? */ +void uv_add_ares_handle(uv_loop_t* loop, uv_ares_task_t* handle); + +int uv_ares_handles_empty(uv_loop_t* loop); #endif /* UV_COMMON_H_ */ diff --git a/deps/uv/src/uv-unix.c b/deps/uv/src/uv-unix.c index 914cd15ce..e73292c93 100644 --- a/deps/uv/src/uv-unix.c +++ b/deps/uv/src/uv-unix.c @@ -85,19 +85,10 @@ extern char **environ; # endif -static uv_err_t last_err; +#define container_of ngx_queue_data -struct uv_ares_data_s { - ares_channel channel; - /* - * While the channel is active this timer is called once per second to be sure - * that we're always calling ares_process. See the warning above the - * definition of ares_timeout(). - */ - ev_timer timer; -}; - -static struct uv_ares_data_s ares_data; +static uv_loop_t default_loop_struct; +static uv_loop_t* default_loop_ptr; void uv__next(EV_P_ ev_idle* watcher, int revents); static int uv__stream_open(uv_stream_t*, int fd, int flags); @@ -157,6 +148,16 @@ enum { }; +void uv_init() { + default_loop_ptr = &default_loop_struct; +#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 + default_loop_struct.ev = ev_default_loop(EVBACKEND_KQUEUE); +#else + default_loop_struct.ev = ev_default_loop(EVFLAG_AUTO); +#endif +} + + /* TODO Share this code with Windows. */ /* TODO Expose callback to user to handle fatal error like V8 does. */ static void uv_fatal_error(const int errorno, const char* syscall) { @@ -180,8 +181,8 @@ static void uv_fatal_error(const int errorno, const char* syscall) { } -uv_err_t uv_last_error() { - return last_err; +uv_err_t uv_last_error(uv_loop_t* loop) { + return loop->last_err; } @@ -210,20 +211,20 @@ static uv_err_code uv_translate_sys_error(int sys_errno) { } -static uv_err_t uv_err_new_artificial(uv_handle_t* handle, int code) { +static uv_err_t uv_err_new_artificial(uv_loop_t* loop, int code) { uv_err_t err; err.sys_errno_ = 0; err.code = code; - last_err = err; + loop->last_err = err; return err; } -uv_err_t uv_err_new(uv_handle_t* handle, int sys_error) { +uv_err_t uv_err_new(uv_loop_t* loop, int sys_error) { uv_err_t err; err.sys_errno_ = sys_error; err.code = uv_translate_sys_error(sys_error); - last_err = err; + loop->last_err = err; return err; } @@ -246,7 +247,7 @@ void uv_close(uv_handle_t* handle, uv_close_cb close_cb) { stream = (uv_stream_t*)handle; uv_read_stop(stream); - ev_io_stop(EV_DEFAULT_ &stream->write_watcher); + ev_io_stop(stream->loop->ev, &stream->write_watcher); uv__close(stream->fd); stream->fd = -1; @@ -282,21 +283,21 @@ void uv_close(uv_handle_t* handle, uv_close_cb close_cb) { case UV_ASYNC: async = (uv_async_t*)handle; - ev_async_stop(EV_DEFAULT_ &async->async_watcher); - ev_ref(EV_DEFAULT_UC); + ev_async_stop(async->loop->ev, &async->async_watcher); + ev_ref(async->loop->ev); break; case UV_TIMER: timer = (uv_timer_t*)handle; if (ev_is_active(&timer->timer_watcher)) { - ev_ref(EV_DEFAULT_UC); + ev_ref(timer->loop->ev); } - ev_timer_stop(EV_DEFAULT_ &timer->timer_watcher); + ev_timer_stop(timer->loop->ev, &timer->timer_watcher); break; case UV_PROCESS: process = (uv_process_t*)handle; - ev_child_stop(EV_DEFAULT_UC_ &process->child_watcher); + ev_child_stop(process->loop->ev, &process->child_watcher); break; default: @@ -306,31 +307,44 @@ void uv_close(uv_handle_t* handle, uv_close_cb close_cb) { handle->flags |= UV_CLOSING; /* This is used to call the on_close callback in the next loop. */ - ev_idle_start(EV_DEFAULT_ &handle->next_watcher); - ev_feed_event(EV_DEFAULT_ &handle->next_watcher, EV_IDLE); + ev_idle_start(handle->loop->ev, &handle->next_watcher); + ev_feed_event(handle->loop->ev, &handle->next_watcher, EV_IDLE); assert(ev_is_pending(&handle->next_watcher)); } -void uv_init() { - /* Initialize the default ev loop. */ -#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 - ev_default_loop(EVBACKEND_KQUEUE); -#else - ev_default_loop(EVFLAG_AUTO); -#endif +uv_loop_t* uv_loop_new() { + uv_loop_t* loop = calloc(1, sizeof(uv_loop_t)); + loop->ev = ev_loop_new(0); + return loop; +} + + +void uv_loop_delete(uv_loop_t* loop) { + uv_ares_destroy(loop, loop->channel); + ev_loop_destroy(loop->ev); + free(loop); +} + + +uv_loop_t* uv_default_loop() { + return default_loop_ptr; } -int uv_run() { - ev_run(EV_DEFAULT_ 0); + + +int uv_run(uv_loop_t* loop) { + ev_run(loop->ev, 0); return 0; } -static void uv__handle_init(uv_handle_t* handle, uv_handle_type type) { - uv_counters()->handle_init++; +static void uv__handle_init(uv_loop_t* loop, uv_handle_t* handle, + uv_handle_type type) { + loop->counters.handle_init++; + handle->loop = loop; handle->type = type; handle->flags = 0; @@ -338,7 +352,7 @@ static void uv__handle_init(uv_handle_t* handle, uv_handle_type type) { handle->next_watcher.data = handle; /* Ref the loop until this handle is closed. See uv__finish_close. */ - ev_ref(EV_DEFAULT_UC); + ev_ref(loop->ev); } @@ -353,7 +367,7 @@ static void uv__udp_watcher_start(uv_udp_t* handle, ev_io* w) { w->data = handle; ev_set_cb(w, uv__udp_io); ev_io_set(w, handle->fd, flags); - ev_io_start(EV_DEFAULT_UC_ w); + ev_io_start(handle->loop->ev, w); } @@ -365,7 +379,7 @@ static void uv__udp_watcher_stop(uv_udp_t* handle, ev_io* w) { flags = (w == &handle->read_watcher ? EV_READ : EV_WRITE); - ev_io_stop(EV_DEFAULT_UC_ w); + ev_io_stop(handle->loop->ev, w); ev_io_set(w, -1, flags); ev_set_cb(w, NULL); w->data = (void*)0xDEADBABE; @@ -385,7 +399,7 @@ static void uv__udp_destroy(uv_udp_t* handle) { req = ngx_queue_data(q, uv_udp_send_t, queue); if (req->send_cb) { /* FIXME proper error code like UV_EABORTED */ - uv_err_new_artificial((uv_handle_t*)handle, UV_EINTR); + uv_err_new_artificial(handle->loop, UV_EINTR); req->send_cb(req, -1); } } @@ -488,7 +502,7 @@ static void uv__udp_run_completed(uv_udp_t* handle) { req->send_cb(req, 0); } else { - uv_err_new((uv_handle_t*)handle, -req->status); + uv_err_new(handle->loop, -req->status); req->send_cb(req, -1); } } @@ -524,11 +538,11 @@ static void uv__udp_recvmsg(uv_udp_t* handle) { if (nread == -1) { if (errno == EAGAIN || errno == EWOULDBLOCK) { - uv_err_new((uv_handle_t*)handle, EAGAIN); + uv_err_new(handle->loop, EAGAIN); handle->recv_cb(handle, 0, buf, NULL, 0); } else { - uv_err_new((uv_handle_t*)handle, errno); + uv_err_new(handle->loop, errno); handle->recv_cb(handle, -1, buf, NULL, 0); } } @@ -564,7 +578,7 @@ static void uv__udp_sendmsg(uv_udp_t* handle) { if (!ngx_queue_empty(&handle->write_completed_queue)) { /* Schedule completion callbacks. */ - ev_feed_event(EV_DEFAULT_ &handle->write_watcher, EV_WRITE); + ev_feed_event(handle->loop->ev, &handle->write_watcher, EV_WRITE); } else if (ngx_queue_empty(&handle->write_queue)) { /* Pending queue and completion queue empty, stop watcher. */ @@ -605,24 +619,24 @@ static int uv__udp_bind(uv_udp_t* handle, /* Check for bad flags. */ if (flags & ~UV_UDP_IPV6ONLY) { - uv_err_new((uv_handle_t*)handle, EINVAL); + uv_err_new(handle->loop, EINVAL); goto out; } /* Cannot set IPv6-only mode on non-IPv6 socket. */ if ((flags & UV_UDP_IPV6ONLY) && domain != AF_INET6) { - uv_err_new((uv_handle_t*)handle, EINVAL); + uv_err_new(handle->loop, EINVAL); goto out; } /* Check for already active socket. */ if (handle->fd != -1) { - uv_err_new_artificial((uv_handle_t*)handle, UV_EALREADY); + uv_err_new_artificial(handle->loop, UV_EALREADY); goto out; } if ((fd = uv__socket(domain, SOCK_DGRAM, 0)) == -1) { - uv_err_new((uv_handle_t*)handle, errno); + uv_err_new(handle->loop, errno); goto out; } @@ -630,7 +644,7 @@ static int uv__udp_bind(uv_udp_t* handle, #ifdef IPV6_V6ONLY yes = 1; if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &yes, sizeof yes) == -1) { - uv_err_new((uv_handle_t*)handle, errno); + uv_err_new(handle->loop, errno); goto out; } #else @@ -640,7 +654,7 @@ static int uv__udp_bind(uv_udp_t* handle, } if (bind(fd, addr, len) == -1) { - uv_err_new((uv_handle_t*)handle, errno); + uv_err_new(handle->loop, errno); goto out; } @@ -704,7 +718,7 @@ static int uv__udp_send(uv_udp_send_t* req, return -1; /* Don't use uv__req_init(), it zeroes the data field. */ - uv_counters()->req_init++; + handle->loop->counters.req_init++; memcpy(&req->addr, addr, addrlen); req->addrlen = addrlen; @@ -717,7 +731,7 @@ static int uv__udp_send(uv_udp_send_t* req, req->bufs = req->bufsml; } else if ((req->bufs = malloc(bufcnt * sizeof(bufs[0]))) == NULL) { - uv_err_new((uv_handle_t*)handle, ENOMEM); + uv_err_new(handle->loop, ENOMEM); return -1; } memcpy(req->bufs, bufs, bufcnt * sizeof(bufs[0])); @@ -729,11 +743,11 @@ static int uv__udp_send(uv_udp_send_t* req, } -int uv_udp_init(uv_udp_t* handle) { +int uv_udp_init(uv_loop_t* loop, uv_udp_t* handle) { memset(handle, 0, sizeof *handle); - uv__handle_init((uv_handle_t*)handle, UV_UDP); - uv_counters()->udp_init++; + uv__handle_init(loop, (uv_handle_t*)handle, UV_UDP); + loop->counters.udp_init++; handle->fd = -1; ngx_queue_init(&handle->write_queue); @@ -797,12 +811,12 @@ 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_err_new_artificial((uv_handle_t*)handle, UV_EINVAL); + uv_err_new_artificial(handle->loop, UV_EINVAL); return -1; } if (ev_is_active(&handle->read_watcher)) { - uv_err_new_artificial((uv_handle_t*)handle, UV_EALREADY); + uv_err_new_artificial(handle->loop, UV_EALREADY); return -1; } @@ -825,9 +839,9 @@ int uv_udp_recv_stop(uv_udp_t* handle) { } -int uv_tcp_init(uv_tcp_t* tcp) { - uv__handle_init((uv_handle_t*)tcp, UV_TCP); - uv_counters()->tcp_init++; +int uv_tcp_init(uv_loop_t* loop, uv_tcp_t* tcp) { + uv__handle_init(loop, (uv_handle_t*)tcp, UV_TCP); + loop->counters.tcp_init++; tcp->alloc_cb = NULL; tcp->connect_req = NULL; @@ -864,7 +878,7 @@ static int uv__tcp_bind(uv_tcp_t* tcp, if (tcp->fd < 0) { if ((tcp->fd = uv__socket(domain, SOCK_STREAM, 0)) == -1) { - uv_err_new((uv_handle_t*)tcp, errno); + uv_err_new(tcp->loop, errno); goto out; } @@ -883,7 +897,7 @@ static int uv__tcp_bind(uv_tcp_t* tcp, if (errno == EADDRINUSE) { tcp->delayed_error = errno; } else { - uv_err_new((uv_handle_t*)tcp, errno); + uv_err_new(tcp->loop, errno); goto out; } } @@ -897,7 +911,7 @@ out: int uv_tcp_bind(uv_tcp_t* tcp, struct sockaddr_in addr) { if (addr.sin_family != AF_INET) { - uv_err_new((uv_handle_t*)tcp, EFAULT); + uv_err_new(tcp->loop, EFAULT); return -1; } @@ -910,7 +924,7 @@ int uv_tcp_bind(uv_tcp_t* tcp, struct sockaddr_in addr) { int uv_tcp_bind6(uv_tcp_t* tcp, struct sockaddr_in6 addr) { if (addr.sin6_family != AF_INET6) { - uv_err_new((uv_handle_t*)tcp, EFAULT); + uv_err_new(tcp->loop, EFAULT); return -1; } @@ -933,7 +947,7 @@ static int uv__stream_open(uv_stream_t* stream, int fd, int flags) { yes = 1; if (stream->type == UV_TCP && setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) { - uv_err_new((uv_handle_t*)stream, errno); + uv_err_new(stream->loop, errno); return -1; } @@ -961,7 +975,7 @@ void uv__server_io(EV_P_ ev_io* watcher, int revents) { assert(!(stream->flags & UV_CLOSING)); if (stream->accepted_fd >= 0) { - ev_io_stop(EV_DEFAULT_ &stream->read_watcher); + ev_io_stop(EV_A, &stream->read_watcher); return; } @@ -980,7 +994,7 @@ void uv__server_io(EV_P_ ev_io* watcher, int revents) { /* TODO special trick. unlock reserved socket, accept, close. */ return; } else { - uv_err_new((uv_handle_t*)stream, errno); + uv_err_new(stream->loop, errno); stream->connection_cb((uv_stream_t*)stream, -1); } } else { @@ -988,7 +1002,7 @@ void uv__server_io(EV_P_ ev_io* watcher, int revents) { stream->connection_cb((uv_stream_t*)stream, 0); if (stream->accepted_fd >= 0) { /* The user hasn't yet accepted called uv_accept() */ - ev_io_stop(EV_DEFAULT_ &stream->read_watcher); + ev_io_stop(stream->loop->ev, &stream->read_watcher); return; } } @@ -1002,6 +1016,9 @@ int uv_accept(uv_stream_t* server, uv_stream_t* client) { int saved_errno; int status; + /* TODO document this */ + assert(server->loop == client->loop); + saved_errno = errno; status = -1; @@ -1009,7 +1026,7 @@ int uv_accept(uv_stream_t* server, uv_stream_t* client) { streamClient = (uv_stream_t*)client; if (streamServer->accepted_fd < 0) { - uv_err_new((uv_handle_t*)server, EAGAIN); + uv_err_new(server->loop, EAGAIN); goto out; } @@ -1021,7 +1038,7 @@ int uv_accept(uv_stream_t* server, uv_stream_t* client) { goto out; } - ev_io_start(EV_DEFAULT_ &streamServer->read_watcher); + ev_io_start(streamServer->loop->ev, &streamServer->read_watcher); streamServer->accepted_fd = -1; status = 0; @@ -1048,13 +1065,13 @@ static int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) { int r; if (tcp->delayed_error) { - uv_err_new((uv_handle_t*)tcp, tcp->delayed_error); + uv_err_new(tcp->loop, tcp->delayed_error); return -1; } if (tcp->fd < 0) { if ((tcp->fd = uv__socket(AF_INET, SOCK_STREAM, 0)) == -1) { - uv_err_new((uv_handle_t*)tcp, errno); + uv_err_new(tcp->loop, errno); return -1; } @@ -1069,7 +1086,7 @@ static int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) { r = listen(tcp->fd, backlog); if (r < 0) { - uv_err_new((uv_handle_t*)tcp, errno); + uv_err_new(tcp->loop, errno); return -1; } @@ -1078,13 +1095,15 @@ static int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) { /* Start listening for connections. */ ev_io_set(&tcp->read_watcher, tcp->fd, EV_READ); ev_set_cb(&tcp->read_watcher, uv__server_io); - ev_io_start(EV_DEFAULT_ &tcp->read_watcher); + ev_io_start(tcp->loop->ev, &tcp->read_watcher); return 0; } void uv__finish_close(uv_handle_t* handle) { + uv_loop_t* loop = handle->loop; + assert(handle->flags & UV_CLOSING); assert(!(handle->flags & UV_CLOSED)); handle->flags |= UV_CLOSED; @@ -1132,13 +1151,13 @@ void uv__finish_close(uv_handle_t* handle) { break; } - ev_idle_stop(EV_DEFAULT_ &handle->next_watcher); + ev_idle_stop(loop->ev, &handle->next_watcher); if (handle->close_cb) { handle->close_cb(handle); } - ev_unref(EV_DEFAULT_UC); + ev_unref(loop->ev); } @@ -1181,7 +1200,7 @@ static void uv__drain(uv_stream_t* stream) { assert(!uv_write_queue_head(stream)); assert(stream->write_queue_size == 0); - ev_io_stop(EV_DEFAULT_ &stream->write_watcher); + ev_io_stop(stream->loop->ev, &stream->write_watcher); /* Shutdown? */ if ((stream->flags & UV_SHUTTING) && @@ -1193,12 +1212,12 @@ static void uv__drain(uv_stream_t* stream) { if (shutdown(stream->fd, SHUT_WR)) { /* Error. Report it. User should call uv_close(). */ - uv_err_new((uv_handle_t*)stream, errno); + uv_err_new(stream->loop, errno); if (req->cb) { req->cb(req, -1); } } else { - uv_err_new((uv_handle_t*)stream, 0); + uv_err_new(stream->loop, 0); ((uv_handle_t*) stream)->flags |= UV_SHUT; if (req->cb) { req->cb(req, 0); @@ -1253,7 +1272,7 @@ static uv_write_t* uv__write(uv_stream_t* stream) { if (n < 0) { if (errno != EAGAIN) { /* Error */ - uv_err_new((uv_handle_t*)stream, errno); + uv_err_new(stream->loop, errno); return req; } } else { @@ -1301,7 +1320,7 @@ static uv_write_t* uv__write(uv_stream_t* stream) { * TODO: start trying to write the next request. */ ngx_queue_insert_tail(&stream->write_completed_queue, &req->queue); - ev_feed_event(EV_DEFAULT_ &stream->write_watcher, EV_WRITE); + ev_feed_event(stream->loop->ev, &stream->write_watcher, EV_WRITE); return NULL; } } @@ -1312,7 +1331,7 @@ static uv_write_t* uv__write(uv_stream_t* stream) { assert(n == 0 || n == -1); /* We're not done. */ - ev_io_start(EV_DEFAULT_ &stream->write_watcher); + ev_io_start(stream->loop->ev, &stream->write_watcher); return NULL; } @@ -1350,6 +1369,7 @@ static void uv__write_callbacks(uv_stream_t* stream) { static void uv__read(uv_stream_t* stream) { uv_buf_t buf; ssize_t nread; + struct ev_loop* ev = stream->loop->ev; /* XXX: Maybe instead of having UV_READING we just test if * tcp->read_cb is NULL or not? @@ -1372,22 +1392,22 @@ static void uv__read(uv_stream_t* stream) { if (errno == EAGAIN) { /* Wait for the next one. */ if (stream->flags & UV_READING) { - ev_io_start(EV_DEFAULT_UC_ &stream->read_watcher); + ev_io_start(ev, &stream->read_watcher); } - uv_err_new((uv_handle_t*)stream, EAGAIN); + uv_err_new(stream->loop, EAGAIN); stream->read_cb(stream, 0, buf); return; } else { /* Error. User should call uv_close(). */ - uv_err_new((uv_handle_t*)stream, errno); + uv_err_new(stream->loop, errno); stream->read_cb(stream, -1, buf); assert(!ev_is_active(&stream->read_watcher)); return; } } else if (nread == 0) { /* EOF */ - uv_err_new_artificial((uv_handle_t*)stream, UV_EOF); - ev_io_stop(EV_DEFAULT_UC_ &stream->read_watcher); + uv_err_new_artificial(stream->loop, UV_EOF); + ev_io_stop(ev, &stream->read_watcher); stream->read_cb(stream, -1, buf); return; } else { @@ -1407,7 +1427,7 @@ int uv_shutdown(uv_shutdown_t* req, uv_stream_t* stream, uv_shutdown_cb cb) { stream->flags & UV_SHUT || stream->flags & UV_CLOSED || stream->flags & UV_CLOSING) { - uv_err_new((uv_handle_t*)stream, EINVAL); + uv_err_new(stream->loop, EINVAL); return -1; } @@ -1422,7 +1442,7 @@ int uv_shutdown(uv_shutdown_t* req, uv_stream_t* stream, uv_shutdown_cb cb) { ((uv_handle_t*)stream)->flags |= UV_SHUTTING; - ev_io_start(EV_DEFAULT_UC_ &stream->write_watcher); + ev_io_start(stream->loop->ev, &stream->write_watcher); return 0; } @@ -1489,7 +1509,7 @@ static void uv__stream_connect(uv_stream_t* stream) { } if (!error) { - ev_io_start(EV_DEFAULT_ &stream->read_watcher); + ev_io_start(stream->loop->ev, &stream->read_watcher); /* Successful connection */ stream->connect_req = NULL; @@ -1502,7 +1522,7 @@ static void uv__stream_connect(uv_stream_t* stream) { return; } else { /* Error */ - uv_err_new((uv_handle_t*)stream, error); + uv_err_new(stream->loop, error); stream->connect_req = NULL; if (req->cb) { @@ -1523,7 +1543,7 @@ static int uv__connect(uv_connect_t* req, if (stream->fd <= 0) { if ((sockfd = uv__socket(addr->sa_family, SOCK_STREAM, 0)) == -1) { - uv_err_new((uv_handle_t*)stream, errno); + uv_err_new(stream->loop, errno); return -1; } @@ -1540,12 +1560,12 @@ static int uv__connect(uv_connect_t* req, ngx_queue_init(&req->queue); if (stream->connect_req) { - uv_err_new((uv_handle_t*)stream, EALREADY); + uv_err_new(stream->loop, EALREADY); return -1; } if (stream->type != UV_TCP) { - uv_err_new((uv_handle_t*)stream, ENOTSOCK); + uv_err_new(stream->loop, ENOTSOCK); return -1; } @@ -1569,16 +1589,16 @@ static int uv__connect(uv_connect_t* req, break; default: - uv_err_new((uv_handle_t*)stream, errno); + uv_err_new(stream->loop, errno); return -1; } } assert(stream->write_watcher.data == stream); - ev_io_start(EV_DEFAULT_ &stream->write_watcher); + ev_io_start(stream->loop->ev, &stream->write_watcher); if (stream->delayed_error) { - ev_feed_event(EV_DEFAULT_ &stream->write_watcher, EV_WRITE); + ev_feed_event(stream->loop->ev, &stream->write_watcher, EV_WRITE); } return 0; @@ -1596,12 +1616,12 @@ int uv_tcp_connect(uv_connect_t* req, status = -1; if (handle->type != UV_TCP) { - uv_err_new((uv_handle_t*)handle, EINVAL); + uv_err_new(handle->loop, EINVAL); goto out; } if (address.sin_family != AF_INET) { - uv_err_new((uv_handle_t*)handle, EINVAL); + uv_err_new(handle->loop, EINVAL); goto out; } @@ -1628,12 +1648,12 @@ int uv_tcp_connect6(uv_connect_t* req, status = -1; if (handle->type != UV_TCP) { - uv_err_new((uv_handle_t*)handle, EINVAL); + uv_err_new(handle->loop, EINVAL); goto out; } if (address.sin6_family != AF_INET6) { - uv_err_new((uv_handle_t*)handle, EINVAL); + uv_err_new(handle->loop, EINVAL); goto out; } @@ -1660,7 +1680,7 @@ int uv_getsockname(uv_handle_t* handle, struct sockaddr* name, int* namelen) { socklen = (socklen_t)*namelen; if (getsockname(handle->fd, name, &socklen) == -1) { - uv_err_new((uv_handle_t*)handle, errno); + uv_err_new(handle->loop, errno); } else { *namelen = (int)socklen; } @@ -1704,7 +1724,7 @@ int uv_write(uv_write_t* req, uv_stream_t* handle, uv_buf_t bufs[], int bufcnt, empty_queue = (stream->write_queue_size == 0); if (stream->fd < 0) { - uv_err_new((uv_handle_t*)stream, EBADF); + uv_err_new(stream->loop, EBADF); return -1; } @@ -1753,35 +1773,35 @@ int uv_write(uv_write_t* req, uv_stream_t* handle, uv_buf_t bufs[], int bufcnt, * fresh stack so we feed the event loop in order to service it. */ if (ngx_queue_empty(&stream->write_queue)) { - ev_feed_event(EV_DEFAULT_ &stream->write_watcher, EV_WRITE); + ev_feed_event(stream->loop->ev, &stream->write_watcher, EV_WRITE); } else { /* Otherwise there is data to write - so we should wait for the file * descriptor to become writable. */ - ev_io_start(EV_DEFAULT_ &stream->write_watcher); + ev_io_start(stream->loop->ev, &stream->write_watcher); } return 0; } -void uv_ref() { - ev_ref(EV_DEFAULT_UC); +void uv_ref(uv_loop_t* loop) { + ev_ref(loop->ev); } -void uv_unref() { - ev_unref(EV_DEFAULT_UC); +void uv_unref(uv_loop_t* loop) { + ev_unref(loop->ev); } -void uv_update_time() { - ev_now_update(EV_DEFAULT_UC); +void uv_update_time(uv_loop_t* loop) { + ev_now_update(loop->ev); } -int64_t uv_now() { - return (int64_t)(ev_now(EV_DEFAULT_UC) * 1000); +int64_t uv_now(uv_loop_t* loop) { + return (int64_t)(ev_now(loop->ev) * 1000); } @@ -1789,7 +1809,7 @@ int uv_read_start(uv_stream_t* stream, uv_alloc_cb alloc_cb, uv_read_cb read_cb) assert(stream->type == UV_TCP || stream->type == UV_NAMED_PIPE); if (stream->flags & UV_CLOSING) { - uv_err_new((uv_handle_t*)stream, EINVAL); + uv_err_new(stream->loop, EINVAL); return -1; } @@ -1811,7 +1831,7 @@ int uv_read_start(uv_stream_t* stream, uv_alloc_cb alloc_cb, uv_read_cb read_cb) /* These should have been set by uv_tcp_init. */ assert(stream->read_watcher.cb == uv__stream_io); - ev_io_start(EV_DEFAULT_UC_ &stream->read_watcher); + ev_io_start(stream->loop->ev, &stream->read_watcher); return 0; } @@ -1821,7 +1841,7 @@ int uv_read_stop(uv_stream_t* stream) { ((uv_handle_t*)tcp)->flags &= ~UV_READING; - ev_io_stop(EV_DEFAULT_UC_ &tcp->read_watcher); + ev_io_stop(tcp->loop->ev, &tcp->read_watcher); tcp->read_cb = NULL; tcp->alloc_cb = NULL; return 0; @@ -1829,7 +1849,7 @@ int uv_read_stop(uv_stream_t* stream) { void uv__req_init(uv_req_t* req) { - uv_counters()->req_init++; + /* loop->counters.req_init++; */ req->type = UV_UNKNOWN_REQ; req->data = NULL; } @@ -1844,9 +1864,9 @@ static void uv__prepare(EV_P_ ev_prepare* w, int revents) { } -int uv_prepare_init(uv_prepare_t* prepare) { - uv__handle_init((uv_handle_t*)prepare, UV_PREPARE); - uv_counters()->prepare_init++; +int uv_prepare_init(uv_loop_t* loop, uv_prepare_t* prepare) { + uv__handle_init(loop, (uv_handle_t*)prepare, UV_PREPARE); + loop->counters.prepare_init++; ev_prepare_init(&prepare->prepare_watcher, uv__prepare); prepare->prepare_watcher.data = prepare; @@ -1862,10 +1882,10 @@ int uv_prepare_start(uv_prepare_t* prepare, uv_prepare_cb cb) { prepare->prepare_cb = cb; - ev_prepare_start(EV_DEFAULT_UC_ &prepare->prepare_watcher); + ev_prepare_start(prepare->loop->ev, &prepare->prepare_watcher); if (!was_active) { - ev_unref(EV_DEFAULT_UC); + ev_unref(prepare->loop->ev); } return 0; @@ -1875,10 +1895,10 @@ int uv_prepare_start(uv_prepare_t* prepare, uv_prepare_cb cb) { int uv_prepare_stop(uv_prepare_t* prepare) { int was_active = ev_is_active(&prepare->prepare_watcher); - ev_prepare_stop(EV_DEFAULT_UC_ &prepare->prepare_watcher); + ev_prepare_stop(prepare->loop->ev, &prepare->prepare_watcher); if (was_active) { - ev_ref(EV_DEFAULT_UC); + ev_ref(prepare->loop->ev); } return 0; } @@ -1894,9 +1914,9 @@ static void uv__check(EV_P_ ev_check* w, int revents) { } -int uv_check_init(uv_check_t* check) { - uv__handle_init((uv_handle_t*)check, UV_CHECK); - uv_counters()->check_init++; +int uv_check_init(uv_loop_t* loop, uv_check_t* check) { + uv__handle_init(loop, (uv_handle_t*)check, UV_CHECK); + loop->counters.check_init++; ev_check_init(&check->check_watcher, uv__check); check->check_watcher.data = check; @@ -1912,10 +1932,10 @@ int uv_check_start(uv_check_t* check, uv_check_cb cb) { check->check_cb = cb; - ev_check_start(EV_DEFAULT_UC_ &check->check_watcher); + ev_check_start(check->loop->ev, &check->check_watcher); if (!was_active) { - ev_unref(EV_DEFAULT_UC); + ev_unref(check->loop->ev); } return 0; @@ -1925,10 +1945,10 @@ int uv_check_start(uv_check_t* check, uv_check_cb cb) { int uv_check_stop(uv_check_t* check) { int was_active = ev_is_active(&check->check_watcher); - ev_check_stop(EV_DEFAULT_UC_ &check->check_watcher); + ev_check_stop(check->loop->ev, &check->check_watcher); if (was_active) { - ev_ref(EV_DEFAULT_UC); + ev_ref(check->loop->ev); } return 0; @@ -1945,9 +1965,9 @@ static void uv__idle(EV_P_ ev_idle* w, int revents) { -int uv_idle_init(uv_idle_t* idle) { - uv__handle_init((uv_handle_t*)idle, UV_IDLE); - uv_counters()->idle_init++; +int uv_idle_init(uv_loop_t* loop, uv_idle_t* idle) { + uv__handle_init(loop, (uv_handle_t*)idle, UV_IDLE); + loop->counters.idle_init++; ev_idle_init(&idle->idle_watcher, uv__idle); idle->idle_watcher.data = idle; @@ -1962,10 +1982,10 @@ int uv_idle_start(uv_idle_t* idle, uv_idle_cb cb) { int was_active = ev_is_active(&idle->idle_watcher); idle->idle_cb = cb; - ev_idle_start(EV_DEFAULT_UC_ &idle->idle_watcher); + ev_idle_start(idle->loop->ev, &idle->idle_watcher); if (!was_active) { - ev_unref(EV_DEFAULT_UC); + ev_unref(idle->loop->ev); } return 0; @@ -1975,10 +1995,10 @@ int uv_idle_start(uv_idle_t* idle, uv_idle_cb cb) { int uv_idle_stop(uv_idle_t* idle) { int was_active = ev_is_active(&idle->idle_watcher); - ev_idle_stop(EV_DEFAULT_UC_ &idle->idle_watcher); + ev_idle_stop(idle->loop->ev, &idle->idle_watcher); if (was_active) { - ev_ref(EV_DEFAULT_UC); + ev_ref(idle->loop->ev); } return 0; @@ -2014,9 +2034,9 @@ static void uv__async(EV_P_ ev_async* w, int revents) { } -int uv_async_init(uv_async_t* async, uv_async_cb async_cb) { - uv__handle_init((uv_handle_t*)async, UV_ASYNC); - uv_counters()->async_init++; +int uv_async_init(uv_loop_t* loop, uv_async_t* async, uv_async_cb async_cb) { + uv__handle_init(loop, (uv_handle_t*)async, UV_ASYNC); + loop->counters.async_init++; ev_async_init(&async->async_watcher, uv__async); async->async_watcher.data = async; @@ -2024,15 +2044,15 @@ int uv_async_init(uv_async_t* async, uv_async_cb async_cb) { async->async_cb = async_cb; /* Note: This does not have symmetry with the other libev wrappers. */ - ev_async_start(EV_DEFAULT_UC_ &async->async_watcher); - ev_unref(EV_DEFAULT_UC); + ev_async_start(loop->ev, &async->async_watcher); + ev_unref(loop->ev); return 0; } int uv_async_send(uv_async_t* async) { - ev_async_send(EV_DEFAULT_UC_ &async->async_watcher); + ev_async_send(async->loop->ev, &async->async_watcher); return 0; } @@ -2041,7 +2061,7 @@ static void uv__timer_cb(EV_P_ ev_timer* w, int revents) { uv_timer_t* timer = w->data; if (!ev_is_active(w)) { - ev_ref(EV_DEFAULT_UC); + ev_ref(EV_A); } if (timer->timer_cb) { @@ -2050,9 +2070,9 @@ static void uv__timer_cb(EV_P_ ev_timer* w, int revents) { } -int uv_timer_init(uv_timer_t* timer) { - uv__handle_init((uv_handle_t*)timer, UV_TIMER); - uv_counters()->timer_init++; +int uv_timer_init(uv_loop_t* loop, uv_timer_t* timer) { + uv__handle_init(loop, (uv_handle_t*)timer, UV_TIMER); + loop->counters.timer_init++; ev_init(&timer->timer_watcher, uv__timer_cb); timer->timer_watcher.data = timer; @@ -2069,29 +2089,29 @@ int uv_timer_start(uv_timer_t* timer, uv_timer_cb cb, int64_t timeout, timer->timer_cb = cb; ev_timer_set(&timer->timer_watcher, timeout / 1000.0, repeat / 1000.0); - ev_timer_start(EV_DEFAULT_UC_ &timer->timer_watcher); - ev_unref(EV_DEFAULT_UC); + ev_timer_start(timer->loop->ev, &timer->timer_watcher); + ev_unref(timer->loop->ev); return 0; } int uv_timer_stop(uv_timer_t* timer) { if (ev_is_active(&timer->timer_watcher)) { - ev_ref(EV_DEFAULT_UC); + ev_ref(timer->loop->ev); } - ev_timer_stop(EV_DEFAULT_UC_ &timer->timer_watcher); + ev_timer_stop(timer->loop->ev, &timer->timer_watcher); return 0; } int uv_timer_again(uv_timer_t* timer) { if (!ev_is_active(&timer->timer_watcher)) { - uv_err_new((uv_handle_t*)timer, EINVAL); + uv_err_new(timer->loop, EINVAL); return -1; } - ev_timer_again(EV_DEFAULT_UC_ &timer->timer_watcher); + ev_timer_again(timer->loop->ev, &timer->timer_watcher); return 0; } @@ -2107,23 +2127,28 @@ int64_t uv_timer_get_repeat(uv_timer_t* timer) { /* - * This is called once per second by ares_data.timer. It is used to + * This is called once per second by loop->timer. It is used to * constantly callback into c-ares for possibly processing timeouts. */ -static void uv__ares_timeout(EV_P_ struct ev_timer* watcher, int revents) { - assert(watcher == &ares_data.timer); +static void uv__ares_timeout(struct ev_loop* ev, struct ev_timer* watcher, + int revents) { + uv_loop_t* loop = container_of(ev, uv_loop_t, ev); + assert(watcher == &loop->timer); assert(revents == EV_TIMER); - assert(!uv_ares_handles_empty()); - ares_process_fd(ares_data.channel, ARES_SOCKET_BAD, ARES_SOCKET_BAD); + assert(!uv_ares_handles_empty(loop)); + ares_process_fd(loop->channel, ARES_SOCKET_BAD, ARES_SOCKET_BAD); } -static void uv__ares_io(EV_P_ struct ev_io* watcher, int revents) { +static void uv__ares_io(struct ev_loop* ev, struct ev_io* watcher, + int revents) { + uv_loop_t* loop = container_of(ev, uv_loop_t, ev); + /* Reset the idle timer */ - ev_timer_again(EV_A_ &ares_data.timer); + ev_timer_again(ev, &loop->timer); /* Process DNS responses */ - ares_process_fd(ares_data.channel, + ares_process_fd(loop->channel, revents & EV_READ ? watcher->fd : ARES_SOCKET_BAD, revents & EV_WRITE ? watcher->fd : ARES_SOCKET_BAD); } @@ -2152,32 +2177,35 @@ static uv_ares_task_t* uv__ares_task_create(int fd) { /* Callback from ares when socket operation is started */ static void uv__ares_sockstate_cb(void* data, ares_socket_t sock, int read, int write) { - uv_ares_task_t* h = uv_find_ares_handle(sock); + uv_loop_t* loop = data; + uv_ares_task_t* h; + + h = uv_find_ares_handle(loop, sock); if (read || write) { if (!h) { /* New socket */ /* If this is the first socket then start the timer. */ - if (!ev_is_active(&ares_data.timer)) { - assert(uv_ares_handles_empty()); - ev_timer_again(EV_DEFAULT_UC_ &ares_data.timer); + if (!ev_is_active(&loop->timer)) { + assert(uv_ares_handles_empty(loop)); + ev_timer_again(loop->ev, &loop->timer); } h = uv__ares_task_create(sock); - uv_add_ares_handle(h); + uv_add_ares_handle(loop, h); } if (read) { - ev_io_start(EV_DEFAULT_UC_ &h->read_watcher); + ev_io_start(loop->ev, &h->read_watcher); } else { - ev_io_stop(EV_DEFAULT_UC_ &h->read_watcher); + ev_io_stop(loop->ev, &h->read_watcher); } if (write) { - ev_io_start(EV_DEFAULT_UC_ &h->write_watcher); + ev_io_start(loop->ev, &h->write_watcher); } else { - ev_io_stop(EV_DEFAULT_UC_ &h->write_watcher); + ev_io_stop(loop->ev, &h->write_watcher); } } else { @@ -2188,14 +2216,14 @@ static void uv__ares_sockstate_cb(void* data, ares_socket_t sock, */ assert(h && "When an ares socket is closed we should have a handle for it"); - ev_io_stop(EV_DEFAULT_UC_ &h->read_watcher); - ev_io_stop(EV_DEFAULT_UC_ &h->write_watcher); + ev_io_stop(loop->ev, &h->read_watcher); + ev_io_stop(loop->ev, &h->write_watcher); uv_remove_ares_handle(h); free(h); - if (uv_ares_handles_empty()) { - ev_timer_stop(EV_DEFAULT_UC_ &ares_data.timer); + if (uv_ares_handles_empty(loop)) { + ev_timer_stop(loop->ev, &loop->timer); } } } @@ -2203,20 +2231,19 @@ static void uv__ares_sockstate_cb(void* data, ares_socket_t sock, /* c-ares integration initialize and terminate */ /* TODO: share this with windows? */ -int uv_ares_init_options(ares_channel *channelptr, - struct ares_options *options, - int optmask) { +int uv_ares_init_options(uv_loop_t* loop, ares_channel *channelptr, + struct ares_options *options, int optmask) { int rc; /* only allow single init at a time */ - if (ares_data.channel != NULL) { - uv_err_new_artificial(NULL, UV_EALREADY); + if (loop->channel != NULL) { + uv_err_new_artificial(loop, UV_EALREADY); return -1; } /* set our callback as an option */ options->sock_state_cb = uv__ares_sockstate_cb; - options->sock_state_cb_data = &ares_data; + options->sock_state_cb_data = loop; optmask |= ARES_OPT_SOCK_STATE_CB; /* We do the call to ares_init_option for caller. */ @@ -2224,27 +2251,27 @@ int uv_ares_init_options(ares_channel *channelptr, /* if success, save channel */ if (rc == ARES_SUCCESS) { - ares_data.channel = *channelptr; + loop->channel = *channelptr; } /* * Initialize the timeout timer. The timer won't be started until the * first socket is opened. */ - ev_init(&ares_data.timer, uv__ares_timeout); - ares_data.timer.repeat = 1.0; + ev_init(&loop->timer, uv__ares_timeout); + loop->timer.repeat = 1.0; return rc; } /* TODO share this with windows? */ -void uv_ares_destroy(ares_channel channel) { +void uv_ares_destroy(uv_loop_t* loop, ares_channel channel) { /* only allow destroy if did init */ - if (ares_data.channel != NULL) { - ev_timer_stop(EV_DEFAULT_UC_ &ares_data.timer); + if (loop->channel != NULL) { + ev_timer_stop(loop->ev, &loop->timer); ares_destroy(channel); - ares_data.channel = NULL; + loop->channel = NULL; } } @@ -2252,7 +2279,7 @@ void uv_ares_destroy(ares_channel channel) { static int uv_getaddrinfo_done(eio_req* req) { uv_getaddrinfo_t* handle = req->data; - uv_unref(); + uv_unref(handle->loop); free(handle->hints); free(handle->service); @@ -2260,7 +2287,7 @@ static int uv_getaddrinfo_done(eio_req* req) { if (handle->retcode != 0) { /* TODO how to display gai error strings? */ - uv_err_new(NULL, handle->retcode); + uv_err_new(handle->loop, handle->retcode); } handle->cb(handle, handle->retcode, handle->res); @@ -2283,17 +2310,18 @@ static void getaddrinfo_thread_proc(eio_req *req) { /* stub implementation of uv_getaddrinfo */ -int uv_getaddrinfo(uv_getaddrinfo_t* handle, +int uv_getaddrinfo(uv_loop_t* loop, + uv_getaddrinfo_t* handle, uv_getaddrinfo_cb cb, const char* hostname, const char* service, const struct addrinfo* hints) { eio_req* req; - uv_eio_init(); + uv_eio_init(loop); if (handle == NULL || cb == NULL || (hostname == NULL && service == NULL)) { - uv_err_new_artificial(NULL, UV_EINVAL); + uv_err_new_artificial(loop, UV_EINVAL); return -1; } @@ -2308,6 +2336,7 @@ int uv_getaddrinfo(uv_getaddrinfo_t* handle, /* TODO security! check lengths, check return values. */ + handle->loop = loop; handle->cb = cb; handle->hostname = hostname ? strdup(hostname) : NULL; handle->service = service ? strdup(service) : NULL; @@ -2315,7 +2344,7 @@ int uv_getaddrinfo(uv_getaddrinfo_t* handle, /* TODO check handle->hostname == NULL */ /* TODO check handle->service == NULL */ - uv_ref(); + uv_ref(loop); req = eio_custom(getaddrinfo_thread_proc, EIO_PRI_DEFAULT, uv_getaddrinfo_done, handle); @@ -2326,11 +2355,11 @@ int uv_getaddrinfo(uv_getaddrinfo_t* handle, } -int uv_pipe_init(uv_pipe_t* handle) { +int uv_pipe_init(uv_loop_t* loop, uv_pipe_t* handle) { memset(handle, 0, sizeof *handle); - uv__handle_init((uv_handle_t*)handle, UV_NAMED_PIPE); - uv_counters()->pipe_init++; + uv__handle_init(loop, (uv_handle_t*)handle, UV_NAMED_PIPE); + loop->counters.pipe_init++; handle->type = UV_NAMED_PIPE; handle->pipe_fname = NULL; /* Only set by listener. */ @@ -2365,13 +2394,13 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) { /* Already bound? */ if (handle->fd >= 0) { - uv_err_new_artificial((uv_handle_t*)handle, UV_EINVAL); + uv_err_new_artificial(handle->loop, UV_EINVAL); goto out; } /* Make a copy of the file name, it outlives this function's scope. */ if ((pipe_fname = strdup(name)) == NULL) { - uv_err_new((uv_handle_t*)handle, ENOMEM); + uv_err_new(handle->loop, ENOMEM); goto out; } @@ -2379,7 +2408,7 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) { name = NULL; if ((sockfd = uv__socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { - uv_err_new((uv_handle_t*)handle, errno); + uv_err_new(handle->loop, errno); goto out; } @@ -2400,7 +2429,7 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) { || unlink(pipe_fname) == -1 || bind(sockfd, (struct sockaddr*)&sun, sizeof sun) == -1) { /* Convert ENOENT to EACCES for compatibility with Windows. */ - uv_err_new((uv_handle_t*)handle, (errno == ENOENT) ? EACCES : errno); + uv_err_new(handle->loop, (errno == ENOENT) ? EACCES : errno); goto out; } } @@ -2437,17 +2466,17 @@ static int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) { status = -1; if (handle->fd == -1) { - uv_err_new_artificial((uv_handle_t*)handle, UV_EINVAL); + uv_err_new_artificial(handle->loop, UV_EINVAL); goto out; } assert(handle->fd >= 0); if ((status = listen(handle->fd, backlog)) == -1) { - uv_err_new((uv_handle_t*)handle, errno); + uv_err_new(handle->loop, errno); } else { handle->connection_cb = cb; ev_io_init(&handle->read_watcher, uv__pipe_accept, handle->fd, EV_READ); - ev_io_start(EV_DEFAULT_ &handle->read_watcher); + ev_io_start(handle->loop->ev, &handle->read_watcher); } out: @@ -2497,7 +2526,7 @@ int uv_pipe_connect(uv_connect_t* req, status = -1; if ((sockfd = uv__socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { - uv_err_new((uv_handle_t*)handle, errno); + uv_err_new(handle->loop, errno); goto out; } @@ -2514,15 +2543,15 @@ int uv_pipe_connect(uv_connect_t* req, while (r == -1 && errno == EINTR); if (r == -1) { - uv_err_new((uv_handle_t*)handle, errno); + uv_err_new(handle->loop, errno); uv__close(sockfd); goto out; } uv__stream_open((uv_stream_t*)handle, sockfd, UV_READABLE | UV_WRITABLE); - ev_io_start(EV_DEFAULT_ &handle->read_watcher); - ev_io_start(EV_DEFAULT_ &handle->write_watcher); + ev_io_start(handle->loop->ev, &handle->read_watcher); + ev_io_start(handle->loop->ev, &handle->write_watcher); status = 0; @@ -2535,7 +2564,7 @@ out: ngx_queue_init(&req->queue); /* Run callback on next tick. */ - ev_feed_event(EV_DEFAULT_ &handle->read_watcher, EV_CUSTOM); + ev_feed_event(handle->loop->ev, &handle->read_watcher, EV_CUSTOM); assert(ev_is_pending(&handle->read_watcher)); /* Mimic the Windows pipe implementation, always @@ -2564,14 +2593,14 @@ static void uv__pipe_accept(EV_P_ ev_io* watcher, int revents) { if (errno == EAGAIN || errno == EWOULDBLOCK) { assert(0 && "EAGAIN on uv__accept(pipefd)"); } else { - uv_err_new((uv_handle_t*)pipe, errno); + uv_err_new(pipe->loop, errno); } } else { pipe->accepted_fd = sockfd; pipe->connection_cb((uv_stream_t*)pipe, 0); if (pipe->accepted_fd == sockfd) { /* The user hasn't yet accepted called uv_accept() */ - ev_io_stop(EV_DEFAULT_ &pipe->read_watcher); + ev_io_stop(pipe->loop->ev, &pipe->read_watcher); } } @@ -2702,7 +2731,7 @@ size_t uv__strlcpy(char* dst, const char* src, size_t size) { } -uv_stream_t* uv_std_handle(uv_std_type type) { +uv_stream_t* uv_std_handle(uv_loop_t* loop, uv_std_type type) { assert(0 && "implement me"); return NULL; } @@ -2736,7 +2765,8 @@ static void uv__chld(EV_P_ ev_child* watcher, int revents) { # define SPAWN_WAIT_EXEC 1 #endif -int uv_spawn(uv_process_t* process, uv_process_options_t options) { +int uv_spawn(uv_loop_t* loop, uv_process_t* process, + uv_process_options_t options) { /* * Save environ in the case that we get it clobbered * by the child process. @@ -2752,8 +2782,8 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) { int status; pid_t pid; - uv__handle_init((uv_handle_t*)process, UV_PROCESS); - uv_counters()->process_init++; + uv__handle_init(loop, (uv_handle_t*)process, UV_PROCESS); + loop->counters.process_init++; process->exit_cb = options.exit_cb; @@ -2900,7 +2930,7 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) { process->pid = pid; ev_child_init(&process->child_watcher, uv__chld, pid, 0); - ev_child_start(EV_DEFAULT_UC_ &process->child_watcher); + ev_child_start(process->loop->ev, &process->child_watcher); process->child_watcher.data = process; if (stdin_pipe[1] >= 0) { @@ -2933,7 +2963,7 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) { return 0; error: - uv_err_new((uv_handle_t*)process, errno); + uv_err_new(process->loop, errno); uv__close(stdin_pipe[0]); uv__close(stdin_pipe[1]); uv__close(stdout_pipe[0]); @@ -2948,7 +2978,7 @@ int uv_process_kill(uv_process_t* process, int signum) { int r = kill(process->pid, signum); if (r) { - uv_err_new((uv_handle_t*)process, errno); + uv_err_new(process->loop, errno); return -1; } else { return 0; diff --git a/deps/uv/src/win/async.c b/deps/uv/src/win/async.c index 1a6fb0880..ee5faea27 100644 --- a/deps/uv/src/win/async.c +++ b/deps/uv/src/win/async.c @@ -54,7 +54,7 @@ static inline char uv_atomic_exchange_set(char volatile* target) { #endif -void uv_async_endgame(uv_async_t* handle) { +void uv_async_endgame(uv_loop_t* loop, uv_async_t* handle) { if (handle->flags & UV_HANDLE_CLOSING && !handle->async_sent) { assert(!(handle->flags & UV_HANDLE_CLOSED)); @@ -64,34 +64,37 @@ void uv_async_endgame(uv_async_t* handle) { handle->close_cb((uv_handle_t*)handle); } - uv_unref(); + uv_unref(loop); } } -int uv_async_init(uv_async_t* handle, uv_async_cb async_cb) { +int uv_async_init(uv_loop_t* loop, uv_async_t* handle, uv_async_cb async_cb) { uv_req_t* req; - uv_counters()->handle_init++; - uv_counters()->async_init++; + loop->counters.handle_init++; + loop->counters.async_init++; handle->type = UV_ASYNC; + handle->loop = loop; handle->flags = 0; handle->async_sent = 0; handle->async_cb = async_cb; req = &handle->async_req; - uv_req_init(req); + uv_req_init(loop, req); req->type = UV_WAKEUP; req->data = handle; - uv_ref(); + uv_ref(loop); return 0; } int uv_async_send(uv_async_t* handle) { + uv_loop_t* loop = handle->loop; + if (handle->type != UV_ASYNC) { /* Can't set errno because that's not thread-safe. */ return -1; @@ -102,14 +105,15 @@ int uv_async_send(uv_async_t* handle) { assert(!(handle->flags & UV_HANDLE_CLOSING)); if (!uv_atomic_exchange_set(&handle->async_sent)) { - POST_COMPLETION_FOR_REQ(&handle->async_req); + POST_COMPLETION_FOR_REQ(loop, &handle->async_req); } return 0; } -void uv_process_async_wakeup_req(uv_async_t* handle, uv_req_t* req) { +void uv_process_async_wakeup_req(uv_loop_t* loop, uv_async_t* handle, + uv_req_t* req) { assert(handle->type == UV_ASYNC); assert(req->type == UV_WAKEUP); @@ -118,6 +122,6 @@ void uv_process_async_wakeup_req(uv_async_t* handle, uv_req_t* req) { handle->async_cb((uv_async_t*) handle, 0); } if (handle->flags & UV_HANDLE_CLOSING) { - uv_want_endgame((uv_handle_t*)handle); + uv_want_endgame(loop, (uv_handle_t*)handle); } } diff --git a/deps/uv/src/win/cares.c b/deps/uv/src/win/cares.c index aa8f181f8..8cc11d880 100644 --- a/deps/uv/src/win/cares.c +++ b/deps/uv/src/win/cares.c @@ -38,41 +38,34 @@ struct uv_ares_action_s { }; -/* memory used per ares_channel */ -typedef struct uv_ares_channel_s { - ares_channel channel; - int activesockets; - uv_timer_t pollingtimer; -} uv_ares_channel_t; - - -/* static data to hold single ares_channel */ -static uv_ares_channel_t uv_ares_data = { NULL, 0 }; - - /* default timeout per socket request if ares does not specify value */ /* use 20 sec */ #define ARES_TIMEOUT_MS 20000 /* thread pool callback when socket is signalled */ -static void CALLBACK uv_ares_socksignal_tp(void* parameter, BOOLEAN timerfired) { +static void CALLBACK uv_ares_socksignal_tp(void* parameter, + BOOLEAN timerfired) { WSANETWORKEVENTS network_events; uv_ares_task_t* sockhandle; uv_ares_action_t* selhandle; uv_req_t* uv_ares_req; + uv_loop_t* loop; assert(parameter != NULL); if (parameter != NULL) { - sockhandle = (uv_ares_task_t*)parameter; + sockhandle = (uv_ares_task_t*) parameter; + loop = sockhandle->loop; /* clear socket status for this event */ /* do not fail if error, thread may run after socket close */ - /* The code assumes that c-ares will write all pending data in the callback, - unless the socket would block. We can clear the state here to avoid unecessary - signals. */ - WSAEnumNetworkEvents(sockhandle->sock, sockhandle->h_event, &network_events); + /* The code assumes that c-ares will write all pending data in the */ + /* callback, unless the socket would block. We can clear the state here */ + /* to avoid unecessary signals. */ + WSAEnumNetworkEvents(sockhandle->sock, + sockhandle->h_event, + &network_events); /* setup new handle */ selhandle = (uv_ares_action_t*)malloc(sizeof(uv_ares_action_t)); @@ -83,47 +76,53 @@ static void CALLBACK uv_ares_socksignal_tp(void* parameter, BOOLEAN timerfired) selhandle->close_cb = NULL; selhandle->data = sockhandle->data; selhandle->sock = sockhandle->sock; - selhandle->read = (network_events.lNetworkEvents & (FD_READ | FD_CONNECT)) ? 1 : 0; - selhandle->write = (network_events.lNetworkEvents & (FD_WRITE | FD_CONNECT)) ? 1 : 0; + selhandle->read = + (network_events.lNetworkEvents & (FD_READ | FD_CONNECT)) ? 1 : 0; + selhandle->write = + (network_events.lNetworkEvents & (FD_WRITE | FD_CONNECT)) ? 1 : 0; uv_ares_req = &selhandle->ares_req; - uv_req_init(uv_ares_req); + uv_req_init(loop, uv_ares_req); uv_ares_req->type = UV_ARES_EVENT_REQ; uv_ares_req->data = selhandle; /* post ares needs to called */ - POST_COMPLETION_FOR_REQ(uv_ares_req); + POST_COMPLETION_FOR_REQ(loop, uv_ares_req); } } /* periodically call ares to check for timeouts */ static void uv_ares_poll(uv_timer_t* handle, int status) { - if (uv_ares_data.channel != NULL && uv_ares_data.activesockets > 0) { - ares_process_fd(uv_ares_data.channel, ARES_SOCKET_BAD, ARES_SOCKET_BAD); + uv_loop_t* loop = handle->loop; + if (loop->ares_channel != NULL && loop->ares_active_sockets > 0) { + ares_process_fd(loop->ares_channel, ARES_SOCKET_BAD, ARES_SOCKET_BAD); } } /* callback from ares when socket operation is started */ -static void uv_ares_sockstate_cb(void *data, ares_socket_t sock, int read, int write) { +static void uv_ares_sockstate_cb(void *data, ares_socket_t sock, int read, + int write) { /* look to see if we have a handle for this socket in our list */ - uv_ares_task_t* uv_handle_ares = uv_find_ares_handle(sock); - uv_ares_channel_t* uv_ares_data_ptr = (uv_ares_channel_t*)data; + uv_loop_t* loop = (uv_loop_t*) data; + uv_ares_task_t* uv_handle_ares = uv_find_ares_handle(loop, sock); int timeoutms = 0; if (read == 0 && write == 0) { /* if read and write are 0, cleanup existing data */ - /* The code assumes that c-ares does a callback with read = 0 and write = 0 - when the socket is closed. After we recieve this we stop monitoring the socket. */ + /* The code assumes that c-ares does a callback with read = 0 and */ + /* write = 0 when the socket is closed. After we recieve this we stop */ + /* monitoring the socket. */ if (uv_handle_ares != NULL) { uv_req_t* uv_ares_req; uv_handle_ares->h_close_event = CreateEvent(NULL, FALSE, FALSE, NULL); /* remove Wait */ if (uv_handle_ares->h_wait) { - UnregisterWaitEx(uv_handle_ares->h_wait, uv_handle_ares->h_close_event); + UnregisterWaitEx(uv_handle_ares->h_wait, + uv_handle_ares->h_close_event); uv_handle_ares->h_wait = NULL; } @@ -138,12 +137,12 @@ static void uv_ares_sockstate_cb(void *data, ares_socket_t sock, int read, int w /* Post request to cleanup the Task */ uv_ares_req = &uv_handle_ares->ares_req; - uv_req_init(uv_ares_req); + uv_req_init(loop, uv_ares_req); uv_ares_req->type = UV_ARES_CLEANUP_REQ; uv_ares_req->data = uv_handle_ares; /* post ares done with socket - finish cleanup when all threads done. */ - POST_COMPLETION_FOR_REQ(uv_ares_req); + POST_COMPLETION_FOR_REQ(loop, uv_ares_req); } else { assert(0); uv_fatal_error(ERROR_INVALID_DATA, "ares_SockStateCB"); @@ -160,7 +159,7 @@ static void uv_ares_sockstate_cb(void *data, ares_socket_t sock, int read, int w } uv_handle_ares->type = UV_ARES_TASK; uv_handle_ares->close_cb = NULL; - uv_handle_ares->data = uv_ares_data_ptr; + uv_handle_ares->data = loop; uv_handle_ares->sock = sock; uv_handle_ares->h_wait = NULL; uv_handle_ares->flags = 0; @@ -172,24 +171,26 @@ static void uv_ares_sockstate_cb(void *data, ares_socket_t sock, int read, int w } /* tie event to socket */ - if (SOCKET_ERROR == WSAEventSelect(sock, uv_handle_ares->h_event, FD_READ | FD_WRITE | FD_CONNECT)) { + if (SOCKET_ERROR == WSAEventSelect(sock, + uv_handle_ares->h_event, + FD_READ | FD_WRITE | FD_CONNECT)) { uv_fatal_error(WSAGetLastError(), "WSAEventSelect"); } /* add handle to list */ - uv_add_ares_handle(uv_handle_ares); - uv_ref(); + uv_add_ares_handle(loop, uv_handle_ares); + uv_ref(loop); /* * we have a single polling timer for all ares sockets. * This is preferred to using ares_timeout. See ares_timeout.c warning. * if timer is not running start it, and keep socket count */ - if (uv_ares_data_ptr->activesockets == 0) { - uv_timer_init(&uv_ares_data_ptr->pollingtimer); - uv_timer_start(&uv_ares_data_ptr->pollingtimer, uv_ares_poll, 1000L, 1000L); + if (loop->ares_active_sockets == 0) { + uv_timer_init(loop, &loop->ares_polling_timer); + uv_timer_start(&loop->ares_polling_timer, uv_ares_poll, 1000L, 1000L); } - uv_ares_data_ptr->activesockets++; + loop->ares_active_sockets++; /* specify thread pool function to call when event is signaled */ if (RegisterWaitForSingleObject(&uv_handle_ares->h_wait, @@ -211,12 +212,11 @@ static void uv_ares_sockstate_cb(void *data, ares_socket_t sock, int read, int w /* called via uv_poll when ares completion port signaled */ -void uv_process_ares_event_req(uv_ares_action_t* handle, uv_req_t* req) { - uv_ares_channel_t* uv_ares_data_ptr = (uv_ares_channel_t*)handle->data; - - ares_process_fd(uv_ares_data_ptr->channel, - handle->read ? handle->sock : INVALID_SOCKET, - handle->write ? handle->sock : INVALID_SOCKET); +void uv_process_ares_event_req(uv_loop_t* loop, uv_ares_action_t* handle, + uv_req_t* req) { + ares_process_fd(loop->ares_channel, + handle->read ? handle->sock : INVALID_SOCKET, + handle->write ? handle->sock : INVALID_SOCKET); /* release handle for select here */ free(handle); @@ -224,47 +224,47 @@ void uv_process_ares_event_req(uv_ares_action_t* handle, uv_req_t* req) { /* called via uv_poll when ares is finished with socket */ -void uv_process_ares_cleanup_req(uv_ares_task_t* handle, uv_req_t* req) { +void uv_process_ares_cleanup_req(uv_loop_t* loop, uv_ares_task_t* handle, + uv_req_t* req) { /* check for event complete without waiting */ unsigned int signaled = WaitForSingleObject(handle->h_close_event, 0); if (signaled != WAIT_TIMEOUT) { - uv_ares_channel_t* uv_ares_data_ptr = (uv_ares_channel_t*)handle->data; - - uv_unref(); + uv_unref(loop); /* close event handle and free uv handle memory */ CloseHandle(handle->h_close_event); free(handle); /* decrement active count. if it becomes 0 stop polling */ - if (uv_ares_data_ptr->activesockets > 0) { - uv_ares_data_ptr->activesockets--; - if (uv_ares_data_ptr->activesockets == 0) { - uv_close((uv_handle_t*)&uv_ares_data_ptr->pollingtimer, NULL); + if (loop->ares_active_sockets > 0) { + loop->ares_active_sockets--; + if (loop->ares_active_sockets == 0) { + uv_close((uv_handle_t*) &loop->ares_polling_timer, NULL); } } } else { /* stil busy - repost and try again */ - POST_COMPLETION_FOR_REQ(req); + POST_COMPLETION_FOR_REQ(loop, req); } } /* set ares SOCK_STATE callback to our handler */ -int uv_ares_init_options(ares_channel *channelptr, - struct ares_options *options, - int optmask) { +int uv_ares_init_options(uv_loop_t* loop, + ares_channel *channelptr, + struct ares_options *options, + int optmask) { int rc; /* only allow single init at a time */ - if (uv_ares_data.channel != NULL) { + if (loop->ares_channel != NULL) { return UV_EALREADY; } /* set our callback as an option */ options->sock_state_cb = uv_ares_sockstate_cb; - options->sock_state_cb_data = &uv_ares_data; + options->sock_state_cb_data = loop; optmask |= ARES_OPT_SOCK_STATE_CB; /* We do the call to ares_init_option for caller. */ @@ -272,7 +272,7 @@ int uv_ares_init_options(ares_channel *channelptr, /* if success, save channel */ if (rc == ARES_SUCCESS) { - uv_ares_data.channel = *channelptr; + loop->ares_channel = *channelptr; } return rc; @@ -280,10 +280,10 @@ int uv_ares_init_options(ares_channel *channelptr, /* release memory */ -void uv_ares_destroy(ares_channel channel) { +void uv_ares_destroy(uv_loop_t* loop, ares_channel channel) { /* only allow destroy if did init */ - if (uv_ares_data.channel != NULL) { + if (loop->ares_channel != NULL) { ares_destroy(channel); - uv_ares_data.channel = NULL; + loop->ares_channel = NULL; } } diff --git a/deps/uv/src/win/core.c b/deps/uv/src/win/core.c index 89e726fa8..1f832cbe2 100644 --- a/deps/uv/src/win/core.c +++ b/deps/uv/src/win/core.c @@ -32,37 +32,49 @@ /* The only event loop we support right now */ -uv_loop_t uv_main_loop_; +static uv_loop_t uv_default_loop_; +static int uv_default_loop_initialized_ = 0; -static void uv_loop_init() { +static void uv_loop_init(uv_loop_t* loop) { /* Create an I/O completion port */ - LOOP->iocp = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 1); - if (LOOP->iocp == NULL) { + loop->iocp = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 1); + if (loop->iocp == NULL) { uv_fatal_error(GetLastError(), "CreateIoCompletionPort"); } - LOOP->refs = 0; + loop->refs = 0; - uv_update_time(); + uv_update_time(loop); - LOOP->pending_reqs_tail = NULL; + loop->pending_reqs_tail = NULL; - LOOP->endgame_handles = NULL; + loop->endgame_handles = NULL; - RB_INIT(&LOOP->timers); + RB_INIT(&loop->timers); - LOOP->check_handles = NULL; - LOOP->prepare_handles = NULL; - LOOP->idle_handles = NULL; + loop->check_handles = NULL; + loop->prepare_handles = NULL; + loop->idle_handles = NULL; - LOOP->next_prepare_handle = NULL; - LOOP->next_check_handle = NULL; - LOOP->next_idle_handle = NULL; + loop->next_prepare_handle = NULL; + loop->next_check_handle = NULL; + loop->next_idle_handle = NULL; - LOOP->last_error = uv_ok_; + loop->ares_active_sockets = 0; + loop->ares_channel = NULL; - LOOP->err_str = NULL; + loop->last_error = uv_ok_; +} + + +uv_loop_t* uv_default_loop() { + if (!uv_default_loop_initialized_) { + uv_loop_init(&uv_default_loop_); + uv_default_loop_initialized_ = 1; + } + + return &uv_default_loop_; } @@ -75,23 +87,20 @@ void uv_init() { /* Initialize FS */ uv_fs_init(); - - /* Intialize event loop */ - uv_loop_init(); } -void uv_ref() { - LOOP->refs++; +void uv_ref(uv_loop_t* loop) { + loop->refs++; } -void uv_unref() { - LOOP->refs--; +void uv_unref(uv_loop_t* loop) { + loop->refs--; } -static void uv_poll(int block) { +static void uv_poll(uv_loop_t* loop, int block) { BOOL success; DWORD bytes, timeout; ULONG_PTR key; @@ -99,12 +108,12 @@ static void uv_poll(int block) { uv_req_t* req; if (block) { - timeout = uv_get_poll_timeout(); + timeout = uv_get_poll_timeout(loop); } else { timeout = 0; } - success = GetQueuedCompletionStatus(LOOP->iocp, + success = GetQueuedCompletionStatus(loop->iocp, &bytes, &key, &overlapped, @@ -114,7 +123,7 @@ static void uv_poll(int block) { /* Package was dequeued */ req = uv_overlapped_to_req(overlapped); - uv_insert_pending_req(req); + uv_insert_pending_req(loop, req); } else if (GetLastError() != WAIT_TIMEOUT) { /* Serious error */ @@ -123,7 +132,7 @@ static void uv_poll(int block) { } -static void uv_poll_ex(int block) { +static void uv_poll_ex(uv_loop_t* loop, int block) { BOOL success; DWORD timeout; uv_req_t* req; @@ -132,14 +141,14 @@ static void uv_poll_ex(int block) { ULONG i; if (block) { - timeout = uv_get_poll_timeout(); + timeout = uv_get_poll_timeout(loop); } else { timeout = 0; } assert(pGetQueuedCompletionStatusEx); - success = pGetQueuedCompletionStatusEx(LOOP->iocp, + success = pGetQueuedCompletionStatusEx(loop->iocp, overlappeds, COUNTOF(overlappeds), &count, @@ -149,7 +158,7 @@ static void uv_poll_ex(int block) { for (i = 0; i < count; i++) { /* Package was dequeued */ req = uv_overlapped_to_req(overlappeds[i].lpOverlapped); - uv_insert_pending_req(req); + uv_insert_pending_req(loop, req); } } else if (GetLastError() != WAIT_TIMEOUT) { /* Serious error */ @@ -158,43 +167,44 @@ static void uv_poll_ex(int block) { } -#define UV_LOOP(poll) \ - while (LOOP->refs > 0) { \ - uv_update_time(); \ - uv_process_timers(); \ +#define UV_LOOP(loop, poll) \ + while ((loop)->refs > 0) { \ + uv_update_time((loop)); \ + uv_process_timers((loop)); \ \ /* Call idle callbacks if nothing to do. */ \ - if (LOOP->pending_reqs_tail == NULL && LOOP->endgame_handles == NULL) { \ - uv_idle_invoke(); \ + if ((loop)->pending_reqs_tail == NULL && \ + (loop)->endgame_handles == NULL) { \ + uv_idle_invoke((loop)); \ } \ \ /* Completely flush all pending reqs and endgames. */ \ /* We do even when we just called the idle callbacks because those may */ \ /* have closed handles or started requests that short-circuited. */ \ - while (LOOP->pending_reqs_tail || LOOP->endgame_handles) { \ - uv_process_endgames(); \ - uv_process_reqs(); \ + while ((loop)->pending_reqs_tail || (loop)->endgame_handles) { \ + uv_process_endgames((loop)); \ + uv_process_reqs((loop)); \ } \ \ - if (LOOP->refs <= 0) { \ + if ((loop)->refs <= 0) { \ break; \ } \ \ - uv_prepare_invoke(); \ + uv_prepare_invoke((loop)); \ \ - poll(LOOP->idle_handles == NULL && LOOP->refs > 0); \ + poll((loop), (loop)->idle_handles == NULL && (loop)->refs > 0); \ \ - uv_check_invoke(); \ + uv_check_invoke((loop)); \ } -int uv_run() { +int uv_run(uv_loop_t* loop) { if (pGetQueuedCompletionStatusEx) { - UV_LOOP(uv_poll_ex); + UV_LOOP(loop, uv_poll_ex); } else { - UV_LOOP(uv_poll); + UV_LOOP(loop, uv_poll); } - assert(LOOP->refs == 0); + assert(loop->refs == 0); return 0; } diff --git a/deps/uv/src/win/error.c b/deps/uv/src/win/error.c index 1e00fc6e8..393c34990 100644 --- a/deps/uv/src/win/error.c +++ b/deps/uv/src/win/error.c @@ -67,22 +67,26 @@ void uv_fatal_error(const int errorno, const char* syscall) { } -uv_err_t uv_last_error() { - return LOOP->last_error; +uv_err_t uv_last_error(uv_loop_t* loop) { + return loop->last_error; } +/* TODO: thread safety */ +static char* last_err_str_ = NULL; + char* uv_strerror(uv_err_t err) { - if (LOOP->err_str != NULL) { - LocalFree(LOOP->err_str); + if (last_err_str_ != NULL) { + LocalFree(last_err_str_); } FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err.sys_errno_, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&LOOP->err_str, 0, NULL); + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR) &last_err_str_, 0, + NULL); - if (LOOP->err_str) { - return LOOP->err_str; + if (last_err_str_) { + return last_err_str_; } else { return "Unknown error"; } @@ -134,13 +138,13 @@ uv_err_t uv_new_sys_error(int sys_errno) { } -void uv_set_sys_error(int sys_errno) { - LOOP->last_error.code = uv_translate_sys_error(sys_errno); - LOOP->last_error.sys_errno_ = sys_errno; +void uv_set_sys_error(uv_loop_t* loop, int sys_errno) { + loop->last_error.code = uv_translate_sys_error(sys_errno); + loop->last_error.sys_errno_ = sys_errno; } -void uv_set_error(uv_err_code code, int sys_errno) { - LOOP->last_error.code = code; - LOOP->last_error.sys_errno_ = sys_errno; +void uv_set_error(uv_loop_t* loop, uv_err_code code, int sys_errno) { + loop->last_error.code = code; + loop->last_error.sys_errno_ = sys_errno; } diff --git a/deps/uv/src/win/fs.c b/deps/uv/src/win/fs.c index 304f353e9..15f92961b 100644 --- a/deps/uv/src/win/fs.c +++ b/deps/uv/src/win/fs.c @@ -59,13 +59,15 @@ WRAP_REQ_ARGS3(req, a0, a1, a2) \ req->arg3 = (void*)a3; -#define QUEUE_FS_TP_JOB(req) \ - if (!QueueUserWorkItem(&uv_fs_thread_proc, req, WT_EXECUTELONGFUNCTION)) {\ - uv_set_sys_error(GetLastError()); \ +#define QUEUE_FS_TP_JOB(loop, req) \ + if (!QueueUserWorkItem(&uv_fs_thread_proc, \ + req, \ + WT_EXECUTELONGFUNCTION)) { \ + uv_set_sys_error((loop), GetLastError()); \ return -1; \ } \ req->flags |= UV_FS_ASYNC_QUEUED; \ - uv_ref(); + uv_ref((loop)); void uv_fs_init() { @@ -73,9 +75,11 @@ void uv_fs_init() { } -static void uv_fs_req_init_async(uv_fs_t* req, uv_fs_type fs_type, uv_fs_cb cb) { - uv_req_init((uv_req_t*) req); +static void uv_fs_req_init_async(uv_loop_t* loop, uv_fs_t* req, + uv_fs_type fs_type, uv_fs_cb cb) { + uv_req_init(loop, (uv_req_t*) req); req->type = UV_FS; + req->loop = loop; req->flags = 0; req->fs_type = fs_type; req->cb = cb; @@ -86,9 +90,11 @@ static void uv_fs_req_init_async(uv_fs_t* req, uv_fs_type fs_type, uv_fs_cb cb) } -static void uv_fs_req_init_sync(uv_fs_t* req, uv_fs_type fs_type) { - uv_req_init((uv_req_t*) req); +static void uv_fs_req_init_sync(uv_loop_t* loop, uv_fs_t* req, + uv_fs_type fs_type) { + uv_req_init(loop, (uv_req_t*) req); req->type = UV_FS; + req->loop = loop; req->flags = 0; req->fs_type = fs_type; req->result = 0; @@ -109,7 +115,8 @@ void fs__close(uv_fs_t* req, uv_file file) { } -void fs__read(uv_fs_t* req, uv_file file, void *buf, size_t length, off_t offset) { +void fs__read(uv_fs_t* req, uv_file file, void *buf, size_t length, + off_t offset) { int result = 0; if (offset != -1) { @@ -124,7 +131,8 @@ void fs__read(uv_fs_t* req, uv_file file, void *buf, size_t length, off_t offset } -void fs__write(uv_fs_t* req, uv_file file, void *buf, size_t length, off_t offset) { +void fs__write(uv_fs_t* req, uv_file file, void *buf, size_t length, + off_t offset) { int result = 0; if (offset != -1) { @@ -281,7 +289,8 @@ void fs__ftruncate(uv_fs_t* req, uv_file file, off_t offset) { } -void fs__sendfile(uv_fs_t* req, uv_file out_file, uv_file in_file, off_t in_offset, size_t length) { +void fs__sendfile(uv_fs_t* req, uv_file out_file, uv_file in_file, + off_t in_offset, size_t length) { const size_t max_buf_size = 65536; size_t buf_size = length < max_buf_size ? length : max_buf_size; int n, result = 0; @@ -293,7 +302,7 @@ void fs__sendfile(uv_fs_t* req, uv_file out_file, uv_file in_file, off_t in_offs if (in_offset != -1) { result = _lseek(in_file, in_offset, SEEK_SET); } - + if (result != -1) { while (length > 0) { n = _read(in_file, buf, length < buf_size ? length : buf_size); @@ -343,7 +352,8 @@ void fs__futime(uv_fs_t* req, uv_file file, double atime, double mtime) { static DWORD WINAPI uv_fs_thread_proc(void* parameter) { - uv_fs_t* req = (uv_fs_t*)parameter; + uv_fs_t* req = (uv_fs_t*) parameter; + uv_loop_t* loop = req->loop; assert(req != NULL); assert(req->type == UV_FS); @@ -356,10 +366,18 @@ static DWORD WINAPI uv_fs_thread_proc(void* parameter) { fs__close(req, (uv_file)req->arg0); break; case UV_FS_READ: - fs__read(req, (uv_file)req->arg0, req->arg1, (size_t)req->arg2, (off_t)req->arg3); + fs__read(req, + (uv_file) req->arg0, + req->arg1, + (size_t) req->arg2, + (off_t) req->arg3); break; case UV_FS_WRITE: - fs__write(req, (uv_file)req->arg0, req->arg1, (size_t)req->arg2, (off_t)req->arg3); + fs__write(req, + (uv_file)req->arg0, + req->arg1, + (size_t) req->arg2, + (off_t) req->arg3); break; case UV_FS_UNLINK: fs__unlink(req, (const char*)req->arg0); @@ -390,7 +408,11 @@ static DWORD WINAPI uv_fs_thread_proc(void* parameter) { fs__ftruncate(req, (uv_file)req->arg0, (off_t)req->arg1); break; case UV_FS_SENDFILE: - fs__sendfile(req, (uv_file)req->arg0, (uv_file)req->arg1, (off_t)req->arg2, (size_t)req->arg3); + fs__sendfile(req, + (uv_file) req->arg0, + (uv_file) req->arg1, + (off_t) req->arg2, + (size_t) req->arg3); break; case UV_FS_CHMOD: fs__chmod(req, (const char*)req->arg0, (int)req->arg1); @@ -405,20 +427,21 @@ static DWORD WINAPI uv_fs_thread_proc(void* parameter) { assert(!"bad uv_fs_type"); } - POST_COMPLETION_FOR_REQ(req); + POST_COMPLETION_FOR_REQ(loop, req); return 0; } -int uv_fs_open(uv_fs_t* req, const char* path, int flags, int mode, uv_fs_cb cb) { +int uv_fs_open(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, + int mode, uv_fs_cb cb) { if (cb) { - uv_fs_req_init_async(req, UV_FS_OPEN, cb); + uv_fs_req_init_async(loop, req, UV_FS_OPEN, cb); WRAP_REQ_ARGS3(req, path, flags, mode); STRDUP_ARG(req, 0); - QUEUE_FS_TP_JOB(req); + QUEUE_FS_TP_JOB(loop, req); } else { - uv_fs_req_init_sync(req, UV_FS_OPEN); + uv_fs_req_init_sync(loop, req, UV_FS_OPEN); fs__open(req, path, flags, mode); } @@ -426,13 +449,13 @@ int uv_fs_open(uv_fs_t* req, const char* path, int flags, int mode, uv_fs_cb cb) } -int uv_fs_close(uv_fs_t* req, uv_file file, uv_fs_cb cb) { +int uv_fs_close(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { if (cb) { - uv_fs_req_init_async(req, UV_FS_CLOSE, cb); + uv_fs_req_init_async(loop, req, UV_FS_CLOSE, cb); WRAP_REQ_ARGS1(req, file); - QUEUE_FS_TP_JOB(req); + QUEUE_FS_TP_JOB(loop, req); } else { - uv_fs_req_init_sync(req, UV_FS_CLOSE); + uv_fs_req_init_sync(loop, req, UV_FS_CLOSE); fs__close(req, file); } @@ -440,13 +463,14 @@ int uv_fs_close(uv_fs_t* req, uv_file file, uv_fs_cb cb) { } -int uv_fs_read(uv_fs_t* req, uv_file file, void* buf, size_t length, off_t offset, uv_fs_cb cb) { +int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, uv_file file, void* buf, + size_t length, off_t offset, uv_fs_cb cb) { if (cb) { - uv_fs_req_init_async(req, UV_FS_READ, cb); + uv_fs_req_init_async(loop, req, UV_FS_READ, cb); WRAP_REQ_ARGS4(req, file, buf, length, offset); - QUEUE_FS_TP_JOB(req); + QUEUE_FS_TP_JOB(loop, req); } else { - uv_fs_req_init_sync(req, UV_FS_READ); + uv_fs_req_init_sync(loop, req, UV_FS_READ); fs__read(req, file, buf, length, offset); } @@ -454,13 +478,14 @@ int uv_fs_read(uv_fs_t* req, uv_file file, void* buf, size_t length, off_t offse } -int uv_fs_write(uv_fs_t* req, uv_file file, void* buf, size_t length, off_t offset, uv_fs_cb cb) { +int uv_fs_write(uv_loop_t* loop, uv_fs_t* req, uv_file file, void* buf, + size_t length, off_t offset, uv_fs_cb cb) { if (cb) { - uv_fs_req_init_async(req, UV_FS_WRITE, cb); + uv_fs_req_init_async(loop, req, UV_FS_WRITE, cb); WRAP_REQ_ARGS4(req, file, buf, length, offset); - QUEUE_FS_TP_JOB(req); + QUEUE_FS_TP_JOB(loop, req); } else { - uv_fs_req_init_sync(req, UV_FS_WRITE); + uv_fs_req_init_sync(loop, req, UV_FS_WRITE); fs__write(req, file, buf, length, offset); } @@ -468,14 +493,15 @@ int uv_fs_write(uv_fs_t* req, uv_file file, void* buf, size_t length, off_t offs } -int uv_fs_unlink(uv_fs_t* req, const char* path, uv_fs_cb cb) { +int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path, + uv_fs_cb cb) { if (cb) { - uv_fs_req_init_async(req, UV_FS_UNLINK, cb); + uv_fs_req_init_async(loop, req, UV_FS_UNLINK, cb); WRAP_REQ_ARGS1(req, path); STRDUP_ARG(req, 0); - QUEUE_FS_TP_JOB(req); + QUEUE_FS_TP_JOB(loop, req); } else { - uv_fs_req_init_sync(req, UV_FS_UNLINK); + uv_fs_req_init_sync(loop, req, UV_FS_UNLINK); fs__unlink(req, path); } @@ -483,14 +509,15 @@ int uv_fs_unlink(uv_fs_t* req, const char* path, uv_fs_cb cb) { } -int uv_fs_mkdir(uv_fs_t* req, const char* path, int mode, uv_fs_cb cb) { +int uv_fs_mkdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode, + uv_fs_cb cb) { if (cb) { - uv_fs_req_init_async(req, UV_FS_MKDIR, cb); + uv_fs_req_init_async(loop, req, UV_FS_MKDIR, cb); WRAP_REQ_ARGS2(req, path, mode); STRDUP_ARG(req, 0); - QUEUE_FS_TP_JOB(req); + QUEUE_FS_TP_JOB(loop, req); } else { - uv_fs_req_init_sync(req, UV_FS_MKDIR); + uv_fs_req_init_sync(loop, req, UV_FS_MKDIR); fs__mkdir(req, path, mode); } @@ -498,14 +525,14 @@ int uv_fs_mkdir(uv_fs_t* req, const char* path, int mode, uv_fs_cb cb) { } -int uv_fs_rmdir(uv_fs_t* req, const char* path, uv_fs_cb cb) { +int uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { if (cb) { - uv_fs_req_init_async(req, UV_FS_RMDIR, cb); + uv_fs_req_init_async(loop, req, UV_FS_RMDIR, cb); WRAP_REQ_ARGS1(req, path); STRDUP_ARG(req, 0); - QUEUE_FS_TP_JOB(req); + QUEUE_FS_TP_JOB(loop, req); } else { - uv_fs_req_init_sync(req, UV_FS_RMDIR); + uv_fs_req_init_sync(loop, req, UV_FS_RMDIR); fs__rmdir(req, path); } @@ -513,14 +540,15 @@ int uv_fs_rmdir(uv_fs_t* req, const char* path, uv_fs_cb cb) { } -int uv_fs_readdir(uv_fs_t* req, const char* path, int flags, uv_fs_cb cb) { +int uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, + uv_fs_cb cb) { if (cb) { - uv_fs_req_init_async(req, UV_FS_READDIR, cb); + uv_fs_req_init_async(loop, req, UV_FS_READDIR, cb); WRAP_REQ_ARGS2(req, path, flags); STRDUP_ARG(req, 0); - QUEUE_FS_TP_JOB(req); + QUEUE_FS_TP_JOB(loop, req); } else { - uv_fs_req_init_sync(req, UV_FS_READDIR); + uv_fs_req_init_sync(loop, req, UV_FS_READDIR); fs__readdir(req, path, flags); } @@ -528,50 +556,56 @@ int uv_fs_readdir(uv_fs_t* req, const char* path, int flags, uv_fs_cb cb) { } -int uv_fs_lstat(uv_fs_t* req, const char* path, uv_fs_cb cb) { +int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { assert(0 && "implement me"); return -1; } // uv_fs_readlink, uv_fs_fchmod, uv_fs_chown, uv_fs_fchown -int uv_fs_link(uv_fs_t* req, const char* path, const char* new_path, uv_fs_cb cb) { +int uv_fs_link(uv_loop_t* loop, uv_fs_t* req, const char* path, + const char* new_path, uv_fs_cb cb) { assert(0 && "implement me"); return -1; } -int uv_fs_symlink(uv_fs_t* req, const char* path, const char* new_path, uv_fs_cb cb) { +int uv_fs_symlink(uv_loop_t* loop, uv_fs_t* req, const char* path, + const char* new_path, uv_fs_cb cb) { assert(0 && "implement me"); return -1; } -int uv_fs_readlink(uv_fs_t* req, const char* path, uv_fs_cb cb) { +int uv_fs_readlink(uv_loop_t* loop, uv_fs_t* req, const char* path, + uv_fs_cb cb) { assert(0 && "implement me"); return -1; } -int uv_fs_fchmod(uv_fs_t* req, uv_file file, int mode, uv_fs_cb cb) { +int uv_fs_fchmod(uv_loop_t* loop, uv_fs_t* req, uv_file file, int mode, + uv_fs_cb cb) { assert(0 && "implement me"); return -1; } -int uv_fs_chown(uv_fs_t* req, const char* path, int uid, int gid, uv_fs_cb cb) { +int uv_fs_chown(uv_loop_t* loop, uv_fs_t* req, const char* path, int uid, + int gid, uv_fs_cb cb) { assert(0 && "implement me"); return -1; } -int uv_fs_fchown(uv_fs_t* req, uv_file file, int uid, int gid, uv_fs_cb cb) { +int uv_fs_fchown(uv_loop_t* loop, uv_fs_t* req, uv_file file, int uid, + int gid, uv_fs_cb cb) { assert(0 && "implement me"); return -1; } -int uv_fs_stat(uv_fs_t* req, const char* path, uv_fs_cb cb) { +int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { int len = strlen(path); char* path2 = NULL; int has_backslash = (path[len - 1] == '\\' || path[len - 1] == '/'); @@ -586,7 +620,7 @@ int uv_fs_stat(uv_fs_t* req, const char* path, uv_fs_cb cb) { } if (cb) { - uv_fs_req_init_async(req, UV_FS_STAT, cb); + uv_fs_req_init_async(loop, req, UV_FS_STAT, cb); if (path2) { WRAP_REQ_ARGS1(req, path2); req->flags |= UV_FS_FREE_ARG0; @@ -594,10 +628,10 @@ int uv_fs_stat(uv_fs_t* req, const char* path, uv_fs_cb cb) { WRAP_REQ_ARGS1(req, path); STRDUP_ARG(req, 0); } - - QUEUE_FS_TP_JOB(req); + + QUEUE_FS_TP_JOB(loop, req); } else { - uv_fs_req_init_sync(req, UV_FS_STAT); + uv_fs_req_init_sync(loop, req, UV_FS_STAT); fs__stat(req, path2 ? path2 : path); if (path2) { free(path2); @@ -608,13 +642,13 @@ int uv_fs_stat(uv_fs_t* req, const char* path, uv_fs_cb cb) { } -int uv_fs_fstat(uv_fs_t* req, uv_file file, uv_fs_cb cb) { +int uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { if (cb) { - uv_fs_req_init_async(req, UV_FS_FSTAT, cb); + uv_fs_req_init_async(loop, req, UV_FS_FSTAT, cb); WRAP_REQ_ARGS1(req, file); - QUEUE_FS_TP_JOB(req); + QUEUE_FS_TP_JOB(loop, req); } else { - uv_fs_req_init_sync(req, UV_FS_FSTAT); + uv_fs_req_init_sync(loop, req, UV_FS_FSTAT); fs__fstat(req, file); } @@ -622,15 +656,16 @@ int uv_fs_fstat(uv_fs_t* req, uv_file file, uv_fs_cb cb) { } -int uv_fs_rename(uv_fs_t* req, const char* path, const char* new_path, uv_fs_cb cb) { +int uv_fs_rename(uv_loop_t* loop, uv_fs_t* req, const char* path, + const char* new_path, uv_fs_cb cb) { if (cb) { - uv_fs_req_init_async(req, UV_FS_RENAME, cb); + uv_fs_req_init_async(loop, req, UV_FS_RENAME, cb); WRAP_REQ_ARGS2(req, path, new_path); STRDUP_ARG(req, 0); STRDUP_ARG(req, 1); - QUEUE_FS_TP_JOB(req); + QUEUE_FS_TP_JOB(loop, req); } else { - uv_fs_req_init_sync(req, UV_FS_RENAME); + uv_fs_req_init_sync(loop, req, UV_FS_RENAME); fs__rename(req, path, new_path); } @@ -638,13 +673,13 @@ int uv_fs_rename(uv_fs_t* req, const char* path, const char* new_path, uv_fs_cb } -int uv_fs_fdatasync(uv_fs_t* req, uv_file file, uv_fs_cb cb) { +int uv_fs_fdatasync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { if (cb) { - uv_fs_req_init_async(req, UV_FS_FDATASYNC, cb); + uv_fs_req_init_async(loop, req, UV_FS_FDATASYNC, cb); WRAP_REQ_ARGS1(req, file); - QUEUE_FS_TP_JOB(req); + QUEUE_FS_TP_JOB(loop, req); } else { - uv_fs_req_init_sync(req, UV_FS_FDATASYNC); + uv_fs_req_init_sync(loop, req, UV_FS_FDATASYNC); fs__fsync(req, file); } @@ -652,13 +687,13 @@ int uv_fs_fdatasync(uv_fs_t* req, uv_file file, uv_fs_cb cb) { } -int uv_fs_fsync(uv_fs_t* req, uv_file file, uv_fs_cb cb) { +int uv_fs_fsync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { if (cb) { - uv_fs_req_init_async(req, UV_FS_FSYNC, cb); + uv_fs_req_init_async(loop, req, UV_FS_FSYNC, cb); WRAP_REQ_ARGS1(req, file); - QUEUE_FS_TP_JOB(req); + QUEUE_FS_TP_JOB(loop, req); } else { - uv_fs_req_init_sync(req, UV_FS_FSYNC); + uv_fs_req_init_sync(loop, req, UV_FS_FSYNC); fs__fsync(req, file); } @@ -666,13 +701,14 @@ int uv_fs_fsync(uv_fs_t* req, uv_file file, uv_fs_cb cb) { } -int uv_fs_ftruncate(uv_fs_t* req, uv_file file, off_t offset, uv_fs_cb cb) { +int uv_fs_ftruncate(uv_loop_t* loop, uv_fs_t* req, uv_file file, + off_t offset, uv_fs_cb cb) { if (cb) { - uv_fs_req_init_async(req, UV_FS_FTRUNCATE, cb); + uv_fs_req_init_async(loop, req, UV_FS_FTRUNCATE, cb); WRAP_REQ_ARGS2(req, file, offset); - QUEUE_FS_TP_JOB(req); + QUEUE_FS_TP_JOB(loop, req); } else { - uv_fs_req_init_sync(req, UV_FS_FTRUNCATE); + uv_fs_req_init_sync(loop, req, UV_FS_FTRUNCATE); fs__ftruncate(req, file, offset); } @@ -680,13 +716,14 @@ int uv_fs_ftruncate(uv_fs_t* req, uv_file file, off_t offset, uv_fs_cb cb) { } -int uv_fs_sendfile(uv_fs_t* req, uv_file out_fd, uv_file in_fd, off_t in_offset, size_t length, uv_fs_cb cb) { +int uv_fs_sendfile(uv_loop_t* loop, uv_fs_t* req, uv_file out_fd, + uv_file in_fd, off_t in_offset, size_t length, uv_fs_cb cb) { if (cb) { - uv_fs_req_init_async(req, UV_FS_SENDFILE, cb); + uv_fs_req_init_async(loop, req, UV_FS_SENDFILE, cb); WRAP_REQ_ARGS4(req, out_fd, in_fd, in_offset, length); - QUEUE_FS_TP_JOB(req); + QUEUE_FS_TP_JOB(loop, req); } else { - uv_fs_req_init_sync(req, UV_FS_SENDFILE); + uv_fs_req_init_sync(loop, req, UV_FS_SENDFILE); fs__sendfile(req, out_fd, in_fd, in_offset, length); } @@ -694,14 +731,15 @@ int uv_fs_sendfile(uv_fs_t* req, uv_file out_fd, uv_file in_fd, off_t in_offset, } -int uv_fs_chmod(uv_fs_t* req, const char* path, int mode, uv_fs_cb cb) { +int uv_fs_chmod(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode, + uv_fs_cb cb) { if (cb) { - uv_fs_req_init_async(req, UV_FS_CHMOD, cb); + uv_fs_req_init_async(loop, req, UV_FS_CHMOD, cb); WRAP_REQ_ARGS2(req, path, mode); STRDUP_ARG(req, 0); - QUEUE_FS_TP_JOB(req); + QUEUE_FS_TP_JOB(loop, req); } else { - uv_fs_req_init_sync(req, UV_FS_CHMOD); + uv_fs_req_init_sync(loop, req, UV_FS_CHMOD); fs__chmod(req, path, mode); } @@ -709,16 +747,17 @@ int uv_fs_chmod(uv_fs_t* req, const char* path, int mode, uv_fs_cb cb) { } -int uv_fs_utime(uv_fs_t* req, const char* path, double atime, double mtime, uv_fs_cb cb) { +int uv_fs_utime(uv_loop_t* loop, uv_fs_t* req, const char* path, double atime, + double mtime, uv_fs_cb cb) { if (cb) { - uv_fs_req_init_async(req, UV_FS_UTIME, cb); + uv_fs_req_init_async(loop, req, UV_FS_UTIME, cb); WRAP_REQ_ARGS1(req, path); STRDUP_ARG(req, 0); req->arg4 = (ssize_t)atime; req->arg5 = (ssize_t)mtime; - QUEUE_FS_TP_JOB(req); + QUEUE_FS_TP_JOB(loop, req); } else { - uv_fs_req_init_sync(req, UV_FS_UTIME); + uv_fs_req_init_sync(loop, req, UV_FS_UTIME); fs__utime(req, path, atime, mtime); } @@ -726,15 +765,16 @@ int uv_fs_utime(uv_fs_t* req, const char* path, double atime, double mtime, uv_f } -int uv_fs_futime(uv_fs_t* req, uv_file file, double atime, double mtime, uv_fs_cb cb) { +int uv_fs_futime(uv_loop_t* loop, uv_fs_t* req, uv_file file, double atime, + double mtime, uv_fs_cb cb) { if (cb) { - uv_fs_req_init_async(req, UV_FS_FUTIME, cb); + uv_fs_req_init_async(loop, req, UV_FS_FUTIME, cb); WRAP_REQ_ARGS1(req, file); req->arg4 = (ssize_t)atime; req->arg5 = (ssize_t)mtime; - QUEUE_FS_TP_JOB(req); + QUEUE_FS_TP_JOB(loop, req); } else { - uv_fs_req_init_sync(req, UV_FS_FUTIME); + uv_fs_req_init_sync(loop, req, UV_FS_FUTIME); fs__futime(req, file, atime, mtime); } @@ -742,13 +782,15 @@ int uv_fs_futime(uv_fs_t* req, uv_file file, double atime, double mtime, uv_fs_c } -void uv_process_fs_req(uv_fs_t* req) { +void uv_process_fs_req(uv_loop_t* loop, uv_fs_t* req) { assert(req->cb); req->cb(req); } void uv_fs_req_cleanup(uv_fs_t* req) { + uv_loop_t* loop = req->loop; + if (req->flags & UV_FS_CLEANEDUP) { return; } @@ -769,7 +811,7 @@ void uv_fs_req_cleanup(uv_fs_t* req) { } if (req->flags & UV_FS_ASYNC_QUEUED) { - uv_unref(); + uv_unref(loop); } req->flags |= UV_FS_CLEANEDUP; diff --git a/deps/uv/src/win/getaddrinfo.c b/deps/uv/src/win/getaddrinfo.c index 609a30d72..b2bcc2f54 100644 --- a/deps/uv/src/win/getaddrinfo.c +++ b/deps/uv/src/win/getaddrinfo.c @@ -61,34 +61,38 @@ */ 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_EAINONAME; - 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); + 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_EAINONAME; + 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* handle = (uv_getaddrinfo_t*)parameter; + uv_getaddrinfo_t* handle = (uv_getaddrinfo_t*) parameter; + uv_loop_t* loop = handle->loop; int ret; assert(handle != NULL); if (handle != NULL) { /* call OS function on this thread */ - ret = GetAddrInfoW(handle->node, handle->service, handle->hints, &handle->res); + ret = GetAddrInfoW(handle->node, + handle->service, + handle->hints, + &handle->res); handle->retcode = ret; /* post getaddrinfo completed */ - POST_COMPLETION_FOR_REQ(&handle->getadddrinfo_req); + POST_COMPLETION_FOR_REQ(loop, &handle->getadddrinfo_req); } return 0; @@ -104,7 +108,8 @@ static DWORD WINAPI getaddrinfo_thread_proc(void* parameter) { * and copy all structs and referenced strings into the one block. * Each size calculation is adjusted to avoid unaligned pointers. */ -void uv_process_getaddrinfo_req(uv_getaddrinfo_t* handle, uv_req_t* req) { +void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t* handle, + uv_req_t* req) { int addrinfo_len = 0; int name_len = 0; size_t addrinfo_struct_len = ALIGNED_SIZE(sizeof(struct addrinfo)); @@ -126,7 +131,8 @@ void uv_process_getaddrinfo_req(uv_getaddrinfo_t* handle, uv_req_t* req) { /* first calculate required length */ addrinfow_ptr = handle->res; while (addrinfow_ptr != NULL) { - addrinfo_len += addrinfo_struct_len + ALIGNED_SIZE(addrinfow_ptr->ai_addrlen); + addrinfo_len += addrinfo_struct_len + + ALIGNED_SIZE(addrinfow_ptr->ai_addrlen); if (addrinfow_ptr->ai_canonname != NULL) { name_len = uv_utf16_to_utf8(addrinfow_ptr->ai_canonname, -1, NULL, 0); if (name_len == 0) { @@ -163,7 +169,8 @@ void uv_process_getaddrinfo_req(uv_getaddrinfo_t* handle, uv_req_t* req) { /* copy sockaddr */ if (addrinfo_ptr->ai_addrlen > 0) { - assert(cur_ptr + addrinfo_ptr->ai_addrlen <= alloc_ptr + addrinfo_len); + assert(cur_ptr + addrinfo_ptr->ai_addrlen <= + alloc_ptr + addrinfo_len); memcpy(cur_ptr, addrinfow_ptr->ai_addr, addrinfo_ptr->ai_addrlen); addrinfo_ptr->ai_addr = (struct sockaddr*)cur_ptr; cur_ptr += ALIGNED_SIZE(addrinfo_ptr->ai_addrlen); @@ -171,10 +178,16 @@ void uv_process_getaddrinfo_req(uv_getaddrinfo_t* handle, uv_req_t* req) { /* convert canonical name to UTF-8 */ if (addrinfow_ptr->ai_canonname != NULL) { - name_len = uv_utf16_to_utf8(addrinfow_ptr->ai_canonname, -1, NULL, 0); + name_len = uv_utf16_to_utf8(addrinfow_ptr->ai_canonname, + -1, + NULL, + 0); assert(name_len > 0); assert(cur_ptr + name_len <= alloc_ptr + addrinfo_len); - name_len = uv_utf16_to_utf8(addrinfow_ptr->ai_canonname, -1, cur_ptr, name_len); + name_len = uv_utf16_to_utf8(addrinfow_ptr->ai_canonname, + -1, + cur_ptr, + name_len); assert(name_len > 0); addrinfo_ptr->ai_canonname = cur_ptr; cur_ptr += ALIGNED_SIZE(name_len); @@ -208,7 +221,7 @@ complete: free(alloc_ptr); } - uv_unref(); + uv_unref(loop); } @@ -216,7 +229,8 @@ complete: * Entry point for getaddrinfo * we convert the UTF-8 strings to UNICODE * and save the UNICODE string pointers in the handle - * We also copy hints so that caller does not need to keep memory until the callback. + * 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 error code if validation fails * @@ -224,7 +238,8 @@ complete: * and copy all structs and referenced strings into the one block. * Each size calculation is adjusted to avoid unaligned pointers. */ -int uv_getaddrinfo(uv_getaddrinfo_t* handle, +int uv_getaddrinfo(uv_loop_t* loop, + uv_getaddrinfo_t* handle, uv_getaddrinfo_cb getaddrinfo_cb, const char* node, const char* service, @@ -236,27 +251,29 @@ int uv_getaddrinfo(uv_getaddrinfo_t* handle, if (handle == NULL || getaddrinfo_cb == NULL || (node == NULL && service == NULL)) { - uv_set_sys_error(WSAEINVAL); + uv_set_sys_error(loop, WSAEINVAL); goto error; } handle->getaddrinfo_cb = getaddrinfo_cb; handle->res = NULL; handle->type = UV_GETADDRINFO; + handle->loop = loop; /* calculate required memory size for all input values */ if (node != NULL) { nodesize = ALIGNED_SIZE(uv_utf8_to_utf16(node, NULL, 0) * sizeof(wchar_t)); if (nodesize == 0) { - uv_set_sys_error(GetLastError()); + uv_set_sys_error(loop, GetLastError()); goto error; } } if (service != NULL) { - servicesize = ALIGNED_SIZE(uv_utf8_to_utf16(service, NULL, 0) * sizeof(wchar_t)); + servicesize = ALIGNED_SIZE(uv_utf8_to_utf16(service, NULL, 0) * + sizeof(wchar_t)); if (servicesize == 0) { - uv_set_sys_error(GetLastError()); + uv_set_sys_error(loop, GetLastError()); goto error; } } @@ -267,18 +284,21 @@ int uv_getaddrinfo(uv_getaddrinfo_t* handle, /* allocate memory for inputs, and partition it as needed */ alloc_ptr = (char*)malloc(nodesize + servicesize + hintssize); if (!alloc_ptr) { - uv_set_sys_error(WSAENOBUFS); + uv_set_sys_error(loop, WSAENOBUFS); goto error; } /* save alloc_ptr now so we can free if error */ handle->alloc = (void*)alloc_ptr; - /* convert node string to UTF16 into allocated memory and save pointer in handle */ + /* convert node string to UTF16 into allocated memory and save pointer in */ + /* handle */ if (node != NULL) { handle->node = (wchar_t*)alloc_ptr; - if (uv_utf8_to_utf16(node, (wchar_t*)alloc_ptr, nodesize / sizeof(wchar_t)) == 0) { - uv_set_sys_error(GetLastError()); + if (uv_utf8_to_utf16(node, + (wchar_t*) alloc_ptr, + nodesize / sizeof(wchar_t)) == 0) { + uv_set_sys_error(loop, GetLastError()); goto error; } alloc_ptr += nodesize; @@ -286,11 +306,14 @@ int uv_getaddrinfo(uv_getaddrinfo_t* handle, handle->node = NULL; } - /* convert service string to UTF16 into allocated memory and save pointer in handle */ + /* convert service string to UTF16 into allocated memory and save pointer */ + /* in handle */ if (service != NULL) { handle->service = (wchar_t*)alloc_ptr; - if (uv_utf8_to_utf16(service, (wchar_t*)alloc_ptr, servicesize / sizeof(wchar_t)) == 0) { - uv_set_sys_error(GetLastError()); + if (uv_utf8_to_utf16(service, + (wchar_t*) alloc_ptr, + servicesize / sizeof(wchar_t)) == 0) { + uv_set_sys_error(loop, GetLastError()); goto error; } alloc_ptr += servicesize; @@ -314,17 +337,19 @@ int uv_getaddrinfo(uv_getaddrinfo_t* handle, } /* init request for Post handling */ - uv_req_init(&handle->getadddrinfo_req); + uv_req_init(loop, &handle->getadddrinfo_req); handle->getadddrinfo_req.data = handle; handle->getadddrinfo_req.type = UV_GETADDRINFO_REQ; /* Ask thread to run. Treat this as a long operation */ - if (QueueUserWorkItem(&getaddrinfo_thread_proc, handle, WT_EXECUTELONGFUNCTION) == 0) { - uv_set_sys_error(GetLastError()); + if (QueueUserWorkItem(&getaddrinfo_thread_proc, + handle, + WT_EXECUTELONGFUNCTION) == 0) { + uv_set_sys_error(loop, GetLastError()); goto error; } - uv_ref(); + uv_ref(loop); return 0; diff --git a/deps/uv/src/win/handle.c b/deps/uv/src/win/handle.c index 350623887..c11b9f820 100644 --- a/deps/uv/src/win/handle.c +++ b/deps/uv/src/win/handle.c @@ -40,15 +40,17 @@ int uv_is_active(uv_handle_t* handle) { int uv_getsockname(uv_handle_t* handle, struct sockaddr* name, int* namelen) { + uv_loop_t* loop = handle->loop; + switch (handle->type) { case UV_TCP: - return uv_tcp_getsockname((uv_tcp_t*) handle, name, namelen); + return uv_tcp_getsockname(loop, (uv_tcp_t*) handle, name, namelen); case UV_UDP: - return uv_udp_getsockname((uv_udp_t*) handle, name, namelen); + return uv_udp_getsockname(loop, (uv_udp_t*) handle, name, namelen); default: - uv_set_sys_error(WSAENOTSOCK); + uv_set_sys_error(loop, WSAENOTSOCK); return -1; } } @@ -60,6 +62,8 @@ void uv_close(uv_handle_t* handle, uv_close_cb cb) { uv_udp_t* udp; uv_process_t* process; + uv_loop_t* loop = handle->loop; + if (handle->flags & UV_HANDLE_CLOSING) { return; } @@ -80,7 +84,7 @@ void uv_close(uv_handle_t* handle, uv_close_cb cb) { tcp->flags &= ~(UV_HANDLE_READING | UV_HANDLE_LISTENING); closesocket(tcp->socket); if (tcp->reqs_pending == 0) { - uv_want_endgame(handle); + uv_want_endgame(loop, handle); } return; @@ -89,7 +93,7 @@ void uv_close(uv_handle_t* handle, uv_close_cb cb) { pipe->flags &= ~(UV_HANDLE_READING | UV_HANDLE_LISTENING); close_pipe(pipe, NULL, NULL); if (pipe->reqs_pending == 0) { - uv_want_endgame(handle); + uv_want_endgame(loop, handle); } return; @@ -98,39 +102,39 @@ void uv_close(uv_handle_t* handle, uv_close_cb cb) { uv_udp_recv_stop(udp); closesocket(udp->socket); if (udp->reqs_pending == 0) { - uv_want_endgame(handle); + uv_want_endgame(loop, handle); } return; case UV_TIMER: uv_timer_stop((uv_timer_t*)handle); - uv_want_endgame(handle); + uv_want_endgame(loop, handle); return; case UV_PREPARE: uv_prepare_stop((uv_prepare_t*)handle); - uv_want_endgame(handle); + uv_want_endgame(loop, handle); return; case UV_CHECK: uv_check_stop((uv_check_t*)handle); - uv_want_endgame(handle); + uv_want_endgame(loop, handle); return; case UV_IDLE: uv_idle_stop((uv_idle_t*)handle); - uv_want_endgame(handle); + uv_want_endgame(loop, handle); return; case UV_ASYNC: if (!((uv_async_t*)handle)->async_sent) { - uv_want_endgame(handle); + uv_want_endgame(loop, handle); } return; case UV_PROCESS: process = (uv_process_t*)handle; - uv_process_close(process); + uv_process_close(loop, process); return; default: @@ -140,54 +144,54 @@ void uv_close(uv_handle_t* handle, uv_close_cb cb) { } -void uv_want_endgame(uv_handle_t* handle) { +void uv_want_endgame(uv_loop_t* loop, uv_handle_t* handle) { if (!(handle->flags & UV_HANDLE_ENDGAME_QUEUED)) { handle->flags |= UV_HANDLE_ENDGAME_QUEUED; - handle->endgame_next = LOOP->endgame_handles; - LOOP->endgame_handles = handle; + handle->endgame_next = loop->endgame_handles; + loop->endgame_handles = handle; } } -void uv_process_endgames() { +void uv_process_endgames(uv_loop_t* loop) { uv_handle_t* handle; - while (LOOP->endgame_handles) { - handle = LOOP->endgame_handles; - LOOP->endgame_handles = handle->endgame_next; + while (loop->endgame_handles) { + handle = loop->endgame_handles; + loop->endgame_handles = handle->endgame_next; handle->flags &= ~UV_HANDLE_ENDGAME_QUEUED; switch (handle->type) { case UV_TCP: - uv_tcp_endgame((uv_tcp_t*)handle); + uv_tcp_endgame(loop, (uv_tcp_t*) handle); break; case UV_NAMED_PIPE: - uv_pipe_endgame((uv_pipe_t*)handle); + uv_pipe_endgame(loop, (uv_pipe_t*) handle); break; case UV_UDP: - uv_udp_endgame((uv_udp_t*) handle); + uv_udp_endgame(loop, (uv_udp_t*) handle); break; case UV_TIMER: - uv_timer_endgame((uv_timer_t*)handle); + uv_timer_endgame(loop, (uv_timer_t*) handle); break; case UV_PREPARE: case UV_CHECK: case UV_IDLE: - uv_loop_watcher_endgame(handle); + uv_loop_watcher_endgame(loop, handle); break; case UV_ASYNC: - uv_async_endgame((uv_async_t*)handle); + uv_async_endgame(loop, (uv_async_t*) handle); break; case UV_PROCESS: - uv_process_endgame((uv_process_t*)handle); + uv_process_endgame(loop, (uv_process_t*) handle); break; default: diff --git a/deps/uv/src/win/internal.h b/deps/uv/src/win/internal.h index 50b9368f2..a771cdc09 100644 --- a/deps/uv/src/win/internal.h +++ b/deps/uv/src/win/internal.h @@ -33,55 +33,10 @@ /* * Timers */ -RB_HEAD(uv_timer_tree_s, uv_timer_s); +void uv_timer_endgame(uv_loop_t* loop, uv_timer_t* handle); -void uv_timer_endgame(uv_timer_t* handle); - -DWORD uv_get_poll_timeout(); -void uv_process_timers(); - - -/* - * Core - */ - -/* Loop state struct. We don't support multiplicity right now, but this */ -/* should help when we get to that. */ -typedef struct uv_loop_s { - /* The loop's I/O completion port */ - HANDLE iocp; - /* Reference count that keeps the event loop alive */ - int refs; - /* The current time according to the event loop. in msecs. */ - int64_t time; - /* Tail of a single-linked circular queue of pending reqs. If the queue */ - /* is empty, tail_ is NULL. If there is only one item, */ - /* tail_->next_req == tail_ */ - uv_req_t* pending_reqs_tail; - /* Head of a single-linked list of closed handles */ - uv_handle_t* endgame_handles; - /* The head of the timers tree */ - struct uv_timer_tree_s timers; - /* Lists of active loop (prepare / check / idle) watchers */ - uv_prepare_t* prepare_handles; - uv_check_t* check_handles; - uv_idle_t* idle_handles; - /* This pointer will refer to the prepare/check/idle handle whose */ - /* callback is scheduled to be called next. This is needed to allow */ - /* safe removal from one of the lists above while that list being */ - /* iterated over. */ - uv_prepare_t* next_prepare_handle; - uv_check_t* next_check_handle; - uv_idle_t* next_idle_handle; - /* Last error code */ - uv_err_t last_error; - /* Error string most recently returned by uv_strerror() */ - char* err_str; -} uv_loop_t; - -extern uv_loop_t uv_main_loop_; - -#define LOOP (&uv_main_loop_) +DWORD uv_get_poll_timeout(uv_loop_t* loop); +void uv_process_timers(uv_loop_t* loop); /* @@ -110,8 +65,8 @@ extern uv_loop_t uv_main_loop_; #define UV_HANDLE_SYNC_BYPASS_IOCP 0x40000 #define UV_HANDLE_ZERO_READ 0x80000 -void uv_want_endgame(uv_handle_t* handle); -void uv_process_endgames(); +void uv_want_endgame(uv_loop_t* loop, uv_handle_t* handle); +void uv_process_endgames(uv_loop_t* loop); #define DECREASE_PENDING_REQ_COUNT(handle) \ do { \ @@ -120,7 +75,7 @@ void uv_process_endgames(); \ if (handle->flags & UV_HANDLE_CLOSING && \ handle->reqs_pending == 0) { \ - uv_want_endgame((uv_handle_t*)handle); \ + uv_want_endgame(loop, (uv_handle_t*)handle); \ } \ } while (0) @@ -134,15 +89,15 @@ void uv_process_endgames(); /* * Requests */ -void uv_req_init(uv_req_t* req); +void uv_req_init(uv_loop_t* loop, uv_req_t* req); uv_req_t* uv_overlapped_to_req(OVERLAPPED* overlapped); -void uv_insert_pending_req(uv_req_t* req); -void uv_process_reqs(); +void uv_insert_pending_req(uv_loop_t* loop, uv_req_t* req); +void uv_process_reqs(uv_loop_t* loop); -#define POST_COMPLETION_FOR_REQ(req) \ - if (!PostQueuedCompletionStatus(LOOP->iocp, \ +#define POST_COMPLETION_FOR_REQ(loop, req) \ + if (!PostQueuedCompletionStatus((loop)->iocp, \ 0, \ 0, \ &((req)->overlapped))) { \ @@ -153,7 +108,7 @@ void uv_process_reqs(); /* * Streams */ -void uv_stream_init(uv_stream_t* handle); +void uv_stream_init(uv_loop_t* loop, uv_stream_t* handle); void uv_connection_init(uv_stream_t* handle); size_t uv_count_bufs(uv_buf_t bufs[], int count); @@ -166,75 +121,89 @@ int uv_tcp_listen(uv_tcp_t* handle, int backlog, uv_connection_cb cb); int uv_tcp_accept(uv_tcp_t* server, uv_tcp_t* client); int uv_tcp_read_start(uv_tcp_t* handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb); -int uv_tcp_write(uv_write_t* req, uv_tcp_t* handle, uv_buf_t bufs[], - int bufcnt, uv_write_cb cb); -int uv_tcp_getsockname(uv_tcp_t* handle, struct sockaddr* name, int* namelen); +int uv_tcp_write(uv_loop_t* loop, uv_write_t* req, uv_tcp_t* handle, + uv_buf_t bufs[], int bufcnt, uv_write_cb cb); +int uv_tcp_getsockname(uv_loop_t* loop, uv_tcp_t* handle, + struct sockaddr* name, int* namelen); -void uv_process_tcp_read_req(uv_tcp_t* handle, uv_req_t* req); -void uv_process_tcp_write_req(uv_tcp_t* handle, uv_write_t* req); -void uv_process_tcp_accept_req(uv_tcp_t* handle, uv_req_t* req); -void uv_process_tcp_connect_req(uv_tcp_t* handle, uv_connect_t* req); +void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle, uv_req_t* req); +void uv_process_tcp_write_req(uv_loop_t* loop, uv_tcp_t* handle, + uv_write_t* req); +void uv_process_tcp_accept_req(uv_loop_t* loop, uv_tcp_t* handle, + uv_req_t* req); +void uv_process_tcp_connect_req(uv_loop_t* loop, uv_tcp_t* handle, + uv_connect_t* req); -void uv_tcp_endgame(uv_tcp_t* handle); +void uv_tcp_endgame(uv_loop_t* loop, uv_tcp_t* handle); /* * UDP */ -int uv_udp_getsockname(uv_udp_t* handle, struct sockaddr* name, int* namelen); +int uv_udp_getsockname(uv_loop_t* loop, uv_udp_t* handle, + struct sockaddr* name, int* namelen); -void uv_process_udp_recv_req(uv_udp_t* handle, uv_req_t* req); -void uv_process_udp_send_req(uv_udp_t* handle, uv_udp_send_t* req); +void uv_process_udp_recv_req(uv_loop_t* loop, uv_udp_t* handle, uv_req_t* req); +void uv_process_udp_send_req(uv_loop_t* loop, uv_udp_t* handle, + uv_udp_send_t* req); -void uv_udp_endgame(uv_udp_t* handle); +void uv_udp_endgame(uv_loop_t* loop, uv_udp_t* handle); /* * Pipes */ -int uv_pipe_init_with_handle(uv_pipe_t* handle, HANDLE pipeHandle); -int uv_stdio_pipe_server(uv_pipe_t* handle, DWORD access, char* name, size_t nameSize); +int uv_pipe_init_with_handle(uv_loop_t* loop, uv_pipe_t* handle, + HANDLE pipeHandle); +int uv_stdio_pipe_server(uv_loop_t* loop, uv_pipe_t* handle, DWORD access, + char* name, size_t nameSize); void close_pipe(uv_pipe_t* handle, int* status, uv_err_t* err); -void uv_pipe_endgame(uv_pipe_t* handle); +void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle); int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb); int uv_pipe_accept(uv_pipe_t* server, uv_pipe_t* client); int uv_pipe_read_start(uv_pipe_t* handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb); -int uv_pipe_write(uv_write_t* req, uv_pipe_t* handle, uv_buf_t bufs[], - int bufcnt, uv_write_cb cb); - -void uv_process_pipe_read_req(uv_pipe_t* handle, uv_req_t* req); -void uv_process_pipe_write_req(uv_pipe_t* handle, uv_write_t* req); -void uv_process_pipe_accept_req(uv_pipe_t* handle, uv_req_t* raw_req); -void uv_process_pipe_connect_req(uv_pipe_t* handle, uv_connect_t* req); -void uv_process_pipe_shutdown_req(uv_pipe_t* handle, uv_shutdown_t* req); +int uv_pipe_write(uv_loop_t* loop, uv_write_t* req, uv_pipe_t* handle, + uv_buf_t bufs[], int bufcnt, uv_write_cb cb); + +void uv_process_pipe_read_req(uv_loop_t* loop, uv_pipe_t* handle, + uv_req_t* req); +void uv_process_pipe_write_req(uv_loop_t* loop, uv_pipe_t* handle, + uv_write_t* req); +void uv_process_pipe_accept_req(uv_loop_t* loop, uv_pipe_t* handle, + uv_req_t* raw_req); +void uv_process_pipe_connect_req(uv_loop_t* loop, uv_pipe_t* handle, + uv_connect_t* req); +void uv_process_pipe_shutdown_req(uv_loop_t* loop, uv_pipe_t* handle, + uv_shutdown_t* req); /* * Loop watchers */ -void uv_loop_watcher_endgame(uv_handle_t* handle); +void uv_loop_watcher_endgame(uv_loop_t* loop, uv_handle_t* handle); -void uv_prepare_invoke(); -void uv_check_invoke(); -void uv_idle_invoke(); +void uv_prepare_invoke(uv_loop_t* loop); +void uv_check_invoke(uv_loop_t* loop); +void uv_idle_invoke(uv_loop_t* loop); /* * Async watcher */ -void uv_async_endgame(uv_async_t* handle); +void uv_async_endgame(uv_loop_t* loop, uv_async_t* handle); -void uv_process_async_wakeup_req(uv_async_t* handle, uv_req_t* req); +void uv_process_async_wakeup_req(uv_loop_t* loop, uv_async_t* handle, + uv_req_t* req); /* * Spawn */ -void uv_process_proc_exit(uv_process_t* handle); -void uv_process_proc_close(uv_process_t* handle); -void uv_process_close(uv_process_t* handle); -void uv_process_endgame(uv_process_t* handle); +void uv_process_proc_exit(uv_loop_t* loop, uv_process_t* handle); +void uv_process_proc_close(uv_loop_t* loop, uv_process_t* handle); +void uv_process_close(uv_loop_t* loop, uv_process_t* handle); +void uv_process_endgame(uv_loop_t* loop, uv_process_t* handle); /* @@ -242,26 +211,29 @@ void uv_process_endgame(uv_process_t* handle); */ typedef struct uv_ares_action_s uv_ares_action_t; -void uv_process_ares_event_req(uv_ares_action_t* handle, uv_req_t* req); -void uv_process_ares_cleanup_req(uv_ares_task_t* handle, uv_req_t* req); +void uv_process_ares_event_req(uv_loop_t* loop, uv_ares_action_t* handle, + uv_req_t* req); +void uv_process_ares_cleanup_req(uv_loop_t* loop, uv_ares_task_t* handle, + uv_req_t* req); /* * Getaddrinfo */ -void uv_process_getaddrinfo_req(uv_getaddrinfo_t* handle, uv_req_t* req); +void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t* handle, + uv_req_t* req); /* * FS */ void uv_fs_init(); -void uv_process_fs_req(uv_fs_t* req); +void uv_process_fs_req(uv_loop_t* loop, uv_fs_t* req); /* * Threadpool */ -void uv_process_work_req(uv_work_t* req); +void uv_process_work_req(uv_loop_t* loop, uv_work_t* req); /* @@ -273,8 +245,8 @@ void uv_fatal_error(const int errorno, const char* syscall); uv_err_code uv_translate_sys_error(int sys_errno); uv_err_t uv_new_sys_error(int sys_errno); -void uv_set_sys_error(int sys_errno); -void uv_set_error(uv_err_code code, int sys_errno); +void uv_set_sys_error(uv_loop_t* loop, int sys_errno); +void uv_set_error(uv_loop_t* loop, uv_err_code code, int sys_errno); #define SET_REQ_STATUS(req, status) \ (req)->overlapped.Internal = (ULONG_PTR) (status) diff --git a/deps/uv/src/win/loop-watcher.c b/deps/uv/src/win/loop-watcher.c index 1344cde0b..15bfae369 100644 --- a/deps/uv/src/win/loop-watcher.c +++ b/deps/uv/src/win/loop-watcher.c @@ -26,7 +26,7 @@ #include "internal.h" -void uv_loop_watcher_endgame(uv_handle_t* handle) { +void uv_loop_watcher_endgame(uv_loop_t* loop, uv_handle_t* handle) { if (handle->flags & UV_HANDLE_CLOSING) { assert(!(handle->flags & UV_HANDLE_CLOSED)); handle->flags |= UV_HANDLE_CLOSED; @@ -35,26 +35,28 @@ void uv_loop_watcher_endgame(uv_handle_t* handle) { handle->close_cb(handle); } - uv_unref(); + uv_unref(loop); } } #define UV_LOOP_WATCHER_DEFINE(name, NAME) \ - int uv_##name##_init(uv_##name##_t* handle) { \ + int uv_##name##_init(uv_loop_t* loop, uv_##name##_t* handle) { \ handle->type = UV_##NAME; \ + handle->loop = loop; \ handle->flags = 0; \ \ - uv_ref(); \ + uv_ref(loop); \ \ - uv_counters()->handle_init++; \ - uv_counters()->prepare_init++; \ + loop->counters.handle_init++; \ + loop->counters.##name##_init++; \ \ return 0; \ } \ \ \ int uv_##name##_start(uv_##name##_t* handle, uv_##name##_cb cb) { \ + uv_loop_t* loop = handle->loop; \ uv_##name##_t* old_head; \ \ assert(handle->type == UV_##NAME); \ @@ -62,7 +64,7 @@ void uv_loop_watcher_endgame(uv_handle_t* handle) { if (handle->flags & UV_HANDLE_ACTIVE) \ return 0; \ \ - old_head = LOOP->name##_handles; \ + old_head = loop->name##_handles; \ \ handle->name##_next = old_head; \ handle->name##_prev = NULL; \ @@ -71,7 +73,7 @@ void uv_loop_watcher_endgame(uv_handle_t* handle) { old_head->name##_prev = handle; \ } \ \ - LOOP->name##_handles = handle; \ + loop->name##_handles = handle; \ \ handle->name##_cb = cb; \ handle->flags |= UV_HANDLE_ACTIVE; \ @@ -81,19 +83,21 @@ void uv_loop_watcher_endgame(uv_handle_t* handle) { \ \ int uv_##name##_stop(uv_##name##_t* handle) { \ + uv_loop_t* loop = handle->loop; \ + \ assert(handle->type == UV_##NAME); \ \ if (!(handle->flags & UV_HANDLE_ACTIVE)) \ return 0; \ \ /* Update loop head if needed */ \ - if (LOOP->name##_handles == handle) { \ - LOOP->name##_handles = handle->name##_next; \ + if (loop->name##_handles == handle) { \ + loop->name##_handles = handle->name##_next; \ } \ \ /* Update the iterator-next pointer of needed */ \ - if (LOOP->next_##name##_handle == handle) { \ - LOOP->next_##name##_handle = handle->name##_next; \ + if (loop->next_##name##_handle == handle) { \ + loop->next_##name##_handle = handle->name##_next; \ } \ \ if (handle->name##_prev) { \ @@ -109,14 +113,14 @@ void uv_loop_watcher_endgame(uv_handle_t* handle) { } \ \ \ - void uv_##name##_invoke() { \ + void uv_##name##_invoke(uv_loop_t* loop) { \ uv_##name##_t* handle; \ \ - LOOP->next_##name##_handle = LOOP->name##_handles; \ + (loop)->next_##name##_handle = (loop)->name##_handles; \ \ - while (LOOP->next_##name##_handle != NULL) { \ - handle = LOOP->next_##name##_handle; \ - LOOP->next_##name##_handle = handle->name##_next; \ + while ((loop)->next_##name##_handle != NULL) { \ + handle = (loop)->next_##name##_handle; \ + (loop)->next_##name##_handle = handle->name##_next; \ \ handle->name##_cb(handle, 0); \ } \ diff --git a/deps/uv/src/win/pipe.c b/deps/uv/src/win/pipe.c index 739516021..87854f614 100644 --- a/deps/uv/src/win/pipe.c +++ b/deps/uv/src/win/pipe.c @@ -51,22 +51,23 @@ static void uv_unique_pipe_name(char* ptr, char* name, size_t size) { } -int uv_pipe_init(uv_pipe_t* handle) { - uv_stream_init((uv_stream_t*)handle); +int uv_pipe_init(uv_loop_t* loop, uv_pipe_t* handle) { + uv_stream_init(loop, (uv_stream_t*)handle); handle->type = UV_NAMED_PIPE; handle->reqs_pending = 0; handle->handle = INVALID_HANDLE_VALUE; handle->name = NULL; - uv_counters()->pipe_init++; + loop->counters.pipe_init++; return 0; } -int uv_pipe_init_with_handle(uv_pipe_t* handle, HANDLE pipeHandle) { - int err = uv_pipe_init(handle); +int uv_pipe_init_with_handle(uv_loop_t* loop, uv_pipe_t* handle, + HANDLE pipeHandle) { + int err = uv_pipe_init(loop, handle); if (!err) { /* @@ -88,7 +89,8 @@ static void uv_pipe_connection_init(uv_pipe_t* handle) { } -int uv_stdio_pipe_server(uv_pipe_t* handle, DWORD access, char* name, size_t nameSize) { +int uv_stdio_pipe_server(uv_loop_t* loop, uv_pipe_t* handle, DWORD access, + char* name, size_t nameSize) { HANDLE pipeHandle; int errno; int err; @@ -98,13 +100,9 @@ int uv_stdio_pipe_server(uv_pipe_t* handle, DWORD access, char* name, size_t nam uv_unique_pipe_name(ptr, name, nameSize); pipeHandle = CreateNamedPipeA(name, - access | FILE_FLAG_OVERLAPPED | FILE_FLAG_FIRST_PIPE_INSTANCE, - PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, - 1, - 65536, - 65536, - 0, - NULL); + access | FILE_FLAG_OVERLAPPED | FILE_FLAG_FIRST_PIPE_INSTANCE, + PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, 1, 65536, 65536, 0, + NULL); if (pipeHandle != INVALID_HANDLE_VALUE) { /* No name collisions. We're done. */ @@ -113,7 +111,7 @@ int uv_stdio_pipe_server(uv_pipe_t* handle, DWORD access, char* name, size_t nam errno = GetLastError(); if (errno != ERROR_PIPE_BUSY && errno != ERROR_ACCESS_DENIED) { - uv_set_sys_error(errno); + uv_set_sys_error(loop, errno); err = -1; goto done; } @@ -123,10 +121,10 @@ int uv_stdio_pipe_server(uv_pipe_t* handle, DWORD access, char* name, size_t nam } if (CreateIoCompletionPort(pipeHandle, - LOOP->iocp, + loop->iocp, (ULONG_PTR)handle, 0) == NULL) { - uv_set_sys_error(GetLastError()); + uv_set_sys_error(loop, GetLastError()); err = -1; goto done; } @@ -145,7 +143,8 @@ done: } -static int uv_set_pipe_handle(uv_pipe_t* handle, HANDLE pipeHandle) { +static int uv_set_pipe_handle(uv_loop_t* loop, uv_pipe_t* handle, + HANDLE pipeHandle) { DWORD mode = PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT; if (!SetNamedPipeHandleState(pipeHandle, &mode, NULL, NULL)) { @@ -153,7 +152,7 @@ static int uv_set_pipe_handle(uv_pipe_t* handle, HANDLE pipeHandle) { } if (CreateIoCompletionPort(pipeHandle, - LOOP->iocp, + loop->iocp, (ULONG_PTR)handle, 0) == NULL) { return -1; @@ -165,6 +164,7 @@ static int uv_set_pipe_handle(uv_pipe_t* handle, HANDLE pipeHandle) { static DWORD WINAPI pipe_shutdown_thread_proc(void* parameter) { int errno; + uv_loop_t* loop; uv_pipe_t* handle; uv_shutdown_t* req; @@ -172,17 +172,19 @@ static DWORD WINAPI pipe_shutdown_thread_proc(void* parameter) { assert(req); handle = (uv_pipe_t*) req->handle; assert(handle); + loop = handle->loop; + assert(loop); FlushFileBuffers(handle->handle); /* Post completed */ - POST_COMPLETION_FOR_REQ(req); + POST_COMPLETION_FOR_REQ(loop, req); return 0; } -void uv_pipe_endgame(uv_pipe_t* handle) { +void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) { unsigned int uv_alloced; DWORD result; uv_shutdown_t* req; @@ -207,7 +209,7 @@ void uv_pipe_endgame(uv_pipe_t* handle) { /* Failure */ handle->flags &= ~UV_HANDLE_SHUTTING; if (req->cb) { - uv_set_sys_error(pRtlNtStatusToDosError(nt_status)); + uv_set_sys_error(loop, pRtlNtStatusToDosError(nt_status)); req->cb(req, -1); } DECREASE_PENDING_REQ_COUNT(handle); @@ -218,7 +220,7 @@ void uv_pipe_endgame(uv_pipe_t* handle) { handle->flags |= UV_HANDLE_SHUT; /* Short-circuit, no need to call FlushFileBuffers. */ - uv_insert_pending_req((uv_req_t*) req); + uv_insert_pending_req(loop, (uv_req_t*) req); return; } @@ -234,7 +236,7 @@ void uv_pipe_endgame(uv_pipe_t* handle) { /* Failure. */ handle->flags &= ~UV_HANDLE_SHUTTING; if (req->cb) { - uv_set_sys_error(GetLastError()); + uv_set_sys_error(loop, GetLastError()); req->cb(req, -1); } DECREASE_PENDING_REQ_COUNT(handle); @@ -259,29 +261,30 @@ void uv_pipe_endgame(uv_pipe_t* handle) { free(handle); } - uv_unref(); + uv_unref(loop); } } /* Creates a pipe server. */ int uv_pipe_bind(uv_pipe_t* handle, const char* name) { + uv_loop_t* loop = handle->loop; int i, errno, nameSize; uv_pipe_accept_t* req; if (handle->flags & UV_HANDLE_BOUND) { - uv_set_sys_error(WSAEINVAL); + uv_set_sys_error(loop, WSAEINVAL); return -1; } if (!name) { - uv_set_sys_error(WSAEINVAL); + uv_set_sys_error(loop, WSAEINVAL); return -1; } for (i = 0; i < COUNTOF(handle->accept_reqs); i++) { req = &handle->accept_reqs[i]; - uv_req_init((uv_req_t*) req); + uv_req_init(loop, (uv_req_t*) req); req->type = UV_ACCEPT; req->data = handle; req->pipeHandle = INVALID_HANDLE_VALUE; @@ -296,7 +299,7 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) { } if (!uv_utf8_to_utf16(name, handle->name, nameSize / sizeof(wchar_t))) { - uv_set_sys_error(GetLastError()); + uv_set_sys_error(loop, GetLastError()); return -1; } @@ -305,28 +308,25 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) { * If this fails then there's already a pipe server for the given pipe name. */ handle->accept_reqs[0].pipeHandle = CreateNamedPipeW(handle->name, - PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | FILE_FLAG_FIRST_PIPE_INSTANCE, - PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, - PIPE_UNLIMITED_INSTANCES, - 65536, - 65536, - 0, - NULL); + PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | + FILE_FLAG_FIRST_PIPE_INSTANCE, + PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, + PIPE_UNLIMITED_INSTANCES, 65536, 65536, 0, NULL); if (handle->accept_reqs[0].pipeHandle == INVALID_HANDLE_VALUE) { errno = GetLastError(); if (errno == ERROR_ACCESS_DENIED) { - uv_set_error(UV_EADDRINUSE, errno); + uv_set_error(loop, UV_EADDRINUSE, errno); } else if (errno == ERROR_PATH_NOT_FOUND || errno == ERROR_INVALID_NAME) { - uv_set_error(UV_EACCESS, errno); + uv_set_error(loop, UV_EACCESS, errno); } else { - uv_set_sys_error(errno); + uv_set_sys_error(loop, errno); } goto error; } - if (uv_set_pipe_handle(handle, handle->accept_reqs[0].pipeHandle)) { - uv_set_sys_error(GetLastError()); + if (uv_set_pipe_handle(loop, handle, handle->accept_reqs[0].pipeHandle)) { + uv_set_sys_error(loop, GetLastError()); goto error; } @@ -354,15 +354,19 @@ error: static DWORD WINAPI pipe_connect_thread_proc(void* parameter) { HANDLE pipeHandle = INVALID_HANDLE_VALUE; int errno; + uv_loop_t* loop; uv_pipe_t* handle; uv_connect_t* req; - req = (uv_connect_t*)parameter; + req = (uv_connect_t*) parameter; assert(req); - handle = (uv_pipe_t*)req->handle; + handle = (uv_pipe_t*) req->handle; assert(handle); + loop = handle->loop; + assert(loop); - /* We're here because CreateFile on a pipe returned ERROR_PIPE_BUSY. We wait for the pipe to become available with WaitNamedPipe. */ + /* We're here because CreateFile on a pipe returned ERROR_PIPE_BUSY. */ + /* We wait for the pipe to become available with WaitNamedPipe. */ while (WaitNamedPipeW(handle->name, 30000)) { /* The pipe is now available, try to connect. */ pipeHandle = CreateFileW(handle->name, @@ -380,7 +384,8 @@ static DWORD WINAPI pipe_connect_thread_proc(void* parameter) { SwitchToThread(); } - if (pipeHandle != INVALID_HANDLE_VALUE && !uv_set_pipe_handle(handle, pipeHandle)) { + if (pipeHandle != INVALID_HANDLE_VALUE && + !uv_set_pipe_handle(loop, handle, pipeHandle)) { handle->handle = pipeHandle; SET_REQ_SUCCESS(req); } else { @@ -388,7 +393,7 @@ static DWORD WINAPI pipe_connect_thread_proc(void* parameter) { } /* Post completed */ - POST_COMPLETION_FOR_REQ(req); + POST_COMPLETION_FOR_REQ(loop, req); return 0; } @@ -396,12 +401,13 @@ static DWORD WINAPI pipe_connect_thread_proc(void* parameter) { int 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 errno, nameSize; HANDLE pipeHandle; handle->handle = INVALID_HANDLE_VALUE; - uv_req_init((uv_req_t*) req); + uv_req_init(loop, (uv_req_t*) req); req->type = UV_CONNECT; req->handle = (uv_stream_t*) handle; req->cb = cb; @@ -429,7 +435,9 @@ int uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle, if (pipeHandle == INVALID_HANDLE_VALUE) { if (GetLastError() == ERROR_PIPE_BUSY) { /* Wait for the server to make a pipe instance available. */ - if (!QueueUserWorkItem(&pipe_connect_thread_proc, req, WT_EXECUTELONGFUNCTION)) { + if (!QueueUserWorkItem(&pipe_connect_thread_proc, + req, + WT_EXECUTELONGFUNCTION)) { errno = GetLastError(); goto error; } @@ -443,7 +451,7 @@ int uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle, goto error; } - if (uv_set_pipe_handle((uv_pipe_t*)req->handle, pipeHandle)) { + if (uv_set_pipe_handle(loop, (uv_pipe_t*)req->handle, pipeHandle)) { errno = GetLastError(); goto error; } @@ -451,7 +459,7 @@ int uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle, handle->handle = pipeHandle; SET_REQ_SUCCESS(req); - uv_insert_pending_req((uv_req_t*) req); + uv_insert_pending_req(loop, (uv_req_t*) req); handle->reqs_pending++; return 0; @@ -464,12 +472,13 @@ error: if (pipeHandle != INVALID_HANDLE_VALUE) { CloseHandle(pipeHandle); } - uv_set_sys_error(errno); + uv_set_sys_error(loop, errno); return -1; } -/* Cleans up uv_pipe_t (server or connection) and all resources associated with it */ +/* Cleans up uv_pipe_t (server or connection) and all resources associated */ +/* with it. */ void close_pipe(uv_pipe_t* handle, int* status, uv_err_t* err) { int i; HANDLE pipeHandle; @@ -504,33 +513,30 @@ void close_pipe(uv_pipe_t* handle, int* status, uv_err_t* err) { } -static void uv_pipe_queue_accept(uv_pipe_t* handle, uv_pipe_accept_t* req, BOOL firstInstance) { +static void uv_pipe_queue_accept(uv_loop_t* loop, uv_pipe_t* handle, + uv_pipe_accept_t* req, BOOL firstInstance) { assert(handle->flags & UV_HANDLE_LISTENING); if (!firstInstance) { assert(req->pipeHandle == INVALID_HANDLE_VALUE); req->pipeHandle = CreateNamedPipeW(handle->name, - PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, - PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, - PIPE_UNLIMITED_INSTANCES, - 65536, - 65536, - 0, - NULL); + PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, + PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, + PIPE_UNLIMITED_INSTANCES, 65536, 65536, 0, NULL); if (req->pipeHandle == INVALID_HANDLE_VALUE) { SET_REQ_ERROR(req, GetLastError()); - uv_insert_pending_req((uv_req_t*) req); + uv_insert_pending_req(loop, (uv_req_t*) req); handle->reqs_pending++; return; } - if (uv_set_pipe_handle(handle, req->pipeHandle)) { + if (uv_set_pipe_handle(loop, handle, req->pipeHandle)) { CloseHandle(req->pipeHandle); req->pipeHandle = INVALID_HANDLE_VALUE; SET_REQ_ERROR(req, GetLastError()); - uv_insert_pending_req((uv_req_t*) req); + uv_insert_pending_req(loop, (uv_req_t*) req); handle->reqs_pending++; return; } @@ -541,7 +547,8 @@ static void uv_pipe_queue_accept(uv_pipe_t* handle, uv_pipe_accept_t* req, BOOL /* Prepare the overlapped structure. */ memset(&(req->overlapped), 0, sizeof(req->overlapped)); - if (!ConnectNamedPipe(req->pipeHandle, &req->overlapped) && GetLastError() != ERROR_IO_PENDING) { + if (!ConnectNamedPipe(req->pipeHandle, &req->overlapped) && + GetLastError() != ERROR_IO_PENDING) { if (GetLastError() == ERROR_PIPE_CONNECTED) { SET_REQ_SUCCESS(req); } else { @@ -550,7 +557,7 @@ static void uv_pipe_queue_accept(uv_pipe_t* handle, uv_pipe_accept_t* req, BOOL /* Make this req pending reporting an error. */ SET_REQ_ERROR(req, GetLastError()); } - uv_insert_pending_req((uv_req_t*) req); + uv_insert_pending_req(loop, (uv_req_t*) req); handle->reqs_pending++; return; } @@ -560,12 +567,14 @@ static void uv_pipe_queue_accept(uv_pipe_t* handle, uv_pipe_accept_t* req, BOOL int uv_pipe_accept(uv_pipe_t* server, uv_pipe_t* client) { - /* Find a connection instance that has been connected, but not yet accepted. */ + uv_loop_t* loop = server->loop; + /* Find a connection instance that has been connected, but not yet */ + /* accepted. */ uv_pipe_accept_t* req = server->pending_accepts; if (!req) { /* No valid connections found, so we error out. */ - uv_set_sys_error(WSAEWOULDBLOCK); + uv_set_sys_error(loop, WSAEWOULDBLOCK); return -1; } @@ -580,7 +589,7 @@ int uv_pipe_accept(uv_pipe_t* server, uv_pipe_t* client) { if (!(server->flags & UV_HANDLE_CLOSING) && !(server->flags & UV_HANDLE_GIVEN_OS_HANDLE)) { - uv_pipe_queue_accept(server, req, FALSE); + uv_pipe_queue_accept(loop, server, req, FALSE); } return 0; @@ -589,25 +598,27 @@ int uv_pipe_accept(uv_pipe_t* server, uv_pipe_t* client) { /* Starts listening for connections for the given pipe. */ int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) { + uv_loop_t* loop = handle->loop; + int i, errno; uv_pipe_accept_t* req; HANDLE pipeHandle; if (!(handle->flags & UV_HANDLE_BOUND) && !(handle->flags & UV_HANDLE_GIVEN_OS_HANDLE)) { - uv_set_error(UV_EINVAL, 0); + uv_set_error(loop, UV_EINVAL, 0); return -1; } if (handle->flags & UV_HANDLE_LISTENING || handle->flags & UV_HANDLE_READING) { - uv_set_error(UV_EALREADY, 0); + uv_set_error(loop, UV_EALREADY, 0); return -1; } if (!(handle->flags & UV_HANDLE_PIPESERVER) && !(handle->flags & UV_HANDLE_GIVEN_OS_HANDLE)) { - uv_set_error(UV_ENOTSUP, 0); + uv_set_error(loop, UV_ENOTSUP, 0); return -1; } @@ -619,24 +630,24 @@ int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) { pipeHandle = handle->handle; assert(pipeHandle != INVALID_HANDLE_VALUE); req = &handle->accept_reqs[0]; - uv_req_init((uv_req_t*) req); + uv_req_init(loop, (uv_req_t*) req); req->pipeHandle = pipeHandle; req->type = UV_ACCEPT; req->data = handle; req->next_pending = NULL; - if (uv_set_pipe_handle(handle, pipeHandle)) { - uv_set_sys_error(GetLastError()); + if (uv_set_pipe_handle(loop, handle, pipeHandle)) { + uv_set_sys_error(loop, GetLastError()); return -1; } - uv_pipe_queue_accept(handle, req, TRUE); + uv_pipe_queue_accept(loop, handle, req, TRUE); } else { /* First pipe handle should have already been created in uv_pipe_bind */ assert(handle->accept_reqs[0].pipeHandle != INVALID_HANDLE_VALUE); for (i = 0; i < COUNTOF(handle->accept_reqs); i++) { - uv_pipe_queue_accept(handle, &handle->accept_reqs[i], i == 0); + uv_pipe_queue_accept(loop, handle, &handle->accept_reqs[i], i == 0); } } @@ -644,7 +655,7 @@ int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) { } -static void uv_pipe_queue_read(uv_pipe_t* handle) { +static void uv_pipe_queue_read(uv_loop_t* loop, uv_pipe_t* handle) { uv_req_t* req; int result; @@ -666,7 +677,7 @@ static void uv_pipe_queue_read(uv_pipe_t* handle) { if (!result && GetLastError() != ERROR_IO_PENDING) { /* Make this req pending reporting an error. */ SET_REQ_ERROR(req, WSAGetLastError()); - uv_insert_pending_req(req); + uv_insert_pending_req(loop, req); handle->reqs_pending++; return; } @@ -679,19 +690,22 @@ static void uv_pipe_queue_read(uv_pipe_t* handle) { } -int uv_pipe_read_start(uv_pipe_t* handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb) { +int uv_pipe_read_start(uv_pipe_t* handle, uv_alloc_cb alloc_cb, + uv_read_cb read_cb) { + uv_loop_t* loop = handle->loop; + if (!(handle->flags & UV_HANDLE_CONNECTION)) { - uv_set_error(UV_EINVAL, 0); + uv_set_error(loop, UV_EINVAL, 0); return -1; } if (handle->flags & UV_HANDLE_READING) { - uv_set_error(UV_EALREADY, 0); + uv_set_error(loop, UV_EALREADY, 0); return -1; } if (handle->flags & UV_HANDLE_EOF) { - uv_set_error(UV_EOF, 0); + uv_set_error(loop, UV_EOF, 0); return -1; } @@ -702,34 +716,34 @@ int uv_pipe_read_start(uv_pipe_t* handle, uv_alloc_cb alloc_cb, uv_read_cb read_ /* If reading was stopped and then started again, there could stell be a */ /* read request pending. */ if (!(handle->flags & UV_HANDLE_READ_PENDING)) - uv_pipe_queue_read(handle); + uv_pipe_queue_read(loop, handle); return 0; } -int uv_pipe_write(uv_write_t* req, uv_pipe_t* handle, uv_buf_t bufs[], int bufcnt, - uv_write_cb cb) { +int uv_pipe_write(uv_loop_t* loop, uv_write_t* req, uv_pipe_t* handle, + uv_buf_t bufs[], int bufcnt, uv_write_cb cb) { int result; if (bufcnt != 1) { - uv_set_error(UV_ENOTSUP, 0); + uv_set_error(loop, UV_ENOTSUP, 0); return -1; } assert(handle->handle != INVALID_HANDLE_VALUE); if (!(handle->flags & UV_HANDLE_CONNECTION)) { - uv_set_error(UV_EINVAL, 0); + uv_set_error(loop, UV_EINVAL, 0); return -1; } if (handle->flags & UV_HANDLE_SHUTTING) { - uv_set_error(UV_EOF, 0); + uv_set_error(loop, UV_EOF, 0); return -1; } - uv_req_init((uv_req_t*) req); + uv_req_init(loop, (uv_req_t*) req); req->type = UV_WRITE; req->handle = (uv_stream_t*) handle; req->cb = cb; @@ -742,7 +756,7 @@ int uv_pipe_write(uv_write_t* req, uv_pipe_t* handle, uv_buf_t bufs[], int bufcn &req->overlapped); if (!result && GetLastError() != ERROR_IO_PENDING) { - uv_set_sys_error(GetLastError()); + uv_set_sys_error(loop, GetLastError()); return -1; } @@ -762,7 +776,8 @@ int uv_pipe_write(uv_write_t* req, uv_pipe_t* handle, uv_buf_t bufs[], int bufcn } -static void uv_pipe_read_eof(uv_pipe_t* handle, uv_buf_t buf) { +static void uv_pipe_read_eof(uv_loop_t* loop, uv_pipe_t* handle, + uv_buf_t buf) { /* If there is an eof timer running, we don't need it any more, */ /* so discard it. */ eof_timer_destroy(handle); @@ -770,33 +785,36 @@ static void uv_pipe_read_eof(uv_pipe_t* handle, uv_buf_t buf) { handle->flags |= UV_HANDLE_EOF; uv_read_stop((uv_stream_t*) handle); - uv_set_error(UV_EOF, 0); + uv_set_error(loop, UV_EOF, 0); handle->read_cb((uv_stream_t*) handle, -1, uv_null_buf_); } -static void uv_pipe_read_error(uv_pipe_t* handle, int error, uv_buf_t buf) { +static void uv_pipe_read_error(uv_loop_t* loop, uv_pipe_t* handle, int error, + uv_buf_t buf) { /* If there is an eof timer running, we don't need it any more, */ /* so discard it. */ eof_timer_destroy(handle); uv_read_stop((uv_stream_t*) handle); - uv_set_sys_error(error); + uv_set_sys_error(loop, error); handle->read_cb((uv_stream_t*)handle, -1, buf); } -static void uv_pipe_read_error_or_eof(uv_pipe_t* handle, int error, uv_buf_t buf) { +static void uv_pipe_read_error_or_eof(uv_loop_t* loop, uv_pipe_t* handle, + int error, uv_buf_t buf) { if (error == ERROR_BROKEN_PIPE) { - uv_pipe_read_eof(handle, buf); + uv_pipe_read_eof(loop, handle, buf); } else { - uv_pipe_read_error(handle, error, buf); + uv_pipe_read_error(loop, handle, error, buf); } } -void uv_process_pipe_read_req(uv_pipe_t* handle, uv_req_t* req) { +void uv_process_pipe_read_req(uv_loop_t* loop, uv_pipe_t* handle, + uv_req_t* req) { DWORD bytes, avail; uv_buf_t buf; @@ -808,7 +826,10 @@ void uv_process_pipe_read_req(uv_pipe_t* handle, uv_req_t* req) { if (!REQ_SUCCESS(req)) { /* An error occurred doing the 0-read. */ if (handle->flags & UV_HANDLE_READING) { - uv_pipe_read_error_or_eof(handle, GET_REQ_ERROR(req), uv_null_buf_); + uv_pipe_read_error_or_eof(loop, + handle, + GET_REQ_ERROR(req), + uv_null_buf_); } } else { /* Do non-blocking reads until the buffer is empty */ @@ -819,7 +840,7 @@ void uv_process_pipe_read_req(uv_pipe_t* handle, uv_req_t* req) { NULL, &avail, NULL)) { - uv_pipe_read_error_or_eof(handle, GetLastError(), uv_null_buf_); + uv_pipe_read_error_or_eof(loop, handle, GetLastError(), uv_null_buf_); break; } @@ -843,7 +864,7 @@ void uv_process_pipe_read_req(uv_pipe_t* handle, uv_req_t* req) { break; } } else { - uv_pipe_read_error_or_eof(handle, GetLastError(), uv_null_buf_); + uv_pipe_read_error_or_eof(loop, handle, GetLastError(), uv_null_buf_); break; } } @@ -851,7 +872,7 @@ void uv_process_pipe_read_req(uv_pipe_t* handle, uv_req_t* req) { /* Post another 0-read if still reading and not closing. */ if ((handle->flags & UV_HANDLE_READING) && !(handle->flags & UV_HANDLE_READ_PENDING)) { - uv_pipe_queue_read(handle); + uv_pipe_queue_read(loop, handle); } } @@ -859,14 +880,15 @@ void uv_process_pipe_read_req(uv_pipe_t* handle, uv_req_t* req) { } -void uv_process_pipe_write_req(uv_pipe_t* handle, uv_write_t* req) { +void uv_process_pipe_write_req(uv_loop_t* loop, uv_pipe_t* handle, + uv_write_t* req) { assert(handle->type == UV_NAMED_PIPE); handle->write_queue_size -= req->queued_bytes; if (req->cb) { if (!REQ_SUCCESS(req)) { - LOOP->last_error = GET_REQ_UV_ERROR(req); + loop->last_error = GET_REQ_UV_ERROR(req); ((uv_write_cb)req->cb)(req, -1); } else { ((uv_write_cb)req->cb)(req, 0); @@ -876,14 +898,15 @@ void uv_process_pipe_write_req(uv_pipe_t* handle, uv_write_t* req) { handle->write_reqs_pending--; if (handle->write_reqs_pending == 0 && handle->flags & UV_HANDLE_SHUTTING) { - uv_want_endgame((uv_handle_t*)handle); + uv_want_endgame(loop, (uv_handle_t*)handle); } DECREASE_PENDING_REQ_COUNT(handle); } -void uv_process_pipe_accept_req(uv_pipe_t* handle, uv_req_t* raw_req) { +void uv_process_pipe_accept_req(uv_loop_t* loop, uv_pipe_t* handle, + uv_req_t* raw_req) { uv_pipe_accept_t* req = (uv_pipe_accept_t*) raw_req; assert(handle->type == UV_NAMED_PIPE); @@ -903,7 +926,7 @@ void uv_process_pipe_accept_req(uv_pipe_t* handle, uv_req_t* raw_req) { } if (!(handle->flags & UV_HANDLE_CLOSING) && !(handle->flags & UV_HANDLE_GIVEN_OS_HANDLE)) { - uv_pipe_queue_accept(handle, req, FALSE); + uv_pipe_queue_accept(loop, handle, req, FALSE); } } @@ -911,7 +934,8 @@ void uv_process_pipe_accept_req(uv_pipe_t* handle, uv_req_t* raw_req) { } -void uv_process_pipe_connect_req(uv_pipe_t* handle, uv_connect_t* req) { +void uv_process_pipe_connect_req(uv_loop_t* loop, uv_pipe_t* handle, + uv_connect_t* req) { assert(handle->type == UV_NAMED_PIPE); if (req->cb) { @@ -919,7 +943,7 @@ void uv_process_pipe_connect_req(uv_pipe_t* handle, uv_connect_t* req) { uv_pipe_connection_init(handle); ((uv_connect_cb)req->cb)(req, 0); } else { - LOOP->last_error = GET_REQ_UV_ERROR(req); + loop->last_error = GET_REQ_UV_ERROR(req); ((uv_connect_cb)req->cb)(req, -1); } } @@ -928,7 +952,8 @@ void uv_process_pipe_connect_req(uv_pipe_t* handle, uv_connect_t* req) { } -void uv_process_pipe_shutdown_req(uv_pipe_t* handle, uv_shutdown_t* req) { +void uv_process_pipe_shutdown_req(uv_loop_t* loop, uv_pipe_t* handle, + uv_shutdown_t* req) { assert(handle->type == UV_NAMED_PIPE); /* Initialize and optionally start the eof timer. */ @@ -959,7 +984,7 @@ static void eof_timer_init(uv_pipe_t* pipe) { pipe->eof_timer = (uv_timer_t*) malloc(sizeof *pipe->eof_timer); - r = uv_timer_init(pipe->eof_timer); + r = uv_timer_init(pipe->loop, pipe->eof_timer); assert(r == 0); /* timers can't fail */ pipe->eof_timer->data = pipe; } @@ -985,6 +1010,7 @@ static void eof_timer_stop(uv_pipe_t* pipe) { static void eof_timer_cb(uv_timer_t* timer, int status) { uv_pipe_t* pipe = (uv_pipe_t*) timer->data; + uv_loop_t* loop = timer->loop; assert(status == 0); /* timers can't fail */ assert(pipe->type == UV_NAMED_PIPE); @@ -1015,7 +1041,7 @@ static void eof_timer_cb(uv_timer_t* timer, int status) { /* Report the eof and update flags. This will get reported even if the */ /* user stopped reading in the meantime. TODO: is that okay? */ - uv_pipe_read_eof(pipe, uv_null_buf_); + uv_pipe_read_eof(loop, pipe, uv_null_buf_); } diff --git a/deps/uv/src/win/process.c b/deps/uv/src/win/process.c index f5523faff..25b0576ad 100644 --- a/deps/uv/src/win/process.c +++ b/deps/uv/src/win/process.c @@ -45,14 +45,15 @@ typedef struct env_var { uv_fatal_error(ERROR_OUTOFMEMORY, "malloc"); \ } \ if (!uv_utf8_to_utf16(s, t, size / sizeof(wchar_t))) { \ - uv_set_sys_error(GetLastError()); \ + uv_set_sys_error(loop, GetLastError()); \ err = -1; \ goto done; \ } -static void uv_process_init(uv_process_t* handle) { +static void uv_process_init(uv_loop_t* loop, uv_process_t* handle) { handle->type = UV_PROCESS; + handle->loop = loop; handle->flags = 0; handle->exit_cb = NULL; handle->pid = 0; @@ -67,17 +68,17 @@ static void uv_process_init(uv_process_t* handle) { handle->stdio_pipes[2].server_pipe = NULL; handle->stdio_pipes[2].child_pipe = INVALID_HANDLE_VALUE; - uv_req_init((uv_req_t*)&handle->exit_req); + uv_req_init(loop, (uv_req_t*)&handle->exit_req); handle->exit_req.type = UV_PROCESS_EXIT; handle->exit_req.data = handle; - uv_req_init((uv_req_t*)&handle->close_req); + uv_req_init(loop, (uv_req_t*)&handle->close_req); handle->close_req.type = UV_PROCESS_CLOSE; handle->close_req.data = handle; - uv_counters()->handle_init++; - uv_counters()->process_init++; + loop->counters.handle_init++; + loop->counters.process_init++; - uv_ref(); + uv_ref(loop); } @@ -122,8 +123,8 @@ static wchar_t* search_path_join_test(const wchar_t* dir, } /* Allocate buffer for output */ - result = result_pos = - (wchar_t*)malloc(sizeof(wchar_t) * (cwd_len + 1 + dir_len + 1 + name_len + 1 + ext_len + 1)); + result = result_pos = (wchar_t*)malloc(sizeof(wchar_t) * + (cwd_len + 1 + dir_len + 1 + name_len + 1 + ext_len + 1)); /* Copy cwd */ wcsncpy(result_pos, cwd, cwd_len); @@ -280,7 +281,8 @@ static wchar_t* search_path(const wchar_t *file, return NULL; } - /* Find the start of the filename so we can split the directory from the name */ + /* Find the start of the filename so we can split the directory from the */ + /* name. */ for (file_name_start = (wchar_t*)file + file_len; file_name_start > file && file_name_start[-1] != L'\\' @@ -489,7 +491,8 @@ error: * issues associated with that solution; this is the caller's * char**, and modifying it is rude. */ -static void check_required_vars_contains_var(env_var_t* required, int size, const char* var) { +static void check_required_vars_contains_var(env_var_t* required, int size, + const char* var) { int i; for (i = 0; i < size; ++i) { if (_strnicmp(required[i].narrow, var, required[i].len) == 0) { @@ -527,7 +530,9 @@ wchar_t* make_program_env(char** env_block) { }; for (env = env_block; *env; env++) { - check_required_vars_contains_var(required_vars, COUNTOF(required_vars), *env); + check_required_vars_contains_var(required_vars, + COUNTOF(required_vars), + *env); env_len += (uv_utf8_to_utf16(*env, NULL, 0) * sizeof(wchar_t)); } @@ -563,7 +568,9 @@ wchar_t* make_program_env(char** env_block) { wcscpy(ptr, required_vars[i].wide); ptr += required_vars[i].len - 1; *ptr++ = L'='; - var_size = GetEnvironmentVariableW(required_vars[i].wide, ptr, required_vars[i].value_len); + var_size = GetEnvironmentVariableW(required_vars[i].wide, + ptr, + required_vars[i].value_len); if (var_size == 0) { uv_fatal_error(GetLastError(), "GetEnvironmentVariableW"); } @@ -582,12 +589,13 @@ wchar_t* make_program_env(char** env_block) { */ static void CALLBACK exit_wait_callback(void* data, BOOLEAN didTimeout) { uv_process_t* process = (uv_process_t*)data; + uv_loop_t* loop = process->loop; assert(didTimeout == FALSE); assert(process); /* Post completed */ - POST_COMPLETION_FOR_REQ(&process->exit_req); + POST_COMPLETION_FOR_REQ(loop, &process->exit_req); } @@ -597,12 +605,13 @@ static void CALLBACK exit_wait_callback(void* data, BOOLEAN didTimeout) { */ static void CALLBACK close_wait_callback(void* data, BOOLEAN didTimeout) { uv_process_t* process = (uv_process_t*)data; + uv_loop_t* loop = process->loop; assert(didTimeout == FALSE); assert(process); /* Post completed */ - POST_COMPLETION_FOR_REQ(&process->close_req); + POST_COMPLETION_FOR_REQ(loop, &process->close_req); } @@ -615,6 +624,7 @@ static DWORD WINAPI spawn_failure(void* data) { char syscall[] = "CreateProcessW: "; char unknown[] = "unknown error\n"; uv_process_t* process = (uv_process_t*) data; + uv_loop_t* loop = process->loop; HANDLE child_stderr = process->stdio_pipes[2].child_pipe; char* buf = NULL; DWORD count, written; @@ -641,14 +651,14 @@ static DWORD WINAPI spawn_failure(void* data) { FlushFileBuffers(child_stderr); /* Post completed */ - POST_COMPLETION_FOR_REQ(&process->exit_req); + POST_COMPLETION_FOR_REQ(loop, &process->exit_req); return 0; } /* Called on main thread after a child process has exited. */ -void uv_process_proc_exit(uv_process_t* handle) { +void uv_process_proc_exit(uv_loop_t* loop, uv_process_t* handle) { int i; DWORD exit_code; @@ -688,12 +698,12 @@ void uv_process_proc_exit(uv_process_t* handle) { /* Called on main thread after UnregisterWaitEx finishes. */ -void uv_process_proc_close(uv_process_t* handle) { - uv_want_endgame((uv_handle_t*)handle); +void uv_process_proc_close(uv_loop_t* loop, uv_process_t* handle) { + uv_want_endgame(loop, (uv_handle_t*)handle); } -void uv_process_endgame(uv_process_t* handle) { +void uv_process_endgame(uv_loop_t* loop, uv_process_t* handle) { if (handle->flags & UV_HANDLE_CLOSING) { assert(!(handle->flags & UV_HANDLE_CLOSED)); handle->flags |= UV_HANDLE_CLOSED; @@ -702,12 +712,12 @@ void uv_process_endgame(uv_process_t* handle) { handle->close_cb((uv_handle_t*)handle); } - uv_unref(); + uv_unref(loop); } } -void uv_process_close(uv_process_t* handle) { +void uv_process_close(uv_loop_t* loop, uv_process_t* handle) { if (handle->wait_handle != INVALID_HANDLE_VALUE) { handle->close_handle = CreateEvent(NULL, FALSE, FALSE, NULL); UnregisterWaitEx(handle->wait_handle, handle->close_handle); @@ -717,25 +727,30 @@ void uv_process_close(uv_process_t* handle) { close_wait_callback, (void*)handle, INFINITE, WT_EXECUTEINWAITTHREAD | WT_EXECUTEONLYONCE); } else { - uv_want_endgame((uv_handle_t*)handle); + uv_want_endgame(loop, (uv_handle_t*)handle); } } -static int uv_create_stdio_pipe_pair(uv_pipe_t* server_pipe, HANDLE* child_pipe, DWORD server_access, DWORD child_access) { +static int uv_create_stdio_pipe_pair(uv_loop_t* loop, uv_pipe_t* server_pipe, + HANDLE* child_pipe, DWORD server_access, DWORD child_access) { int err; SECURITY_ATTRIBUTES sa = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE }; char pipe_name[64]; DWORD mode = PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT; if (server_pipe->type != UV_NAMED_PIPE) { - uv_set_error(UV_EINVAL, 0); + uv_set_error(loop, UV_EINVAL, 0); err = -1; goto done; } /* Create server pipe handle. */ - err = uv_stdio_pipe_server(server_pipe, server_access, pipe_name, sizeof(pipe_name)); + err = uv_stdio_pipe_server(loop, + server_pipe, + server_access, + pipe_name, + sizeof(pipe_name)); if (err) { goto done; } @@ -750,13 +765,13 @@ static int uv_create_stdio_pipe_pair(uv_pipe_t* server_pipe, HANDLE* child_pipe, NULL); if (*child_pipe == INVALID_HANDLE_VALUE) { - uv_set_sys_error(GetLastError()); + uv_set_sys_error(loop, GetLastError()); err = -1; goto done; } if (!SetNamedPipeHandleState(*child_pipe, &mode, NULL, NULL)) { - uv_set_sys_error(GetLastError()); + uv_set_sys_error(loop, GetLastError()); err = -1; goto done; } @@ -766,7 +781,7 @@ static int uv_create_stdio_pipe_pair(uv_pipe_t* server_pipe, HANDLE* child_pipe, */ if (!ConnectNamedPipe(server_pipe->handle, NULL)) { if (GetLastError() != ERROR_PIPE_CONNECTED) { - uv_set_sys_error(GetLastError()); + uv_set_sys_error(loop, GetLastError()); err = -1; goto done; } @@ -790,19 +805,22 @@ done: } -int uv_spawn(uv_process_t* process, uv_process_options_t options) { +int uv_spawn(uv_loop_t* loop, uv_process_t* process, + uv_process_options_t options) { int err = 0, i; wchar_t* path; int size; + BOOL result; wchar_t* application_path, *application, *arguments, *env, *cwd; STARTUPINFOW startup; PROCESS_INFORMATION info; - uv_process_init(process); + uv_process_init(loop, process); process->exit_cb = options.exit_cb; UTF8_TO_UTF16(options.file, application); - arguments = options.args ? make_program_args(options.args, options.windows_verbatim_arguments) : NULL; + arguments = options.args ? make_program_args(options.args, + options.windows_verbatim_arguments) : NULL; env = options.env ? make_program_env(options.env) : NULL; if (options.cwd) { @@ -816,7 +834,7 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) { } GetCurrentDirectoryW(size, cwd); } else { - uv_set_sys_error(GetLastError()); + uv_set_sys_error(loop, GetLastError()); err = -1; goto done; } @@ -843,7 +861,12 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) { /* Create stdio pipes. */ if (options.stdin_stream) { - err = uv_create_stdio_pipe_pair(options.stdin_stream, &process->stdio_pipes[0].child_pipe, PIPE_ACCESS_OUTBOUND, GENERIC_READ | FILE_WRITE_ATTRIBUTES); + err = uv_create_stdio_pipe_pair( + loop, + options.stdin_stream, + &process->stdio_pipes[0].child_pipe, + PIPE_ACCESS_OUTBOUND, + GENERIC_READ | FILE_WRITE_ATTRIBUTES); if (err) { goto done; } @@ -852,7 +875,11 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) { } if (options.stdout_stream) { - err = uv_create_stdio_pipe_pair(options.stdout_stream, &process->stdio_pipes[1].child_pipe, PIPE_ACCESS_INBOUND, GENERIC_WRITE); + err = uv_create_stdio_pipe_pair( + loop, options.stdout_stream, + &process->stdio_pipes[1].child_pipe, + PIPE_ACCESS_INBOUND, + GENERIC_WRITE); if (err) { goto done; } @@ -861,7 +888,12 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) { } if (options.stderr_stream) { - err = uv_create_stdio_pipe_pair(options.stderr_stream, &process->stdio_pipes[2].child_pipe, PIPE_ACCESS_INBOUND, GENERIC_WRITE); + err = uv_create_stdio_pipe_pair( + loop, + options.stderr_stream, + &process->stdio_pipes[2].child_pipe, + PIPE_ACCESS_INBOUND, + GENERIC_WRITE); if (err) { goto done; } @@ -895,9 +927,10 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) { process->pid = info.dwProcessId; /* Setup notifications for when the child process exits. */ - if (!RegisterWaitForSingleObject(&process->wait_handle, process->process_handle, - exit_wait_callback, (void*)process, INFINITE, - WT_EXECUTEINWAITTHREAD | WT_EXECUTEONLYONCE)) { + result = RegisterWaitForSingleObject(&process->wait_handle, + process->process_handle, exit_wait_callback, (void*)process, INFINITE, + WT_EXECUTEINWAITTHREAD | WT_EXECUTEONLYONCE); + if (!result) { uv_fatal_error(GetLastError(), "RegisterWaitForSingleObject"); } diff --git a/deps/uv/src/win/req.c b/deps/uv/src/win/req.c index 53430ec07..beff95bd0 100644 --- a/deps/uv/src/win/req.c +++ b/deps/uv/src/win/req.c @@ -26,8 +26,8 @@ #include "internal.h" -void uv_req_init(uv_req_t* req) { - uv_counters()->req_init++; +void uv_req_init(uv_loop_t* loop, uv_req_t* req) { + loop->counters.req_init++; req->type = UV_UNKNOWN_REQ; SET_REQ_SUCCESS(req); } @@ -38,29 +38,29 @@ uv_req_t* uv_overlapped_to_req(OVERLAPPED* overlapped) { } -void uv_insert_pending_req(uv_req_t* req) { +void uv_insert_pending_req(uv_loop_t* loop, uv_req_t* req) { req->next_req = NULL; - if (LOOP->pending_reqs_tail) { - req->next_req = LOOP->pending_reqs_tail->next_req; - LOOP->pending_reqs_tail->next_req = req; - LOOP->pending_reqs_tail = req; + if (loop->pending_reqs_tail) { + req->next_req = loop->pending_reqs_tail->next_req; + loop->pending_reqs_tail->next_req = req; + loop->pending_reqs_tail = req; } else { req->next_req = req; - LOOP->pending_reqs_tail = req; + loop->pending_reqs_tail = req; } } -static uv_req_t* uv_remove_pending_req() { +static uv_req_t* uv_remove_pending_req(uv_loop_t* loop) { uv_req_t* req; - if (LOOP->pending_reqs_tail) { - req = LOOP->pending_reqs_tail->next_req; + if (loop->pending_reqs_tail) { + req = loop->pending_reqs_tail->next_req; - if (req == LOOP->pending_reqs_tail) { - LOOP->pending_reqs_tail = NULL; + if (req == loop->pending_reqs_tail) { + loop->pending_reqs_tail = NULL; } else { - LOOP->pending_reqs_tail->next_req = req->next_req; + loop->pending_reqs_tail->next_req = req->next_req; } return req; @@ -72,15 +72,19 @@ static uv_req_t* uv_remove_pending_req() { } -#define DELEGATE_STREAM_REQ(req, method, handle_at) \ +#define DELEGATE_STREAM_REQ(loop, req, method, handle_at) \ do { \ switch (((uv_handle_t*) (req)->handle_at)->type) { \ case UV_TCP: \ - uv_process_tcp_##method##_req((uv_tcp_t*) ((req)->handle_at), req); \ + uv_process_tcp_##method##_req(loop, \ + (uv_tcp_t*) ((req)->handle_at), \ + req); \ break; \ \ case UV_NAMED_PIPE: \ - uv_process_pipe_##method##_req((uv_pipe_t*) ((req)->handle_at), req); \ + uv_process_pipe_##method##_req(loop, \ + (uv_pipe_t*) ((req)->handle_at), \ + req); \ break; \ \ default: \ @@ -89,73 +93,76 @@ static uv_req_t* uv_remove_pending_req() { } while (0) -void uv_process_reqs() { +void uv_process_reqs(uv_loop_t* loop) { uv_req_t* req; - while (req = uv_remove_pending_req()) { + while (req = uv_remove_pending_req(loop)) { switch (req->type) { case UV_READ: - DELEGATE_STREAM_REQ(req, read, data); + DELEGATE_STREAM_REQ(loop, req, read, data); break; case UV_WRITE: - DELEGATE_STREAM_REQ((uv_write_t*) req, write, handle); + DELEGATE_STREAM_REQ(loop, (uv_write_t*) req, write, handle); break; case UV_ACCEPT: - DELEGATE_STREAM_REQ(req, accept, data); + DELEGATE_STREAM_REQ(loop, req, accept, data); break; case UV_CONNECT: - DELEGATE_STREAM_REQ((uv_connect_t*) req, connect, handle); + DELEGATE_STREAM_REQ(loop, (uv_connect_t*) req, connect, handle); break; case UV_SHUTDOWN: /* Tcp shutdown requests don't come here. */ assert(((uv_shutdown_t*) req)->handle->type == UV_NAMED_PIPE); uv_process_pipe_shutdown_req( - (uv_pipe_t*) ((uv_shutdown_t*) req)->handle, (uv_shutdown_t*) req); + loop, + (uv_pipe_t*) ((uv_shutdown_t*) req)->handle, + (uv_shutdown_t*) req); break; case UV_UDP_RECV: - uv_process_udp_recv_req((uv_udp_t*) req->data, req); + uv_process_udp_recv_req(loop, (uv_udp_t*) req->data, req); break; case UV_UDP_SEND: - uv_process_udp_send_req(((uv_udp_send_t*) req)->handle, + uv_process_udp_send_req(loop, + ((uv_udp_send_t*) req)->handle, (uv_udp_send_t*) req); break; case UV_WAKEUP: - uv_process_async_wakeup_req((uv_async_t*) req->data, req); + uv_process_async_wakeup_req(loop, (uv_async_t*) req->data, req); break; case UV_ARES_EVENT_REQ: - uv_process_ares_event_req((uv_ares_action_t*) req->data, req); + uv_process_ares_event_req(loop, (uv_ares_action_t*) req->data, req); break; case UV_ARES_CLEANUP_REQ: - uv_process_ares_cleanup_req((uv_ares_task_t*) req->data, req); + uv_process_ares_cleanup_req(loop, (uv_ares_task_t*) req->data, req); break; case UV_GETADDRINFO_REQ: - uv_process_getaddrinfo_req((uv_getaddrinfo_t*) req->data, req); + uv_process_getaddrinfo_req(loop, (uv_getaddrinfo_t*) req->data, req); break; case UV_PROCESS_EXIT: - uv_process_proc_exit((uv_process_t*) req->data); + uv_process_proc_exit(loop, (uv_process_t*) req->data); break; case UV_PROCESS_CLOSE: - uv_process_proc_close((uv_process_t*) req->data); + uv_process_proc_close(loop, (uv_process_t*) req->data); break; case UV_FS: - uv_process_fs_req((uv_fs_t*) req); + uv_process_fs_req(loop, (uv_fs_t*) req); break; case UV_WORK: - uv_process_work_req((uv_work_t*) req); + uv_process_work_req(loop, (uv_work_t*) req); break; default: diff --git a/deps/uv/src/win/stdio.c b/deps/uv/src/win/stdio.c index 033313397..30fe2a1d6 100644 --- a/deps/uv/src/win/stdio.c +++ b/deps/uv/src/win/stdio.c @@ -27,7 +27,7 @@ #include "internal.h" -static uv_pipe_t* uv_make_pipe_for_std_handle(HANDLE handle) { +static uv_pipe_t* uv_make_pipe_for_std_handle(uv_loop_t* loop, HANDLE handle) { uv_pipe_t* pipe = NULL; pipe = (uv_pipe_t*)malloc(sizeof(uv_pipe_t)); @@ -35,7 +35,7 @@ static uv_pipe_t* uv_make_pipe_for_std_handle(HANDLE handle) { uv_fatal_error(ERROR_OUTOFMEMORY, "malloc"); } - if (uv_pipe_init_with_handle(pipe, handle)) { + if (uv_pipe_init_with_handle(loop, pipe, handle)) { free(pipe); return NULL; } @@ -45,7 +45,7 @@ static uv_pipe_t* uv_make_pipe_for_std_handle(HANDLE handle) { } -uv_stream_t* uv_std_handle(uv_std_type type) { +uv_stream_t* uv_std_handle(uv_loop_t* loop, uv_std_type type) { HANDLE handle; switch (type) { @@ -56,7 +56,7 @@ uv_stream_t* uv_std_handle(uv_std_type type) { } /* Assume only named pipes for now. */ - return (uv_stream_t*)uv_make_pipe_for_std_handle(handle); + return (uv_stream_t*)uv_make_pipe_for_std_handle(loop, handle); break; case UV_STDOUT: @@ -69,7 +69,7 @@ uv_stream_t* uv_std_handle(uv_std_type type) { default: assert(0); - uv_set_error(UV_EINVAL, 0); + uv_set_error(loop, UV_EINVAL, 0); return NULL; } } diff --git a/deps/uv/src/win/stream.c b/deps/uv/src/win/stream.c index b2c5aa340..26964110f 100644 --- a/deps/uv/src/win/stream.c +++ b/deps/uv/src/win/stream.c @@ -26,14 +26,15 @@ #include "internal.h" -void uv_stream_init(uv_stream_t* handle) { +void uv_stream_init(uv_loop_t* loop, uv_stream_t* handle) { handle->write_queue_size = 0; + handle->loop = loop; handle->flags = 0; - uv_counters()->handle_init++; - uv_counters()->stream_init++; + loop->counters.handle_init++; + loop->counters.stream_init++; - uv_ref(); + uv_ref(loop); } @@ -41,7 +42,7 @@ void uv_connection_init(uv_stream_t* handle) { handle->flags |= UV_HANDLE_CONNECTION; handle->write_reqs_pending = 0; - uv_req_init((uv_req_t*) &(handle->read_req)); + uv_req_init(handle->loop, (uv_req_t*) &(handle->read_req)); handle->read_req.type = UV_READ; handle->read_req.data = handle; } @@ -75,7 +76,8 @@ int uv_accept(uv_stream_t* server, uv_stream_t* client) { } -int uv_read_start(uv_stream_t* handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb) { +int uv_read_start(uv_stream_t* handle, uv_alloc_cb alloc_cb, + uv_read_cb read_cb) { switch (handle->type) { case UV_TCP: return uv_tcp_read_start((uv_tcp_t*)handle, alloc_cb, read_cb); @@ -97,31 +99,35 @@ int uv_read_stop(uv_stream_t* handle) { 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; + switch (handle->type) { case UV_TCP: - return uv_tcp_write(req, (uv_tcp_t*) handle, bufs, bufcnt, cb); + return uv_tcp_write(loop, req, (uv_tcp_t*) handle, bufs, bufcnt, cb); case UV_NAMED_PIPE: - return uv_pipe_write(req, (uv_pipe_t*) handle, bufs, bufcnt, cb); + return uv_pipe_write(loop, req, (uv_pipe_t*) handle, bufs, bufcnt, cb); default: assert(0); - uv_set_sys_error(WSAEINVAL); + uv_set_sys_error(loop, WSAEINVAL); return -1; } } 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_CONNECTION)) { - uv_set_sys_error(WSAEINVAL); + uv_set_sys_error(loop, WSAEINVAL); return -1; } if (handle->flags & UV_HANDLE_SHUTTING) { - uv_set_sys_error(WSAESHUTDOWN); + uv_set_sys_error(loop, WSAESHUTDOWN); return -1; } - uv_req_init((uv_req_t*) req); + uv_req_init(loop, (uv_req_t*) req); req->type = UV_SHUTDOWN; req->handle = handle; req->cb = cb; @@ -130,7 +136,7 @@ int uv_shutdown(uv_shutdown_t* req, uv_stream_t* handle, uv_shutdown_cb cb) { handle->shutdown_req = req; handle->reqs_pending++; - uv_want_endgame((uv_handle_t*)handle); + uv_want_endgame(loop, (uv_handle_t*)handle); return 0; } diff --git a/deps/uv/src/win/tcp.c b/deps/uv/src/win/tcp.c index 619a59b16..618fc1e9f 100644 --- a/deps/uv/src/win/tcp.c +++ b/deps/uv/src/win/tcp.c @@ -46,37 +46,39 @@ static char uv_zero_[] = ""; static unsigned int active_tcp_streams = 0; -static int uv_tcp_set_socket(uv_tcp_t* handle, SOCKET socket) { +static int uv_tcp_set_socket(uv_loop_t* loop, uv_tcp_t* handle, + SOCKET socket) { DWORD yes = 1; assert(handle->socket == INVALID_SOCKET); /* Set the socket to nonblocking mode */ if (ioctlsocket(socket, FIONBIO, &yes) == SOCKET_ERROR) { - uv_set_sys_error(WSAGetLastError()); + uv_set_sys_error(loop, WSAGetLastError()); return -1; } /* Make the socket non-inheritable */ if (!SetHandleInformation((HANDLE)socket, HANDLE_FLAG_INHERIT, 0)) { - uv_set_sys_error(GetLastError()); + uv_set_sys_error(loop, GetLastError()); return -1; } /* Associate it with the I/O completion port. */ /* Use uv_handle_t pointer as completion key. */ if (CreateIoCompletionPort((HANDLE)socket, - LOOP->iocp, + loop->iocp, (ULONG_PTR)socket, 0) == NULL) { - uv_set_sys_error(GetLastError()); + uv_set_sys_error(loop, GetLastError()); return -1; } if (pSetFileCompletionNotificationModes) { - if (!pSetFileCompletionNotificationModes((HANDLE)socket, FILE_SKIP_SET_EVENT_ON_HANDLE | - FILE_SKIP_COMPLETION_PORT_ON_SUCCESS)) { - uv_set_sys_error(GetLastError()); + if (!pSetFileCompletionNotificationModes((HANDLE) socket, + FILE_SKIP_SET_EVENT_ON_HANDLE | + FILE_SKIP_COMPLETION_PORT_ON_SUCCESS)) { + uv_set_sys_error(loop, GetLastError()); return -1; } @@ -89,8 +91,8 @@ static int uv_tcp_set_socket(uv_tcp_t* handle, SOCKET socket) { } -int uv_tcp_init(uv_tcp_t* handle) { - uv_stream_init((uv_stream_t*)handle); +int uv_tcp_init(uv_loop_t* loop, uv_tcp_t* handle) { + uv_stream_init(loop, (uv_stream_t*)handle); handle->accept_reqs = NULL; handle->pending_accepts = NULL; @@ -98,13 +100,13 @@ int uv_tcp_init(uv_tcp_t* handle) { handle->type = UV_TCP; handle->reqs_pending = 0; - uv_counters()->tcp_init++; + loop->counters.tcp_init++; return 0; } -void uv_tcp_endgame(uv_tcp_t* handle) { +void uv_tcp_endgame(uv_loop_t* loop, uv_tcp_t* handle) { uv_err_t err; int status; @@ -122,7 +124,7 @@ void uv_tcp_endgame(uv_tcp_t* handle) { } if (handle->shutdown_req->cb) { if (status == -1) { - LOOP->last_error = err; + loop->last_error = err; } handle->shutdown_req->cb(handle->shutdown_req, status); } @@ -145,12 +147,13 @@ void uv_tcp_endgame(uv_tcp_t* handle) { active_tcp_streams--; - uv_unref(); + uv_unref(loop); } } -static int uv__bind(uv_tcp_t* handle, int domain, struct sockaddr* addr, int addrsize) { +static int uv__bind(uv_loop_t* loop, uv_tcp_t* handle, int domain, + struct sockaddr* addr, int addrsize) { DWORD err; int r; SOCKET sock; @@ -158,11 +161,11 @@ static int uv__bind(uv_tcp_t* handle, int domain, struct sockaddr* addr, int add if (handle->socket == INVALID_SOCKET) { sock = socket(domain, SOCK_STREAM, 0); if (sock == INVALID_SOCKET) { - uv_set_sys_error(WSAGetLastError()); + uv_set_sys_error(loop, WSAGetLastError()); return -1; } - if (uv_tcp_set_socket(handle, sock) == -1) { + if (uv_tcp_set_socket(loop, handle, sock) == -1) { closesocket(sock); return -1; } @@ -177,7 +180,7 @@ static int uv__bind(uv_tcp_t* handle, int domain, struct sockaddr* addr, int add handle->bind_error = uv_new_sys_error(err); handle->flags |= UV_HANDLE_BIND_ERROR; } else { - uv_set_sys_error(err); + uv_set_sys_error(loop, err); return -1; } } @@ -189,31 +192,46 @@ static int uv__bind(uv_tcp_t* handle, int domain, struct sockaddr* addr, int add int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr) { + uv_loop_t* loop = handle->loop; + if (addr.sin_family != AF_INET) { - uv_set_sys_error(WSAEFAULT); + uv_set_sys_error(loop, WSAEFAULT); return -1; } - return uv__bind(handle, AF_INET, (struct sockaddr*)&addr, sizeof(struct sockaddr_in)); + return uv__bind(loop, + handle, + AF_INET, + (struct sockaddr*)&addr, + sizeof(struct sockaddr_in)); } int uv_tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr) { + uv_loop_t* loop = handle->loop; + if (addr.sin6_family != AF_INET6) { - uv_set_sys_error(WSAEFAULT); + uv_set_sys_error(loop, WSAEFAULT); return -1; } + if (uv_allow_ipv6) { handle->flags |= UV_HANDLE_IPV6; - return uv__bind(handle, AF_INET6, (struct sockaddr*)&addr, sizeof(struct sockaddr_in6)); + return uv__bind(loop, + handle, + AF_INET6, + (struct sockaddr*)&addr, + sizeof(struct sockaddr_in6)); + } else { - uv_new_sys_error(WSAEAFNOSUPPORT); + uv_set_sys_error(loop, WSAEAFNOSUPPORT); return -1; } } static void uv_tcp_queue_accept(uv_tcp_t* handle, uv_tcp_accept_t* req) { + uv_loop_t* loop = handle->loop; BOOL success; DWORD bytes; SOCKET accept_socket; @@ -236,7 +254,7 @@ static void uv_tcp_queue_accept(uv_tcp_t* handle, uv_tcp_accept_t* req) { accept_socket = socket(family, SOCK_STREAM, 0); if (accept_socket == INVALID_SOCKET) { SET_REQ_ERROR(req, WSAGetLastError()); - uv_insert_pending_req((uv_req_t*)req); + uv_insert_pending_req(loop, (uv_req_t*)req); handle->reqs_pending++; return; } @@ -257,7 +275,7 @@ static void uv_tcp_queue_accept(uv_tcp_t* handle, uv_tcp_accept_t* req) { /* Process the req without IOCP. */ req->accept_socket = accept_socket; handle->reqs_pending++; - uv_insert_pending_req((uv_req_t*)req); + uv_insert_pending_req(loop, (uv_req_t*)req); } else if (UV_SUCCEEDED_WITH_IOCP(success)) { /* The req will be processed with IOCP. */ req->accept_socket = accept_socket; @@ -265,7 +283,7 @@ static void uv_tcp_queue_accept(uv_tcp_t* handle, uv_tcp_accept_t* req) { } else { /* Make this req pending reporting an error. */ SET_REQ_ERROR(req, WSAGetLastError()); - uv_insert_pending_req((uv_req_t*)req); + uv_insert_pending_req(loop, (uv_req_t*)req); handle->reqs_pending++; /* Destroy the preallocated client socket. */ closesocket(accept_socket); @@ -273,7 +291,7 @@ static void uv_tcp_queue_accept(uv_tcp_t* handle, uv_tcp_accept_t* req) { } -static void uv_tcp_queue_read(uv_tcp_t* handle) { +static void uv_tcp_queue_read(uv_loop_t* loop, uv_tcp_t* handle) { uv_req_t* req; uv_buf_t buf; int result; @@ -314,7 +332,7 @@ static void uv_tcp_queue_read(uv_tcp_t* handle) { handle->flags |= UV_HANDLE_READ_PENDING; req->overlapped.InternalHigh = bytes; handle->reqs_pending++; - uv_insert_pending_req(req); + uv_insert_pending_req(loop, req); } else if (UV_SUCCEEDED_WITH_IOCP(result == 0)) { /* The req will be processed with IOCP. */ handle->flags |= UV_HANDLE_READ_PENDING; @@ -322,27 +340,28 @@ static void uv_tcp_queue_read(uv_tcp_t* handle) { } else { /* Make this req pending reporting an error. */ SET_REQ_ERROR(req, WSAGetLastError()); - uv_insert_pending_req(req); + uv_insert_pending_req(loop, req); handle->reqs_pending++; } } int uv_tcp_listen(uv_tcp_t* handle, int backlog, uv_connection_cb cb) { + uv_loop_t* loop = handle->loop; unsigned int i; uv_tcp_accept_t* req; assert(backlog > 0); if (handle->flags & UV_HANDLE_BIND_ERROR) { - LOOP->last_error = handle->bind_error; + loop->last_error = handle->bind_error; return -1; } if (handle->flags & UV_HANDLE_LISTENING || handle->flags & UV_HANDLE_READING) { /* Already listening. */ - uv_set_sys_error(WSAEALREADY); + uv_set_sys_error(loop, WSAEALREADY); return -1; } @@ -351,7 +370,7 @@ int uv_tcp_listen(uv_tcp_t* handle, int backlog, uv_connection_cb cb) { return -1; if (listen(handle->socket, backlog) == SOCKET_ERROR) { - uv_set_sys_error(WSAGetLastError()); + uv_set_sys_error(loop, WSAGetLastError()); return -1; } @@ -367,7 +386,7 @@ int uv_tcp_listen(uv_tcp_t* handle, int backlog, uv_connection_cb cb) { for (i = 0; i < uv_simultaneous_server_accepts; i++) { req = &handle->accept_reqs[i]; - uv_req_init((uv_req_t*)req); + uv_req_init(loop, (uv_req_t*)req); req->type = UV_ACCEPT; req->accept_socket = INVALID_SOCKET; req->data = handle; @@ -379,26 +398,27 @@ int uv_tcp_listen(uv_tcp_t* handle, int backlog, uv_connection_cb cb) { int uv_tcp_accept(uv_tcp_t* server, uv_tcp_t* client) { + uv_loop_t* loop = server->loop; int rv = 0; uv_tcp_accept_t* req = server->pending_accepts; if (!req) { /* No valid connections found, so we error out. */ - uv_set_sys_error(WSAEWOULDBLOCK); + uv_set_sys_error(loop, WSAEWOULDBLOCK); return -1; } if (req->accept_socket == INVALID_SOCKET) { - uv_set_sys_error(WSAENOTCONN); + uv_set_sys_error(loop, WSAENOTCONN); return -1; } - if (uv_tcp_set_socket(client, req->accept_socket) == -1) { + if (uv_tcp_set_socket(client->loop, client, req->accept_socket) == -1) { closesocket(req->accept_socket); rv = -1; } else { - uv_connection_init((uv_stream_t*)client); + uv_connection_init((uv_stream_t*) client); } /* Prepare the req to pick up a new connection */ @@ -416,19 +436,22 @@ int uv_tcp_accept(uv_tcp_t* server, uv_tcp_t* client) { } -int uv_tcp_read_start(uv_tcp_t* handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb) { +int uv_tcp_read_start(uv_tcp_t* handle, uv_alloc_cb alloc_cb, + uv_read_cb read_cb) { + uv_loop_t* loop = handle->loop; + if (!(handle->flags & UV_HANDLE_CONNECTION)) { - uv_set_sys_error(WSAEINVAL); + uv_set_sys_error(loop, WSAEINVAL); return -1; } if (handle->flags & UV_HANDLE_READING) { - uv_set_sys_error(WSAEALREADY); + uv_set_sys_error(loop, WSAEALREADY); return -1; } if (handle->flags & UV_HANDLE_EOF) { - uv_set_sys_error(WSAESHUTDOWN); + uv_set_sys_error(loop, WSAESHUTDOWN); return -1; } @@ -439,7 +462,7 @@ int uv_tcp_read_start(uv_tcp_t* handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb /* If reading was stopped and then started again, there could stell be a */ /* read request pending. */ if (!(handle->flags & UV_HANDLE_READ_PENDING)) - uv_tcp_queue_read(handle); + uv_tcp_queue_read(loop, handle); return 0; } @@ -447,17 +470,18 @@ int uv_tcp_read_start(uv_tcp_t* handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb int uv_tcp_connect(uv_connect_t* req, uv_tcp_t* handle, struct sockaddr_in address, uv_connect_cb cb) { + uv_loop_t* loop = handle->loop; int addrsize = sizeof(struct sockaddr_in); BOOL success; DWORD bytes; if (handle->flags & UV_HANDLE_BIND_ERROR) { - LOOP->last_error = handle->bind_error; + loop->last_error = handle->bind_error; return -1; } if (address.sin_family != AF_INET) { - uv_set_sys_error(WSAEFAULT); + uv_set_sys_error(loop, WSAEFAULT); return -1; } @@ -465,7 +489,7 @@ int uv_tcp_connect(uv_connect_t* req, uv_tcp_t* handle, uv_tcp_bind(handle, uv_addr_ip4_any_) < 0) return -1; - uv_req_init((uv_req_t*) req); + uv_req_init(loop, (uv_req_t*) req); req->type = UV_CONNECT; req->handle = (uv_stream_t*) handle; req->cb = cb; @@ -482,12 +506,12 @@ int uv_tcp_connect(uv_connect_t* req, uv_tcp_t* handle, if (UV_SUCCEEDED_WITHOUT_IOCP(success)) { /* Process the req without IOCP. */ handle->reqs_pending++; - uv_insert_pending_req((uv_req_t*)req); + uv_insert_pending_req(loop, (uv_req_t*)req); } else if (UV_SUCCEEDED_WITH_IOCP(success)) { /* The req will be processed with IOCP. */ handle->reqs_pending++; } else { - uv_set_sys_error(WSAGetLastError()); + uv_set_sys_error(loop, WSAGetLastError()); return -1; } @@ -497,6 +521,7 @@ int uv_tcp_connect(uv_connect_t* req, uv_tcp_t* handle, int uv_tcp_connect6(uv_connect_t* req, uv_tcp_t* handle, struct sockaddr_in6 address, uv_connect_cb cb) { + uv_loop_t* loop = handle->loop; int addrsize = sizeof(struct sockaddr_in6); BOOL success; DWORD bytes; @@ -507,12 +532,12 @@ int uv_tcp_connect6(uv_connect_t* req, uv_tcp_t* handle, } if (handle->flags & UV_HANDLE_BIND_ERROR) { - LOOP->last_error = handle->bind_error; + loop->last_error = handle->bind_error; return -1; } if (address.sin6_family != AF_INET6) { - uv_set_sys_error(WSAEFAULT); + uv_set_sys_error(loop, WSAEFAULT); return -1; } @@ -520,7 +545,7 @@ int uv_tcp_connect6(uv_connect_t* req, uv_tcp_t* handle, uv_tcp_bind6(handle, uv_addr_ip6_any_) < 0) return -1; - uv_req_init((uv_req_t*) req); + uv_req_init(loop, (uv_req_t*) req); req->type = UV_CONNECT; req->handle = (uv_stream_t*) handle; req->cb = cb; @@ -536,11 +561,11 @@ int uv_tcp_connect6(uv_connect_t* req, uv_tcp_t* handle, if (UV_SUCCEEDED_WITHOUT_IOCP(success)) { handle->reqs_pending++; - uv_insert_pending_req((uv_req_t*)req); + uv_insert_pending_req(loop, (uv_req_t*)req); } else if (UV_SUCCEEDED_WITH_IOCP(success)) { handle->reqs_pending++; } else { - uv_set_sys_error(WSAGetLastError()); + uv_set_sys_error(loop, WSAGetLastError()); return -1; } @@ -548,17 +573,18 @@ int uv_tcp_connect6(uv_connect_t* req, uv_tcp_t* handle, } -int uv_tcp_getsockname(uv_tcp_t* handle, struct sockaddr* name, int* namelen) { +int uv_tcp_getsockname(uv_loop_t* loop, uv_tcp_t* handle, + struct sockaddr* name, int* namelen) { int result; if (handle->flags & UV_HANDLE_SHUTTING) { - uv_set_sys_error(WSAESHUTDOWN); + uv_set_sys_error(loop, WSAESHUTDOWN); return -1; } result = getsockname(handle->socket, name, namelen); if (result != 0) { - uv_set_sys_error(WSAGetLastError()); + uv_set_sys_error(loop, WSAGetLastError()); return -1; } @@ -566,22 +592,22 @@ int uv_tcp_getsockname(uv_tcp_t* handle, struct sockaddr* name, int* namelen) { } -int uv_tcp_write(uv_write_t* req, uv_tcp_t* handle, uv_buf_t bufs[], int bufcnt, - uv_write_cb cb) { +int uv_tcp_write(uv_loop_t* loop, uv_write_t* req, uv_tcp_t* handle, + uv_buf_t bufs[], int bufcnt, uv_write_cb cb) { int result; DWORD bytes; if (!(handle->flags & UV_HANDLE_CONNECTION)) { - uv_set_sys_error(WSAEINVAL); + uv_set_sys_error(loop, WSAEINVAL); return -1; } if (handle->flags & UV_HANDLE_SHUTTING) { - uv_set_sys_error(WSAESHUTDOWN); + uv_set_sys_error(loop, WSAESHUTDOWN); return -1; } - uv_req_init((uv_req_t*) req); + uv_req_init(loop, (uv_req_t*) req); req->type = UV_WRITE; req->handle = (uv_stream_t*) handle; req->cb = cb; @@ -600,7 +626,7 @@ int uv_tcp_write(uv_write_t* req, uv_tcp_t* handle, uv_buf_t bufs[], int bufcnt, req->queued_bytes = 0; handle->reqs_pending++; handle->write_reqs_pending++; - uv_insert_pending_req((uv_req_t*)req); + uv_insert_pending_req(loop, (uv_req_t*) req); } else if (UV_SUCCEEDED_WITH_IOCP(result == 0)) { /* Request queued by the kernel. */ req->queued_bytes = uv_count_bufs(bufs, bufcnt); @@ -609,7 +635,7 @@ int uv_tcp_write(uv_write_t* req, uv_tcp_t* handle, uv_buf_t bufs[], int bufcnt, handle->write_queue_size += req->queued_bytes; } else { /* Send failed due to an error. */ - uv_set_sys_error(WSAGetLastError()); + uv_set_sys_error(loop, WSAGetLastError()); return -1; } @@ -617,7 +643,8 @@ int uv_tcp_write(uv_write_t* req, uv_tcp_t* handle, uv_buf_t bufs[], int bufcnt, } -void uv_process_tcp_read_req(uv_tcp_t* handle, uv_req_t* req) { +void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle, + uv_req_t* req) { DWORD bytes, flags, err; uv_buf_t buf; @@ -629,7 +656,7 @@ void uv_process_tcp_read_req(uv_tcp_t* handle, uv_req_t* req) { /* An error occurred doing the read. */ if ((handle->flags & UV_HANDLE_READING)) { handle->flags &= ~UV_HANDLE_READING; - LOOP->last_error = GET_REQ_UV_SOCK_ERROR(req); + loop->last_error = GET_REQ_UV_SOCK_ERROR(req); buf = (handle->flags & UV_HANDLE_ZERO_READ) ? uv_buf_init(NULL, 0) : handle->read_buffer; handle->read_cb((uv_stream_t*)handle, -1, buf); @@ -639,7 +666,9 @@ void uv_process_tcp_read_req(uv_tcp_t* handle, uv_req_t* req) { /* The read was done with a non-zero buffer length. */ if (req->overlapped.InternalHigh > 0) { /* Successful read */ - handle->read_cb((uv_stream_t*)handle, req->overlapped.InternalHigh, handle->read_buffer); + handle->read_cb((uv_stream_t*)handle, + req->overlapped.InternalHigh, + handle->read_buffer); /* Read again only if bytes == buf.len */ if (req->overlapped.InternalHigh < handle->read_buffer.len) { goto done; @@ -648,8 +677,8 @@ void uv_process_tcp_read_req(uv_tcp_t* handle, uv_req_t* req) { /* Connection closed */ handle->flags &= ~UV_HANDLE_READING; handle->flags |= UV_HANDLE_EOF; - LOOP->last_error.code = UV_EOF; - LOOP->last_error.sys_errno_ = ERROR_SUCCESS; + loop->last_error.code = UV_EOF; + loop->last_error.sys_errno_ = ERROR_SUCCESS; buf.base = 0; buf.len = 0; handle->read_cb((uv_stream_t*)handle, -1, handle->read_buffer); @@ -680,8 +709,8 @@ void uv_process_tcp_read_req(uv_tcp_t* handle, uv_req_t* req) { /* Connection closed */ handle->flags &= ~UV_HANDLE_READING; handle->flags |= UV_HANDLE_EOF; - LOOP->last_error.code = UV_EOF; - LOOP->last_error.sys_errno_ = ERROR_SUCCESS; + loop->last_error.code = UV_EOF; + loop->last_error.sys_errno_ = ERROR_SUCCESS; handle->read_cb((uv_stream_t*)handle, -1, buf); break; } @@ -689,11 +718,11 @@ void uv_process_tcp_read_req(uv_tcp_t* handle, uv_req_t* req) { err = WSAGetLastError(); if (err == WSAEWOULDBLOCK) { /* Read buffer was completely empty, report a 0-byte read. */ - uv_set_sys_error(WSAEWOULDBLOCK); + uv_set_sys_error(loop, WSAEWOULDBLOCK); handle->read_cb((uv_stream_t*)handle, 0, buf); } else { /* Ouch! serious error. */ - uv_set_sys_error(err); + uv_set_sys_error(loop, err); handle->flags &= ~UV_HANDLE_READING; handle->read_cb((uv_stream_t*)handle, -1, buf); } @@ -705,7 +734,7 @@ done: /* Post another read if still reading and not closing. */ if ((handle->flags & UV_HANDLE_READING) && !(handle->flags & UV_HANDLE_READ_PENDING)) { - uv_tcp_queue_read(handle); + uv_tcp_queue_read(loop, handle); } } @@ -713,27 +742,29 @@ done: } -void uv_process_tcp_write_req(uv_tcp_t* handle, uv_write_t* req) { +void uv_process_tcp_write_req(uv_loop_t* loop, uv_tcp_t* handle, + uv_write_t* req) { assert(handle->type == UV_TCP); handle->write_queue_size -= req->queued_bytes; if (req->cb) { - LOOP->last_error = GET_REQ_UV_SOCK_ERROR(req); - ((uv_write_cb)req->cb)(req, LOOP->last_error.code == UV_OK ? 0 : -1); + loop->last_error = GET_REQ_UV_SOCK_ERROR(req); + ((uv_write_cb)req->cb)(req, loop->last_error.code == UV_OK ? 0 : -1); } handle->write_reqs_pending--; if (handle->flags & UV_HANDLE_SHUTTING && handle->write_reqs_pending == 0) { - uv_want_endgame((uv_handle_t*)handle); + uv_want_endgame(loop, (uv_handle_t*)handle); } DECREASE_PENDING_REQ_COUNT(handle); } -void uv_process_tcp_accept_req(uv_tcp_t* handle, uv_req_t* raw_req) { +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; assert(handle->type == UV_TCP); @@ -746,7 +777,7 @@ void uv_process_tcp_accept_req(uv_tcp_t* handle, uv_req_t* raw_req) { if (handle->flags & UV_HANDLE_LISTENING) { handle->flags &= ~UV_HANDLE_LISTENING; if (handle->connection_cb) { - LOOP->last_error = GET_REQ_UV_SOCK_ERROR(req); + loop->last_error = GET_REQ_UV_SOCK_ERROR(req); handle->connection_cb((uv_stream_t*)handle, -1); } } @@ -778,7 +809,8 @@ void uv_process_tcp_accept_req(uv_tcp_t* handle, uv_req_t* raw_req) { } -void uv_process_tcp_connect_req(uv_tcp_t* handle, uv_connect_t* req) { +void uv_process_tcp_connect_req(uv_loop_t* loop, uv_tcp_t* handle, + uv_connect_t* req) { assert(handle->type == UV_TCP); if (req->cb) { @@ -792,11 +824,11 @@ void uv_process_tcp_connect_req(uv_tcp_t* handle, uv_connect_t* req) { active_tcp_streams++; ((uv_connect_cb)req->cb)(req, 0); } else { - uv_set_sys_error(WSAGetLastError()); + uv_set_sys_error(loop, WSAGetLastError()); ((uv_connect_cb)req->cb)(req, -1); } } else { - LOOP->last_error = GET_REQ_UV_SOCK_ERROR(req); + loop->last_error = GET_REQ_UV_SOCK_ERROR(req); ((uv_connect_cb)req->cb)(req, -1); } } diff --git a/deps/uv/src/win/threadpool.c b/deps/uv/src/win/threadpool.c index 5b4436e75..c40613e1f 100644 --- a/deps/uv/src/win/threadpool.c +++ b/deps/uv/src/win/threadpool.c @@ -25,9 +25,11 @@ #include "internal.h" -static void uv_work_req_init(uv_work_t* req, uv_work_cb work_cb, uv_after_work_cb after_work_cb) { - uv_req_init((uv_req_t*) req); +static void uv_work_req_init(uv_loop_t* loop, uv_work_t* req, + uv_work_cb work_cb, uv_after_work_cb after_work_cb) { + uv_req_init(loop, (uv_req_t*) req); req->type = UV_WORK; + req->loop = loop; req->work_cb = work_cb; req->after_work_cb = after_work_cb; memset(&req->overlapped, 0, sizeof(req->overlapped)); @@ -36,6 +38,7 @@ static void uv_work_req_init(uv_work_t* req, uv_work_cb work_cb, uv_after_work_c static DWORD WINAPI uv_work_thread_proc(void* parameter) { uv_work_t* req = (uv_work_t*)parameter; + uv_loop_t* loop = req->loop; assert(req != NULL); assert(req->type == UV_WORK); @@ -43,27 +46,28 @@ static DWORD WINAPI uv_work_thread_proc(void* parameter) { req->work_cb(req); - POST_COMPLETION_FOR_REQ(req); + POST_COMPLETION_FOR_REQ(loop, req); return 0; } -int uv_queue_work(uv_work_t* req, uv_work_cb work_cb, uv_after_work_cb after_work_cb) { - uv_work_req_init(req, work_cb, after_work_cb); +int uv_queue_work(uv_loop_t* loop, uv_work_t* req, uv_work_cb work_cb, + uv_after_work_cb after_work_cb) { + uv_work_req_init(loop, req, work_cb, after_work_cb); if (!QueueUserWorkItem(&uv_work_thread_proc, req, WT_EXECUTELONGFUNCTION)) { - uv_set_sys_error(GetLastError()); + uv_set_sys_error(loop, GetLastError()); return -1; } - uv_ref(); + uv_ref(loop); return 0; } -void uv_process_work_req(uv_work_t* req) { +void uv_process_work_req(uv_loop_t* loop, uv_work_t* req) { assert(req->after_work_cb); req->after_work_cb(req); - uv_unref(); + uv_unref(loop); } diff --git a/deps/uv/src/win/timer.c b/deps/uv/src/win/timer.c index 68d3e3025..c21ea6ec1 100644 --- a/deps/uv/src/win/timer.c +++ b/deps/uv/src/win/timer.c @@ -36,12 +36,12 @@ static uint64_t uv_hrtime_frequency_ = 0; static char uv_hrtime_initialized_ = 0; -void uv_update_time() { +void uv_update_time(uv_loop_t* loop) { DWORD ticks = GetTickCount(); /* The assumption is made that LARGE_INTEGER.QuadPart has the same type */ - /* LOOP->time, which happens to be. Is there any way to assert this? */ - LARGE_INTEGER* time = (LARGE_INTEGER*) &LOOP->time; + /* loop->time, which happens to be. Is there any way to assert this? */ + LARGE_INTEGER* time = (LARGE_INTEGER*) &loop->time; /* If the timer has wrapped, add 1 to it's high-order dword. */ /* uv_poll must make sure that the timer can never overflow more than */ @@ -53,11 +53,11 @@ void uv_update_time() { } -int64_t uv_now() { - return LOOP->time; +int64_t uv_now(uv_loop_t* loop) { + return loop->time; } - +/* TODO: thread safety */ uint64_t uv_hrtime(void) { LARGE_INTEGER counter; @@ -68,7 +68,7 @@ uint64_t uv_hrtime(void) { if (!QueryPerformanceFrequency(&counter)) { uv_hrtime_frequency_ = 0; - uv_set_sys_error(GetLastError()); + /* uv_set_sys_error(loop, GetLastError()); */ return 0; } @@ -77,12 +77,12 @@ uint64_t uv_hrtime(void) { /* If the performance frequency is zero, there's no support. */ if (!uv_hrtime_frequency_) { - uv_set_sys_error(ERROR_NOT_SUPPORTED); + /* uv_set_sys_error(loop, ERROR_NOT_SUPPORTED); */ return 0; } if (!QueryPerformanceCounter(&counter)) { - uv_set_sys_error(GetLastError()); + /* uv_set_sys_error(loop, GetLastError()); */ return 0; } @@ -111,22 +111,23 @@ static int uv_timer_compare(uv_timer_t* a, uv_timer_t* b) { RB_GENERATE_STATIC(uv_timer_tree_s, uv_timer_s, tree_entry, uv_timer_compare); -int uv_timer_init(uv_timer_t* handle) { - uv_counters()->handle_init++; - uv_counters()->timer_init++; +int uv_timer_init(uv_loop_t* loop, uv_timer_t* handle) { + loop->counters.handle_init++; + loop->counters.timer_init++; handle->type = UV_TIMER; + handle->loop = loop; handle->flags = 0; handle->timer_cb = NULL; handle->repeat = 0; - uv_ref(); + uv_ref(loop); return 0; } -void uv_timer_endgame(uv_timer_t* handle) { +void uv_timer_endgame(uv_loop_t* loop, uv_timer_t* handle) { if (handle->flags & UV_HANDLE_CLOSING) { assert(!(handle->flags & UV_HANDLE_CLOSED)); handle->flags |= UV_HANDLE_CLOSED; @@ -135,22 +136,25 @@ void uv_timer_endgame(uv_timer_t* handle) { handle->close_cb((uv_handle_t*)handle); } - uv_unref(); + uv_unref(loop); } } -int uv_timer_start(uv_timer_t* handle, uv_timer_cb timer_cb, int64_t timeout, int64_t repeat) { +int uv_timer_start(uv_timer_t* handle, uv_timer_cb timer_cb, int64_t timeout, + int64_t repeat) { + uv_loop_t* loop = handle->loop; + if (handle->flags & UV_HANDLE_ACTIVE) { - RB_REMOVE(uv_timer_tree_s, &LOOP->timers, handle); + RB_REMOVE(uv_timer_tree_s, &loop->timers, handle); } handle->timer_cb = timer_cb; - handle->due = LOOP->time + timeout; + handle->due = loop->time + timeout; handle->repeat = repeat; handle->flags |= UV_HANDLE_ACTIVE; - if (RB_INSERT(uv_timer_tree_s, &LOOP->timers, handle) != NULL) { + if (RB_INSERT(uv_timer_tree_s, &loop->timers, handle) != NULL) { uv_fatal_error(ERROR_INVALID_DATA, "RB_INSERT"); } @@ -159,10 +163,12 @@ int uv_timer_start(uv_timer_t* handle, uv_timer_cb timer_cb, int64_t timeout, in int uv_timer_stop(uv_timer_t* handle) { + uv_loop_t* loop = handle->loop; + if (!(handle->flags & UV_HANDLE_ACTIVE)) return 0; - RB_REMOVE(uv_timer_tree_s, &LOOP->timers, handle); + RB_REMOVE(uv_timer_tree_s, &loop->timers, handle); handle->flags &= ~UV_HANDLE_ACTIVE; @@ -171,21 +177,23 @@ int uv_timer_stop(uv_timer_t* handle) { int uv_timer_again(uv_timer_t* handle) { + uv_loop_t* loop = handle->loop; + /* If timer_cb is NULL that means that the timer was never started. */ if (!handle->timer_cb) { - uv_set_sys_error(ERROR_INVALID_DATA); + uv_set_sys_error(loop, ERROR_INVALID_DATA); return -1; } if (handle->flags & UV_HANDLE_ACTIVE) { - RB_REMOVE(uv_timer_tree_s, &LOOP->timers, handle); + RB_REMOVE(uv_timer_tree_s, &loop->timers, handle); handle->flags &= ~UV_HANDLE_ACTIVE; } if (handle->repeat) { - handle->due = LOOP->time + handle->repeat; + handle->due = loop->time + handle->repeat; - if (RB_INSERT(uv_timer_tree_s, &LOOP->timers, handle) != NULL) { + if (RB_INSERT(uv_timer_tree_s, &loop->timers, handle) != NULL) { uv_fatal_error(ERROR_INVALID_DATA, "RB_INSERT"); } @@ -208,16 +216,16 @@ int64_t uv_timer_get_repeat(uv_timer_t* handle) { } -DWORD uv_get_poll_timeout() { +DWORD uv_get_poll_timeout(uv_loop_t* loop) { uv_timer_t* timer; int64_t delta; /* Check if there are any running timers */ - timer = RB_MIN(uv_timer_tree_s, &LOOP->timers); + timer = RB_MIN(uv_timer_tree_s, &loop->timers); if (timer) { - uv_update_time(); + uv_update_time(loop); - delta = timer->due - LOOP->time; + delta = timer->due - loop->time; if (delta >= UINT_MAX >> 1) { /* A timeout value of UINT_MAX means infinite, so that's no good. But */ /* more importantly, there's always the risk that GetTickCount wraps. */ @@ -240,22 +248,22 @@ DWORD uv_get_poll_timeout() { } -void uv_process_timers() { +void uv_process_timers(uv_loop_t* loop) { uv_timer_t* timer; /* Call timer callbacks */ - for (timer = RB_MIN(uv_timer_tree_s, &LOOP->timers); - timer != NULL && timer->due <= LOOP->time; - timer = RB_MIN(uv_timer_tree_s, &LOOP->timers)) { - RB_REMOVE(uv_timer_tree_s, &LOOP->timers, timer); + for (timer = RB_MIN(uv_timer_tree_s, &loop->timers); + timer != NULL && timer->due <= loop->time; + timer = RB_MIN(uv_timer_tree_s, &loop->timers)) { + RB_REMOVE(uv_timer_tree_s, &loop->timers, timer); if (timer->repeat != 0) { /* If it is a repeating timer, reschedule with repeat timeout. */ timer->due += timer->repeat; - if (timer->due < LOOP->time) { - timer->due = LOOP->time; + if (timer->due < loop->time) { + timer->due = loop->time; } - if (RB_INSERT(uv_timer_tree_s, &LOOP->timers, timer) != NULL) { + if (RB_INSERT(uv_timer_tree_s, &loop->timers, timer) != NULL) { uv_fatal_error(ERROR_INVALID_DATA, "RB_INSERT"); } } else { diff --git a/deps/uv/src/win/udp.c b/deps/uv/src/win/udp.c index 85a5c5cb7..6f8fa6b0f 100644 --- a/deps/uv/src/win/udp.c +++ b/deps/uv/src/win/udp.c @@ -40,12 +40,13 @@ static char uv_zero_[] = ""; static unsigned int active_udp_streams = 0; -int uv_udp_getsockname(uv_udp_t* handle, struct sockaddr* name, int* namelen) { +int uv_udp_getsockname(uv_loop_t* loop, uv_udp_t* handle, + struct sockaddr* name, int* namelen) { int result; result = getsockname(handle->socket, name, namelen); if (result != 0) { - uv_set_sys_error(WSAGetLastError()); + uv_set_sys_error(loop, WSAGetLastError()); return -1; } @@ -53,37 +54,38 @@ int uv_udp_getsockname(uv_udp_t* handle, struct sockaddr* name, int* namelen) { } -static int uv_udp_set_socket(uv_udp_t* handle, SOCKET socket) { +static int uv_udp_set_socket(uv_loop_t* loop, uv_udp_t* handle, + SOCKET socket) { DWORD yes = 1; assert(handle->socket == INVALID_SOCKET); /* Set the socket to nonblocking mode */ if (ioctlsocket(socket, FIONBIO, &yes) == SOCKET_ERROR) { - uv_set_sys_error(WSAGetLastError()); + uv_set_sys_error(loop, WSAGetLastError()); return -1; } /* Make the socket non-inheritable */ if (!SetHandleInformation((HANDLE)socket, HANDLE_FLAG_INHERIT, 0)) { - uv_set_sys_error(GetLastError()); + uv_set_sys_error(loop, GetLastError()); return -1; } /* Associate it with the I/O completion port. */ /* Use uv_handle_t pointer as completion key. */ if (CreateIoCompletionPort((HANDLE)socket, - LOOP->iocp, + loop->iocp, (ULONG_PTR)socket, 0) == NULL) { - uv_set_sys_error(GetLastError()); + uv_set_sys_error(loop, GetLastError()); return -1; } if (pSetFileCompletionNotificationModes) { - if (!pSetFileCompletionNotificationModes((HANDLE)socket, FILE_SKIP_SET_EVENT_ON_HANDLE | - FILE_SKIP_COMPLETION_PORT_ON_SUCCESS)) { - uv_set_sys_error(GetLastError()); + if (!pSetFileCompletionNotificationModes((HANDLE)socket, + FILE_SKIP_SET_EVENT_ON_HANDLE | FILE_SKIP_COMPLETION_PORT_ON_SUCCESS)) { + uv_set_sys_error(loop, GetLastError()); return -1; } @@ -96,26 +98,27 @@ static int uv_udp_set_socket(uv_udp_t* handle, SOCKET socket) { } -int uv_udp_init(uv_udp_t* handle) { +int uv_udp_init(uv_loop_t* loop, uv_udp_t* handle) { handle->type = UV_UDP; handle->socket = INVALID_SOCKET; handle->reqs_pending = 0; + handle->loop = loop; handle->flags = 0; - uv_req_init((uv_req_t*) &(handle->recv_req)); + uv_req_init(loop, (uv_req_t*) &(handle->recv_req)); handle->recv_req.type = UV_UDP_RECV; handle->recv_req.data = handle; - uv_ref(); + uv_ref(loop); - uv_counters()->handle_init++; - uv_counters()->udp_init++; + loop->counters.handle_init++; + loop->counters.udp_init++; return 0; } -void uv_udp_endgame(uv_udp_t* handle) { +void uv_udp_endgame(uv_loop_t* loop, uv_udp_t* handle) { if (handle->flags & UV_HANDLE_CLOSING && handle->reqs_pending == 0) { assert(!(handle->flags & UV_HANDLE_CLOSED)); @@ -125,30 +128,31 @@ void uv_udp_endgame(uv_udp_t* handle) { handle->close_cb((uv_handle_t*)handle); } - uv_unref(); + uv_unref(loop); } } static int uv__bind(uv_udp_t* handle, int domain, struct sockaddr* addr, int addrsize, unsigned int flags) { + uv_loop_t* loop = handle->loop; DWORD err; int r; SOCKET sock; if ((flags & UV_UDP_IPV6ONLY) && domain != AF_INET6) { /* UV_UDP_IPV6ONLY is supported only for IPV6 sockets */ - uv_set_sys_error(UV_EINVAL); + uv_set_sys_error(loop, UV_EINVAL); } if (handle->socket == INVALID_SOCKET) { sock = socket(domain, SOCK_DGRAM, 0); if (sock == INVALID_SOCKET) { - uv_set_sys_error(WSAGetLastError()); + uv_set_sys_error(loop, WSAGetLastError()); return -1; } - if (uv_udp_set_socket(handle, sock) == -1) { + if (uv_udp_set_socket(loop, handle, sock) == -1) { closesocket(sock); return -1; } @@ -162,14 +166,18 @@ static int uv__bind(uv_udp_t* handle, int domain, struct sockaddr* addr, /* TODO: how to handle errors? This may fail if there is no ipv4 stack */ /* available, or when run on XP/2003 which have no support for dualstack */ /* sockets. For now we're silently ignoring the error. */ - setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (const char*) &off, sizeof off); + setsockopt(sock, + IPPROTO_IPV6, + IPV6_V6ONLY, + (const char*) &off, + sizeof off); } r = bind(handle->socket, addr, addrsize); if (r == SOCKET_ERROR) { err = WSAGetLastError(); - uv_set_sys_error(WSAGetLastError()); + uv_set_sys_error(loop, WSAGetLastError()); return -1; } @@ -179,9 +187,12 @@ static int uv__bind(uv_udp_t* handle, int domain, struct sockaddr* addr, } -int uv_udp_bind(uv_udp_t* handle, struct sockaddr_in addr, unsigned int flags) { +int uv_udp_bind(uv_udp_t* handle, struct sockaddr_in addr, + unsigned int flags) { + uv_loop_t* loop = handle->loop; + if (addr.sin_family != AF_INET) { - uv_set_sys_error(WSAEFAULT); + uv_set_sys_error(loop, WSAEFAULT); return -1; } @@ -193,9 +204,12 @@ int uv_udp_bind(uv_udp_t* handle, struct sockaddr_in addr, unsigned int flags) { } -int uv_udp_bind6(uv_udp_t* handle, struct sockaddr_in6 addr, unsigned int flags) { +int uv_udp_bind6(uv_udp_t* handle, struct sockaddr_in6 addr, + unsigned int flags) { + uv_loop_t* loop = handle->loop; + if (addr.sin6_family != AF_INET6) { - uv_set_sys_error(WSAEFAULT); + uv_set_sys_error(loop, WSAEFAULT); return -1; } @@ -213,7 +227,7 @@ int uv_udp_bind6(uv_udp_t* handle, struct sockaddr_in6 addr, unsigned int flags) } -static void uv_udp_queue_recv(uv_udp_t* handle) { +static void uv_udp_queue_recv(uv_loop_t* loop, uv_udp_t* handle) { uv_req_t* req; uv_buf_t buf; DWORD bytes, flags; @@ -256,7 +270,7 @@ static void uv_udp_queue_recv(uv_udp_t* handle) { handle->flags |= UV_HANDLE_READ_PENDING; req->overlapped.InternalHigh = bytes; handle->reqs_pending++; - uv_insert_pending_req(req); + uv_insert_pending_req(loop, req); } else if (UV_SUCCEEDED_WITH_IOCP(result == 0)) { /* The req will be processed with IOCP. */ handle->flags |= UV_HANDLE_READ_PENDING; @@ -264,7 +278,7 @@ static void uv_udp_queue_recv(uv_udp_t* handle) { } else { /* Make this req pending reporting an error. */ SET_REQ_ERROR(req, WSAGetLastError()); - uv_insert_pending_req(req); + uv_insert_pending_req(loop, req); handle->reqs_pending++; } #if 0 @@ -288,7 +302,7 @@ static void uv_udp_queue_recv(uv_udp_t* handle) { handle->flags |= UV_HANDLE_READ_PENDING; req->overlapped.InternalHigh = bytes; handle->reqs_pending++; - uv_insert_pending_req(req); + uv_insert_pending_req(loop, req); } else if (UV_SUCCEEDED_WITH_IOCP(result == 0)) { /* The req will be processed with IOCP. */ handle->flags |= UV_HANDLE_READ_PENDING; @@ -296,7 +310,7 @@ static void uv_udp_queue_recv(uv_udp_t* handle) { } else { /* Make this req pending reporting an error. */ SET_REQ_ERROR(req, WSAGetLastError()); - uv_insert_pending_req(req); + uv_insert_pending_req(loop, req); handle->reqs_pending++; } } @@ -304,9 +318,12 @@ static void uv_udp_queue_recv(uv_udp_t* handle) { } -int uv_udp_recv_start(uv_udp_t* handle, uv_alloc_cb alloc_cb, uv_udp_recv_cb recv_cb) { +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; + if (handle->flags & UV_HANDLE_READING) { - uv_set_sys_error(WSAEALREADY); + uv_set_sys_error(loop, WSAEALREADY); return -1; } @@ -324,7 +341,7 @@ int uv_udp_recv_start(uv_udp_t* handle, uv_alloc_cb alloc_cb, uv_udp_recv_cb rec /* If reading was stopped and then started again, there could stell be a */ /* recv request pending. */ if (!(handle->flags & UV_HANDLE_READ_PENDING)) - uv_udp_queue_recv(handle); + uv_udp_queue_recv(loop, handle); return 0; } @@ -342,6 +359,7 @@ int uv_udp_recv_stop(uv_udp_t* handle) { int uv_udp_connect6(uv_connect_t* req, uv_udp_t* handle, struct sockaddr_in6 address, uv_connect_cb cb) { + uv_loop_t* loop = handle->loop; int addrsize = sizeof(struct sockaddr_in6); BOOL success; DWORD bytes; @@ -352,7 +370,7 @@ int uv_udp_connect6(uv_connect_t* req, uv_udp_t* handle, } if (address.sin6_family != AF_INET6) { - uv_set_sys_error(WSAEFAULT); + uv_set_sys_error(loop, WSAEFAULT); return -1; } @@ -360,7 +378,7 @@ int uv_udp_connect6(uv_connect_t* req, uv_udp_t* handle, uv_udp_bind6(handle, uv_addr_ip6_any_, 0) < 0) return -1; - uv_req_init((uv_req_t*) req); + uv_req_init(loop, (uv_req_t*) req); req->type = UV_CONNECT; req->handle = (uv_stream_t*) handle; req->cb = cb; @@ -376,11 +394,11 @@ int uv_udp_connect6(uv_connect_t* req, uv_udp_t* handle, if (UV_SUCCEEDED_WITHOUT_IOCP(success)) { handle->reqs_pending++; - uv_insert_pending_req((uv_req_t*)req); + uv_insert_pending_req(loop, (uv_req_t*)req); } else if (UV_SUCCEEDED_WITH_IOCP(success)) { handle->reqs_pending++; } else { - uv_set_sys_error(WSAGetLastError()); + uv_set_sys_error(loop, WSAGetLastError()); return -1; } @@ -390,9 +408,10 @@ int uv_udp_connect6(uv_connect_t* req, uv_udp_t* handle, static int uv__udp_send(uv_udp_send_t* req, uv_udp_t* handle, uv_buf_t bufs[], int bufcnt, struct sockaddr* addr, int addr_len, uv_udp_send_cb cb) { + uv_loop_t* loop = handle->loop; DWORD result, bytes; - uv_req_init((uv_req_t*) req); + uv_req_init(loop, (uv_req_t*) req); req->type = UV_UDP_SEND; req->handle = handle; req->cb = cb; @@ -412,14 +431,14 @@ static int uv__udp_send(uv_udp_send_t* req, uv_udp_t* handle, uv_buf_t bufs[], /* Request completed immediately. */ req->queued_bytes = 0; handle->reqs_pending++; - uv_insert_pending_req((uv_req_t*)req); + uv_insert_pending_req(loop, (uv_req_t*)req); } else if (UV_SUCCEEDED_WITH_IOCP(result == 0)) { /* Request queued by the kernel. */ req->queued_bytes = uv_count_bufs(bufs, bufcnt); handle->reqs_pending++; } else { /* Send failed due to an error. */ - uv_set_sys_error(WSAGetLastError()); + uv_set_sys_error(loop, WSAGetLastError()); return -1; } @@ -463,7 +482,8 @@ int uv_udp_send6(uv_udp_send_t* req, uv_udp_t* handle, uv_buf_t bufs[], } -void uv_process_udp_recv_req(uv_udp_t* handle, uv_req_t* req) { +void uv_process_udp_recv_req(uv_loop_t* loop, uv_udp_t* handle, + uv_req_t* req) { uv_buf_t buf; int partial; @@ -475,7 +495,7 @@ void uv_process_udp_recv_req(uv_udp_t* handle, uv_req_t* req) { GET_REQ_STATUS(req) != STATUS_RECEIVE_EXPEDITED) { /* An error occurred doing the read. */ if ((handle->flags & UV_HANDLE_READING)) { - LOOP->last_error = GET_REQ_UV_SOCK_ERROR(req); + loop->last_error = GET_REQ_UV_SOCK_ERROR(req); uv_udp_recv_stop(handle); #if 0 buf = (handle->flags & UV_HANDLE_ZERO_READ) ? @@ -532,11 +552,11 @@ void uv_process_udp_recv_req(uv_udp_t* handle, uv_req_t* req) { } else { err = WSAGetLastError(); if (err == WSAEWOULDBLOCK) { - uv_set_sys_error(WSAEWOULDBLOCK); + uv_set_sys_error(loop, WSAEWOULDBLOCK); handle->recv_cb(handle, 0, buf, NULL, 0); } else { /* Ouch! serious error. */ - uv_set_sys_error(err); + uv_set_sys_error(loop, err); handle->recv_cb(handle, -1, buf, NULL, 0); } } @@ -547,21 +567,22 @@ done: /* Post another read if still reading and not closing. */ if ((handle->flags & UV_HANDLE_READING) && !(handle->flags & UV_HANDLE_READ_PENDING)) { - uv_udp_queue_recv(handle); + uv_udp_queue_recv(loop, handle); } DECREASE_PENDING_REQ_COUNT(handle); } -void uv_process_udp_send_req(uv_udp_t* handle, uv_udp_send_t* req) { +void uv_process_udp_send_req(uv_loop_t* loop, uv_udp_t* handle, + uv_udp_send_t* req) { assert(handle->type == UV_UDP); if (req->cb) { if (REQ_SUCCESS(req)) { req->cb(req, 0); } else { - LOOP->last_error = GET_REQ_UV_SOCK_ERROR(req); + loop->last_error = GET_REQ_UV_SOCK_ERROR(req); req->cb(req, -1); } } diff --git a/deps/uv/src/win/util.c b/deps/uv/src/win/util.c index 65679b101..67de53e5c 100644 --- a/deps/uv/src/win/util.c +++ b/deps/uv/src/win/util.c @@ -27,13 +27,27 @@ #include "internal.h" -int uv_utf16_to_utf8(const wchar_t* utf16Buffer, size_t utf16Size, char* utf8Buffer, size_t utf8Size) { - return WideCharToMultiByte(CP_UTF8, 0, utf16Buffer, utf16Size, utf8Buffer, utf8Size, NULL, NULL); +int uv_utf16_to_utf8(const wchar_t* utf16Buffer, size_t utf16Size, + char* utf8Buffer, size_t utf8Size) { + return WideCharToMultiByte(CP_UTF8, + 0, + utf16Buffer, + utf16Size, + utf8Buffer, + utf8Size, + NULL, + NULL); } -int uv_utf8_to_utf16(const char* utf8Buffer, wchar_t* utf16Buffer, size_t utf16Size) { - return MultiByteToWideChar(CP_UTF8, 0, utf8Buffer, -1, utf16Buffer, utf16Size); +int uv_utf8_to_utf16(const char* utf8Buffer, wchar_t* utf16Buffer, + size_t utf16Size) { + return MultiByteToWideChar(CP_UTF8, + 0, + utf8Buffer, + -1, + utf16Buffer, + utf16Size); } @@ -55,7 +69,7 @@ int uv_exepath(char* buffer, size_t* size) { /* Get the path as UTF-16 */ utf16Size = GetModuleFileNameW(NULL, utf16Buffer, *size - 1); if (utf16Size <= 0) { - uv_set_sys_error(GetLastError()); + /* uv_set_sys_error(loop, GetLastError()); */ retVal = -1; goto done; } @@ -65,7 +79,7 @@ int uv_exepath(char* buffer, size_t* size) { /* Convert to UTF-8 */ *size = uv_utf16_to_utf8(utf16Buffer, utf16Size, buffer, *size); if (!*size) { - uv_set_sys_error(GetLastError()); + /* uv_set_sys_error(loop, GetLastError()); */ retVal = -1; goto done; } diff --git a/deps/uv/test/benchmark-ares.c b/deps/uv/test/benchmark-ares.c index d4d88e033..5b24402d6 100644 --- a/deps/uv/test/benchmark-ares.c +++ b/deps/uv/test/benchmark-ares.c @@ -26,6 +26,8 @@ #include <stdio.h> #include <string.h> /* strlen */ +static uv_loop_t* loop; + ares_channel channel; struct ares_options options; int optmask; @@ -67,7 +69,7 @@ static void prep_tcploopback() options.tcp_port = htons(TEST_PORT_2); options.flags = ARES_FLAG_USEVC; - rc = uv_ares_init_options(&channel, &options, optmask); + rc = uv_ares_init_options(loop, &channel, &options, optmask); ASSERT(rc == ARES_SUCCESS); } @@ -85,11 +87,13 @@ BENCHMARK_IMPL(gethostbyname) { } uv_init(); + loop = uv_default_loop(); + ares_callbacks = 0; ares_errors = 0; - uv_update_time(); - start_time = uv_now(); + uv_update_time(loop); + start_time = uv_now(loop); prep_tcploopback(); @@ -101,11 +105,11 @@ BENCHMARK_IMPL(gethostbyname) { &argument); } - uv_run(); + uv_run(loop); - uv_ares_destroy(channel); + uv_ares_destroy(loop, channel); - end_time = uv_now(); + end_time = uv_now(loop); if (ares_errors > 0) { printf("There were %d failures\n", ares_errors); diff --git a/deps/uv/test/benchmark-getaddrinfo.c b/deps/uv/test/benchmark-getaddrinfo.c index 00366e616..31503d805 100644 --- a/deps/uv/test/benchmark-getaddrinfo.c +++ b/deps/uv/test/benchmark-getaddrinfo.c @@ -32,6 +32,8 @@ const char* name = "localhost"; +static uv_loop_t* loop; + static uv_getaddrinfo_t handles[CONCURRENT_CALLS]; static int calls_initiated = 0; @@ -58,7 +60,7 @@ static void getaddrinfo_initiate(uv_getaddrinfo_t* handle) { calls_initiated++; - r = uv_getaddrinfo(handle, &getaddrinfo_cb, name, NULL, NULL); + r = uv_getaddrinfo(loop, handle, &getaddrinfo_cb, name, NULL, NULL); ASSERT(r == 0); } @@ -66,19 +68,20 @@ static void getaddrinfo_initiate(uv_getaddrinfo_t* handle) { BENCHMARK_IMPL(getaddrinfo) { int i; - uv_init(); + uv_init(loop); + loop = uv_default_loop(); - uv_update_time(); - start_time = uv_now(); + uv_update_time(loop); + start_time = uv_now(loop); for (i = 0; i < CONCURRENT_CALLS; i++) { getaddrinfo_initiate(&handles[i]); } - uv_run(); + uv_run(loop); - uv_update_time(); - end_time = uv_now(); + uv_update_time(loop); + end_time = uv_now(loop); ASSERT(calls_initiated == TOTAL_CALLS); ASSERT(calls_completed == TOTAL_CALLS); diff --git a/deps/uv/test/benchmark-ping-pongs.c b/deps/uv/test/benchmark-ping-pongs.c index 805672399..c3263ae5f 100644 --- a/deps/uv/test/benchmark-ping-pongs.c +++ b/deps/uv/test/benchmark-ping-pongs.c @@ -46,6 +46,8 @@ typedef struct buf_s { static char PING[] = "PING\n"; +static uv_loop_t* loop; + static buf_t* buf_freelist = NULL; static int pinger_shutdown_cb_called; static int completed_pingers = 0; @@ -130,7 +132,7 @@ static void pinger_read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) { pinger = (pinger_t*)tcp->data; if (nread < 0) { - ASSERT(uv_last_error().code == UV_EOF); + ASSERT(uv_last_error(loop).code == UV_EOF); if (buf.base) { buf_free(buf); @@ -148,7 +150,7 @@ static void pinger_read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) { pinger->state = (pinger->state + 1) % (sizeof(PING) - 1); if (pinger->state == 0) { pinger->pongs++; - if (uv_now() - start_time > TIME) { + if (uv_now(loop) - start_time > TIME) { uv_shutdown(&pinger->shutdown_req, (uv_stream_t*) tcp, pinger_shutdown_cb); break; } else { @@ -185,7 +187,7 @@ static void pinger_new() { pinger->pongs = 0; /* Try to connec to the server and do NUM_PINGS ping-pongs. */ - r = uv_tcp_init(&pinger->tcp); + r = uv_tcp_init(loop, &pinger->tcp); ASSERT(!r); pinger->tcp.data = pinger; @@ -199,10 +201,12 @@ static void pinger_new() { BENCHMARK_IMPL(ping_pongs) { uv_init(); - start_time = uv_now(); + loop = uv_default_loop(); + + start_time = uv_now(loop); pinger_new(); - uv_run(); + uv_run(loop); ASSERT(completed_pingers == 1); diff --git a/deps/uv/test/benchmark-pound.c b/deps/uv/test/benchmark-pound.c index bae5e46f8..c2c41c07a 100644 --- a/deps/uv/test/benchmark-pound.c +++ b/deps/uv/test/benchmark-pound.c @@ -65,6 +65,8 @@ typedef struct { static char buffer[] = "QS"; +static uv_loop_t* loop; + static tcp_conn_rec tcp_conns[MAX_CONNS]; static pipe_conn_rec pipe_conns[MAX_CONNS]; @@ -89,7 +91,7 @@ static uv_buf_t alloc_cb(uv_handle_t* handle, size_t suggested_size) { static void after_write(uv_write_t* req, int status) { if (status != 0) { - fprintf(stderr, "write error %s\n", uv_err_name(uv_last_error())); + fprintf(stderr, "write error %s\n", uv_err_name(uv_last_error(loop))); uv_close((uv_handle_t*)req->handle, close_cb); conns_failed++; return; @@ -134,7 +136,7 @@ static void connect_cb(uv_connect_t* req, int status) { static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) { conn_rec* p = (conn_rec*)stream->data; - uv_err_t err = uv_last_error(); + uv_err_t err = uv_last_error(loop); ASSERT(stream != NULL); @@ -150,7 +152,7 @@ static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) { } else if (err.code == UV_ECONNRESET) { conns_failed++; } else { - fprintf(stderr, "read error %s\n", uv_err_name(uv_last_error())); + fprintf(stderr, "read error %s\n", uv_err_name(uv_last_error(loop))); ASSERT(0); } } @@ -167,7 +169,7 @@ static void close_cb(uv_handle_t* handle) { printf("close_cb %d\n", p->i); #endif - if (uv_now() - start < 10000) { + if (uv_now(loop) - start < 10000) { p->make_connect(p); } } @@ -195,7 +197,7 @@ static void tcp_make_connect(conn_rec* p) { struct sockaddr_in addr; int r; - r = uv_tcp_init((uv_tcp_t*)&p->stream); + r = uv_tcp_init(loop, (uv_tcp_t*)&p->stream); ASSERT(r == 0); addr = uv_ip4_addr("127.0.0.1", TEST_PORT); @@ -203,7 +205,7 @@ static void tcp_make_connect(conn_rec* p) { r = uv_tcp_connect(&((tcp_conn_rec*)p)->conn_req, (uv_tcp_t*)&p->stream, addr, connect_cb); if (r) { fprintf(stderr, "uv_tcp_connect error %s\n", - uv_err_name(uv_last_error())); + uv_err_name(uv_last_error(loop))); ASSERT(0); } @@ -220,13 +222,13 @@ static void tcp_make_connect(conn_rec* p) { static void pipe_make_connect(conn_rec* p) { int r; - r = uv_pipe_init((uv_pipe_t*)&p->stream); + r = uv_pipe_init(loop, (uv_pipe_t*)&p->stream); ASSERT(r == 0); r = uv_pipe_connect(&((pipe_conn_rec*)p)->conn_req, (uv_pipe_t*)&p->stream, TEST_PIPENAME, connect_cb); if (r) { fprintf(stderr, "uv_tcp_connect error %s\n", - uv_err_name(uv_last_error())); + uv_err_name(uv_last_error(loop))); ASSERT(0); } @@ -276,9 +278,10 @@ static int pound_it(int concurrency, uint64_t end_time; uv_init(); + loop = uv_default_loop(); - uv_update_time(); - start = uv_now(); + uv_update_time(loop); + start = uv_now(loop); /* Run benchmark for at least five seconds. */ start_time = uv_hrtime(); @@ -288,7 +291,7 @@ static int pound_it(int concurrency, r = do_connect(concurrency, make_connect, arg); ASSERT(!r); - uv_run(); + uv_run(loop); end_time = uv_hrtime(); diff --git a/deps/uv/test/benchmark-pump.c b/deps/uv/test/benchmark-pump.c index 7713a5858..abbb7be28 100644 --- a/deps/uv/test/benchmark-pump.c +++ b/deps/uv/test/benchmark-pump.c @@ -44,6 +44,7 @@ static void req_free(uv_req_t* uv_req); static uv_buf_t buf_alloc(uv_handle_t*, size_t size); static void buf_free(uv_buf_t uv_buf_t); +static uv_loop_t* loop; static uv_tcp_t tcpServer; static uv_pipe_t pipeServer; @@ -97,8 +98,8 @@ static void show_stats(uv_timer_t* handle, int status) { /* Exit if the show is over */ if (!--stats_left) { - uv_update_time(); - diff = uv_now() - start_time; + uv_update_time(loop); + diff = uv_now(loop) - start_time; LOGF("%s_pump%d_client: %.1f gbit/s\n", type == TCP ? "tcp" : "pipe", write_sockets, gbit(nsent_total, diff)); @@ -119,8 +120,8 @@ static void show_stats(uv_timer_t* handle, int status) { static void read_show_stats() { int64_t diff; - uv_update_time(); - diff = uv_now() - start_time; + uv_update_time(loop); + diff = uv_now(loop) - start_time; LOGF("%s_pump%d_server: %.1f gbit/s\n", type == TCP ? "tcp" : "pipe", max_read_sockets, gbit(nrecv_total, diff)); @@ -141,7 +142,7 @@ void read_sockets_close_cb(uv_handle_t* handle) { /* If it's past the first second and everyone has closed their connection * Then print stats. */ - if (uv_now() - start_time > 1000 && read_sockets == 0) { + if (uv_now(loop) - start_time > 1000 && read_sockets == 0) { read_show_stats(); uv_close((uv_handle_t*)server, NULL); } @@ -153,21 +154,21 @@ static void start_stats_collection() { /* Show-stats timer */ stats_left = STATS_COUNT; - r = uv_timer_init(&timer_handle); + r = uv_timer_init(loop, &timer_handle); ASSERT(r == 0); r = uv_timer_start(&timer_handle, show_stats, STATS_INTERVAL, STATS_INTERVAL); ASSERT(r == 0); - uv_update_time(); - start_time = uv_now(); + uv_update_time(loop); + start_time = uv_now(loop); } static void read_cb(uv_stream_t* stream, ssize_t bytes, uv_buf_t buf) { if (nrecv_total == 0) { ASSERT(start_time == 0); - uv_update_time(); - start_time = uv_now(); + uv_update_time(loop); + start_time = uv_now(loop); } if (bytes < 0) { @@ -213,7 +214,7 @@ static void do_write(uv_stream_t* stream) { static void connect_cb(uv_connect_t* req, int status) { int i; - if (status) LOG(uv_strerror(uv_last_error())); + if (status) LOG(uv_strerror(uv_last_error(loop))); ASSERT(status == 0); write_sockets++; @@ -243,7 +244,7 @@ static void maybe_connect_some() { if (type == TCP) { tcp = &tcp_write_handles[max_connect_socket++]; - r = uv_tcp_init(tcp); + r = uv_tcp_init(loop, tcp); ASSERT(r == 0); req = (uv_connect_t*) req_alloc(); @@ -252,7 +253,7 @@ static void maybe_connect_some() { } else { pipe = &pipe_write_handles[max_connect_socket++]; - r = uv_pipe_init(pipe); + r = uv_pipe_init(loop, pipe); ASSERT(r == 0); req = (uv_connect_t*) req_alloc(); @@ -272,10 +273,10 @@ static void connection_cb(uv_stream_t* s, int status) { if (type == TCP) { stream = (uv_stream_t*)malloc(sizeof(uv_tcp_t)); - uv_tcp_init((uv_tcp_t*)stream); + uv_tcp_init(loop, (uv_tcp_t*)stream); } else { stream = (uv_stream_t*)malloc(sizeof(uv_pipe_t)); - uv_pipe_init((uv_pipe_t*)stream); + uv_pipe_init(loop, (uv_pipe_t*)stream); } r = uv_accept(s, stream); @@ -367,18 +368,20 @@ HELPER_IMPL(tcp_pump_server) { type = TCP; uv_init(); + loop = uv_default_loop(); + listen_addr = uv_ip4_addr("0.0.0.0", TEST_PORT); /* Server */ server = (uv_stream_t*)&tcpServer; - r = uv_tcp_init(&tcpServer); + r = uv_tcp_init(loop, &tcpServer); ASSERT(r == 0); r = uv_tcp_bind(&tcpServer, listen_addr); ASSERT(r == 0); r = uv_listen((uv_stream_t*)&tcpServer, MAX_WRITE_HANDLES, connection_cb); ASSERT(r == 0); - uv_run(); + uv_run(loop); return 0; } @@ -389,17 +392,18 @@ HELPER_IMPL(pipe_pump_server) { type = PIPE; uv_init(); + loop = uv_default_loop(); /* Server */ server = (uv_stream_t*)&pipeServer; - r = uv_pipe_init(&pipeServer); + r = uv_pipe_init(loop, &pipeServer); ASSERT(r == 0); r = uv_pipe_bind(&pipeServer, TEST_PIPENAME); ASSERT(r == 0); r = uv_listen((uv_stream_t*)&pipeServer, MAX_WRITE_HANDLES, connection_cb); ASSERT(r == 0); - uv_run(); + uv_run(loop); return 0; } @@ -411,13 +415,14 @@ void tcp_pump(int n) { type = TCP; uv_init(); + loop = uv_default_loop(); connect_addr = uv_ip4_addr("127.0.0.1", TEST_PORT); /* Start making connections */ maybe_connect_some(); - uv_run(); + uv_run(loop); } @@ -427,11 +432,12 @@ void pipe_pump(int n) { type = PIPE; uv_init(); + loop = uv_default_loop(); /* Start making connections */ maybe_connect_some(); - uv_run(); + uv_run(loop); } diff --git a/deps/uv/test/benchmark-spawn.c b/deps/uv/test/benchmark-spawn.c index 46ddca0e3..9798f9d95 100644 --- a/deps/uv/test/benchmark-spawn.c +++ b/deps/uv/test/benchmark-spawn.c @@ -24,6 +24,8 @@ #include "task.h" #include "uv.h" +static uv_loop_t* loop; + static int N = 1000; static int done; @@ -85,7 +87,7 @@ void pipe_close_cb(uv_handle_t* pipe) { void on_read(uv_stream_t* pipe, ssize_t nread, uv_buf_t buf) { - uv_err_t err = uv_last_error(); + uv_err_t err = uv_last_error(loop); if (nread > 0) { ASSERT(pipe_open == 1); @@ -111,10 +113,10 @@ static void spawn() { options.args = args; options.exit_cb = exit_cb; - uv_pipe_init(&out); + uv_pipe_init(loop, &out); options.stdout_stream = &out; - r = uv_spawn(&process, options); + r = uv_spawn(loop, &process, options); ASSERT(r == 0); process_open = 1; @@ -131,21 +133,22 @@ BENCHMARK_IMPL(spawn) { static int64_t start_time, end_time; uv_init(); + loop = uv_default_loop(); r = uv_exepath(exepath, &exepath_size); ASSERT(r == 0); exepath[exepath_size] = '\0'; - uv_update_time(); - start_time = uv_now(); + uv_update_time(loop); + start_time = uv_now(loop); spawn(); - r = uv_run(); + r = uv_run(loop); ASSERT(r == 0); - uv_update_time(); - end_time = uv_now(); + uv_update_time(loop); + end_time = uv_now(loop); LOGF("spawn: %.0f spawns/s\n", (double) N / (double) (end_time - start_time) * 1000.0); diff --git a/deps/uv/test/benchmark-udp-packet-storm.c b/deps/uv/test/benchmark-udp-packet-storm.c index 9b97ffef3..2be773831 100644 --- a/deps/uv/test/benchmark-udp-packet-storm.c +++ b/deps/uv/test/benchmark-udp-packet-storm.c @@ -37,6 +37,8 @@ #define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0])) +static uv_loop_t* loop; + static int n_senders_; static int n_receivers_; static uv_udp_t senders[MAX_SENDERS]; @@ -91,7 +93,7 @@ static void recv_cb(uv_udp_t* handle, return; if (nread == -1) { - ASSERT(uv_last_error().code == UV_EINTR); /* FIXME change error code */ + ASSERT(uv_last_error(loop).code == UV_EINTR); /* FIXME change error code */ return; } @@ -133,24 +135,25 @@ static int do_packet_storm(int n_senders, int n_receivers) { ASSERT(n_receivers <= MAX_RECEIVERS); uv_init(); + loop = uv_default_loop(); n_senders_ = n_senders; n_receivers_ = n_receivers; - r = uv_timer_init(&timeout); + r = uv_timer_init(loop, &timeout); ASSERT(r == 0); r = uv_timer_start(&timeout, timeout_cb, TEST_DURATION, 0); ASSERT(r == 0); /* Timer should not keep loop alive. */ - uv_unref(); + uv_unref(loop); for (i = 0; i < n_receivers; i++) { struct sockaddr_in addr; handle = &receivers[i]; - r = uv_udp_init(handle); + r = uv_udp_init(loop, handle); ASSERT(r == 0); addr = uv_ip4_addr("0.0.0.0", BASE_PORT + i); @@ -171,7 +174,7 @@ static int do_packet_storm(int n_senders, int n_receivers) { for (i = 0; i < n_senders; i++) { handle = &senders[i]; - r = uv_udp_init(handle); + r = uv_udp_init(loop, handle); ASSERT(r == 0); req = malloc(sizeof(*req) + sizeof(*ss)); @@ -185,7 +188,7 @@ static int do_packet_storm(int n_senders, int n_receivers) { req->data = ss; } - uv_run(); + uv_run(loop); printf("udp_packet_storm_%dv%d: %.0f/s received, %.0f/s sent\n", n_receivers, diff --git a/deps/uv/test/dns-server.c b/deps/uv/test/dns-server.c index 2e4a8f394..e45372e5b 100644 --- a/deps/uv/test/dns-server.c +++ b/deps/uv/test/dns-server.c @@ -47,6 +47,9 @@ typedef struct { } dnshandle; +static uv_loop_t* loop; + + static int server_closed; static uv_tcp_t server; @@ -71,7 +74,7 @@ static void after_write(uv_write_t* req, int status) { write_req_t* wr; if (status) { - uv_err_t err = uv_last_error(); + uv_err_t err = uv_last_error(loop); fprintf(stderr, "uv_write error: %s\n", uv_strerror(err)); ASSERT(0); } @@ -220,7 +223,7 @@ static void after_read(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) { if (nread < 0) { /* Error or EOF */ - ASSERT (uv_last_error().code == UV_EOF); + ASSERT (uv_last_error(loop).code == UV_EOF); if (buf.base) { free(buf.base); @@ -269,7 +272,7 @@ static void on_connection(uv_stream_t* server, int status) { handle->state.prevbuf_pos = 0; handle->state.prevbuf_rem = 0; - uv_tcp_init((uv_tcp_t*)handle); + uv_tcp_init(loop, (uv_tcp_t*)handle); r = uv_accept(server, (uv_stream_t*)handle); ASSERT(r == 0); @@ -288,7 +291,7 @@ static int dns_start(int port) { struct sockaddr_in addr = uv_ip4_addr("0.0.0.0", port); int r; - r = uv_tcp_init(&server); + r = uv_tcp_init(loop, &server); if (r) { /* TODO: Error codes */ fprintf(stderr, "Socket creation error\n"); @@ -315,9 +318,11 @@ static int dns_start(int port) { HELPER_IMPL(dns_server) { uv_init(); + loop = uv_default_loop(); + if (dns_start(TEST_PORT_2)) return 1; - uv_run(); + uv_run(loop); return 0; } diff --git a/deps/uv/test/echo-server.c b/deps/uv/test/echo-server.c index 270af3787..ba8a912e3 100644 --- a/deps/uv/test/echo-server.c +++ b/deps/uv/test/echo-server.c @@ -29,6 +29,8 @@ typedef struct { uv_buf_t buf; } write_req_t; +static uv_loop_t* loop; + static int server_closed; static stream_type serverType; static uv_tcp_t tcpServer; @@ -46,7 +48,7 @@ static void after_write(uv_write_t* req, int status) { write_req_t* wr; if (status) { - uv_err_t err = uv_last_error(); + uv_err_t err = uv_last_error(loop); fprintf(stderr, "uv_write error: %s\n", uv_strerror(err)); ASSERT(0); } @@ -72,7 +74,7 @@ static void after_read(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) { if (nread < 0) { /* Error or EOF */ - ASSERT (uv_last_error().code == UV_EOF); + ASSERT (uv_last_error(loop).code == UV_EOF); if (buf.base) { free(buf.base); @@ -133,7 +135,8 @@ static void on_connection(uv_stream_t* server, int status) { int r; if (status != 0) { - fprintf(stderr, "Connect error %d\n", uv_last_error().code); + fprintf(stderr, "Connect error %d\n", + uv_last_error(loop).code); } ASSERT(status == 0); @@ -141,13 +144,13 @@ static void on_connection(uv_stream_t* server, int status) { case TCP: stream = malloc(sizeof(uv_tcp_t)); ASSERT(stream != NULL); - uv_tcp_init((uv_tcp_t*)stream); + uv_tcp_init(loop, (uv_tcp_t*)stream); break; case PIPE: stream = malloc(sizeof(uv_pipe_t)); ASSERT(stream != NULL); - uv_pipe_init((uv_pipe_t*)stream); + uv_pipe_init(loop, (uv_pipe_t*)stream); break; default: @@ -178,7 +181,7 @@ static int tcp4_echo_start(int port) { server = (uv_handle_t*)&tcpServer; serverType = TCP; - r = uv_tcp_init(&tcpServer); + r = uv_tcp_init(loop, &tcpServer); if (r) { /* TODO: Error codes */ fprintf(stderr, "Socket creation error\n"); @@ -195,7 +198,8 @@ static int tcp4_echo_start(int port) { 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())); + fprintf(stderr, "Listen error %s\n", + uv_err_name(uv_last_error(loop))); return 1; } @@ -210,7 +214,7 @@ static int tcp6_echo_start(int port) { server = (uv_handle_t*)&tcpServer; serverType = TCP; - r = uv_tcp_init(&tcpServer); + r = uv_tcp_init(loop, &tcpServer); if (r) { /* TODO: Error codes */ fprintf(stderr, "Socket creation error\n"); @@ -242,21 +246,24 @@ static int pipe_echo_start(char* pipeName) { server = (uv_handle_t*)&pipeServer; serverType = PIPE; - r = uv_pipe_init(&pipeServer); + r = uv_pipe_init(loop, &pipeServer); if (r) { - fprintf(stderr, "uv_pipe_init: %s\n", uv_strerror(uv_last_error())); + fprintf(stderr, "uv_pipe_init: %s\n", + uv_strerror(uv_last_error(loop))); return 1; } r = uv_pipe_bind(&pipeServer, pipeName); if (r) { - fprintf(stderr, "uv_pipe_bind: %s\n", uv_strerror(uv_last_error())); + fprintf(stderr, "uv_pipe_bind: %s\n", + uv_strerror(uv_last_error(loop))); 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())); + fprintf(stderr, "uv_pipe_listen: %s\n", + uv_strerror(uv_last_error(loop))); return 1; } @@ -266,30 +273,35 @@ static int pipe_echo_start(char* pipeName) { HELPER_IMPL(tcp4_echo_server) { uv_init(); + loop = uv_default_loop(); + if (tcp4_echo_start(TEST_PORT)) return 1; - uv_run(); + uv_run(loop); return 0; } HELPER_IMPL(tcp6_echo_server) { uv_init(); + loop = uv_default_loop(); + if (tcp6_echo_start(TEST_PORT)) return 1; - uv_run(); + uv_run(loop); return 0; } HELPER_IMPL(pipe_echo_server) { uv_init(); + loop = uv_default_loop(); if (pipe_echo_start(TEST_PIPENAME)) return 1; - uv_run(); + uv_run(loop); return 0; } diff --git a/deps/uv/test/test-async.c b/deps/uv/test/test-async.c index 2a3a1bfa9..ccf259e23 100644 --- a/deps/uv/test/test-async.c +++ b/deps/uv/test/test-async.c @@ -184,12 +184,12 @@ TEST_IMPL(async) { uv_init(); - r = uv_prepare_init(&prepare_handle); + r = uv_prepare_init(uv_default_loop(), &prepare_handle); ASSERT(r == 0); r = uv_prepare_start(&prepare_handle, prepare_cb); ASSERT(r == 0); - r = uv_async_init(&async1_handle, async1_cb); + r = uv_async_init(uv_default_loop(), &async1_handle, async1_cb); ASSERT(r == 0); #if 0 @@ -197,7 +197,7 @@ TEST_IMPL(async) { ASSERT(r == 0); #endif - r = uv_run(); + r = uv_run(uv_default_loop()); ASSERT(r == 0); r = uv_wait_thread(thread1_id); diff --git a/deps/uv/test/test-callback-stack.c b/deps/uv/test/test-callback-stack.c index 64cc4d9ec..d0f469243 100644 --- a/deps/uv/test/test-callback-stack.c +++ b/deps/uv/test/test-callback-stack.c @@ -76,11 +76,11 @@ static void read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) { free(buf.base); if (nread == 0) { - ASSERT(uv_last_error().code == UV_EAGAIN); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EAGAIN); return; } else if (nread == -1) { - ASSERT(uv_last_error().code == UV_EOF); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EOF); nested++; uv_close((uv_handle_t*)tcp, close_cb); @@ -140,7 +140,7 @@ static void write_cb(uv_write_t* req, int status) { /* back to our receive buffer when we start reading. This maximizes the */ /* tempation for the backend to use dirty stack for calling read_cb. */ nested++; - r = uv_timer_init(&timer); + r = uv_timer_init(uv_default_loop(), &timer); ASSERT(r == 0); r = uv_timer_start(&timer, timer_cb, 500, 0); ASSERT(r == 0); @@ -178,7 +178,7 @@ TEST_IMPL(callback_stack) { uv_init(); - if (uv_tcp_init(&client)) { + if (uv_tcp_init(uv_default_loop(), &client)) { FATAL("uv_tcp_init failed"); } @@ -191,7 +191,7 @@ TEST_IMPL(callback_stack) { } nested--; - uv_run(); + uv_run(uv_default_loop()); ASSERT(nested == 0); ASSERT(connect_cb_called == 1 && "connect_cb must be called exactly once"); diff --git a/deps/uv/test/test-connection-fail.c b/deps/uv/test/test-connection-fail.c index 1c2d21212..099b1ad22 100644 --- a/deps/uv/test/test-connection-fail.c +++ b/deps/uv/test/test-connection-fail.c @@ -69,7 +69,7 @@ static void timer_cb(uv_timer_t* handle, int status) { 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().code == UV_ECONNREFUSED); + ASSERT(uv_last_error(uv_default_loop()).code == UV_ECONNREFUSED); connect_cb_calls++; ASSERT(close_cb_calls == 0); @@ -79,7 +79,7 @@ static void on_connect_with_close(uv_connect_t *req, int status) { static void on_connect_without_close(uv_connect_t *req, int status) { ASSERT(status == -1); - ASSERT(uv_last_error().code == UV_ECONNREFUSED); + ASSERT(uv_last_error(uv_default_loop()).code == UV_ECONNREFUSED); connect_cb_calls++; uv_timer_start(&timer, timer_cb, 100, 0); @@ -98,7 +98,7 @@ void connection_fail(uv_connect_cb connect_cb) { server_addr = uv_ip4_addr("127.0.0.1", TEST_PORT); /* Try to connec to the server and do NUM_PINGS ping-pongs. */ - r = uv_tcp_init(&tcp); + r = uv_tcp_init(uv_default_loop(), &tcp); ASSERT(!r); /* We are never doing multiple reads/connects at a time anyway. */ @@ -107,7 +107,7 @@ void connection_fail(uv_connect_cb connect_cb) { r = uv_tcp_connect(&req, &tcp, server_addr, connect_cb); ASSERT(!r); - uv_run(); + uv_run(uv_default_loop()); ASSERT(connect_cb_calls == 1); ASSERT(close_cb_calls == 1); @@ -138,7 +138,8 @@ TEST_IMPL(connection_fail) { TEST_IMPL(connection_fail_doesnt_auto_close) { uv_init(); - uv_timer_init(&timer); + + uv_timer_init(uv_default_loop(), &timer); connection_fail(on_connect_without_close); diff --git a/deps/uv/test/test-delayed-accept.c b/deps/uv/test/test-delayed-accept.c index 5a2704d4e..85099519b 100644 --- a/deps/uv/test/test-delayed-accept.c +++ b/deps/uv/test/test-delayed-accept.c @@ -57,16 +57,16 @@ static void do_accept(uv_timer_t* timer_handle, int status) { ASSERT(status == 0); ASSERT(accepted_handle != NULL); - uv_tcp_init(accepted_handle); + uv_tcp_init(uv_default_loop(), accepted_handle); - /* Test to that uv_counters()->tcp_init does not increase across the uv_accept. */ - tcpcnt = uv_counters()->tcp_init; + /* Test to that uv_default_loop()->counters.tcp_init does not increase across the uv_accept. */ + tcpcnt = uv_default_loop()->counters.tcp_init; server = (uv_tcp_t*)timer_handle->data; r = uv_accept((uv_stream_t*)server, (uv_stream_t*)accepted_handle); ASSERT(r == 0); - ASSERT(uv_counters()->tcp_init == tcpcnt); + ASSERT(uv_default_loop()->counters.tcp_init == tcpcnt); do_accept_called++; @@ -93,7 +93,7 @@ static void connection_cb(uv_stream_t* tcp, int status) { ASSERT(timer_handle != NULL); /* Accept the client after 1 second */ - r = uv_timer_init(timer_handle); + r = uv_timer_init(uv_default_loop(), timer_handle); ASSERT(r == 0); timer_handle->data = tcp; @@ -112,10 +112,10 @@ static void start_server() { ASSERT(server != NULL); - r = uv_tcp_init(server); + r = uv_tcp_init(uv_default_loop(), server); ASSERT(r == 0); - ASSERT(uv_counters()->tcp_init == 1); - ASSERT(uv_counters()->handle_init == 1); + ASSERT(uv_default_loop()->counters.tcp_init == 1); + ASSERT(uv_default_loop()->counters.handle_init == 1); r = uv_tcp_bind(server, addr); ASSERT(r == 0); @@ -134,11 +134,11 @@ static void read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) { if (nread != -1) { ASSERT(nread == 0); - ASSERT(uv_last_error().code == UV_EAGAIN); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EAGAIN); } else { ASSERT(tcp != NULL); ASSERT(nread == -1); - ASSERT(uv_last_error().code == UV_EOF); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EOF); uv_close((uv_handle_t*)tcp, close_cb); } } @@ -170,7 +170,7 @@ static void client_connect() { ASSERT(client != NULL); ASSERT(connect_req != NULL); - r = uv_tcp_init(client); + r = uv_tcp_init(uv_default_loop(), client); ASSERT(r == 0); r = uv_tcp_connect(connect_req, client, addr, connect_cb); @@ -187,7 +187,7 @@ TEST_IMPL(delayed_accept) { client_connect(); client_connect(); - uv_run(); + uv_run(uv_default_loop()); ASSERT(connection_cb_called == 2); ASSERT(do_accept_called == 2); diff --git a/deps/uv/test/test-fs.c b/deps/uv/test/test-fs.c index 7ad35ea83..4d72abd63 100644 --- a/deps/uv/test/test-fs.c +++ b/deps/uv/test/test-fs.c @@ -58,6 +58,8 @@ static int fdatasync_cb_count; static int ftruncate_cb_count; static int sendfile_cb_count; +static uv_loop_t* loop; + static uv_fs_t open_req1; static uv_fs_t open_req2; static uv_fs_t read_req; @@ -95,7 +97,7 @@ static void close_cb(uv_fs_t* req) { close_cb_count++; uv_fs_req_cleanup(req); if (close_cb_count == 3) { - r = uv_fs_unlink(&unlink_req, "test_file2", unlink_cb); + r = uv_fs_unlink(loop, &unlink_req, "test_file2", unlink_cb); } } @@ -107,7 +109,7 @@ static void ftruncate_cb(uv_fs_t* req) { ASSERT(req->result != -1); ftruncate_cb_count++; uv_fs_req_cleanup(req); - r = uv_fs_close(&close_req, open_req1.result, close_cb); + r = uv_fs_close(loop, &close_req, open_req1.result, close_cb); } @@ -120,10 +122,11 @@ static void read_cb(uv_fs_t* req) { uv_fs_req_cleanup(req); if (read_cb_count == 1) { ASSERT(strcmp(buf, test_buf) == 0); - r = uv_fs_ftruncate(&ftruncate_req, open_req1.result, 7, ftruncate_cb); + r = uv_fs_ftruncate(loop, &ftruncate_req, open_req1.result, 7, + ftruncate_cb); } else { ASSERT(strcmp(buf, "test-bu") == 0); - r = uv_fs_close(&close_req, open_req1.result, close_cb); + r = uv_fs_close(loop, &close_req, open_req1.result, close_cb); } } @@ -132,7 +135,7 @@ static void open_cb(uv_fs_t* req) { int r; ASSERT(req == &open_req1); ASSERT(req->fs_type == UV_FS_OPEN); - if (req->result < 0) { + if (req->result < 0) { /* TODO get error with uv_last_error() */ fprintf(stderr, "async open error: %d\n", req->errorno); ASSERT(0); @@ -140,7 +143,8 @@ static void open_cb(uv_fs_t* req) { open_cb_count++; uv_fs_req_cleanup(req); memset(buf, 0, sizeof(buf)); - r = uv_fs_read(&read_req, open_req1.result, buf, sizeof(buf), -1, read_cb); + r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1, + read_cb); } @@ -151,7 +155,7 @@ static void fsync_cb(uv_fs_t* req) { ASSERT(req->result != -1); fsync_cb_count++; uv_fs_req_cleanup(req); - r = uv_fs_close(&close_req, open_req1.result, close_cb); + r = uv_fs_close(loop, &close_req, open_req1.result, close_cb); } @@ -162,7 +166,7 @@ static void fdatasync_cb(uv_fs_t* req) { ASSERT(req->result != -1); fdatasync_cb_count++; uv_fs_req_cleanup(req); - r = uv_fs_fsync(&fsync_req, open_req1.result, fsync_cb); + r = uv_fs_fsync(loop, &fsync_req, open_req1.result, fsync_cb); } @@ -173,7 +177,7 @@ static void write_cb(uv_fs_t* req) { ASSERT(req->result != -1); write_cb_count++; uv_fs_req_cleanup(req); - r = uv_fs_fdatasync(&fdatasync_req, open_req1.result, fdatasync_cb); + r = uv_fs_fdatasync(loop, &fdatasync_req, open_req1.result, fdatasync_cb); } @@ -184,8 +188,8 @@ static void create_cb(uv_fs_t* req) { ASSERT(req->result != -1); create_cb_count++; uv_fs_req_cleanup(req); - r = uv_fs_write(&write_req, req->result, test_buf, sizeof(test_buf), -1, - write_cb); + r = uv_fs_write(loop, &write_req, req->result, test_buf, sizeof(test_buf), + -1, write_cb); } @@ -222,7 +226,8 @@ static void readdir_cb(uv_fs_t* req) { ASSERT(req->result == 2); ASSERT(req->ptr); ASSERT(strcmp((const char*)req->ptr, "file1") == 0); - ASSERT(strcmp((char*)req->ptr + strlen((const char*)req->ptr) + 1, "file2") == 0); + ASSERT(strcmp((char*)req->ptr + strlen((const char*)req->ptr) + 1, + "file2") == 0); readdir_cb_count++; uv_fs_req_cleanup(req); ASSERT(!req->ptr); @@ -257,11 +262,12 @@ TEST_IMPL(fs_file_async) { unlink("test_file2"); uv_init(); + loop = uv_default_loop(); - r = uv_fs_open(&open_req1, "test_file", O_WRONLY | O_CREAT, + r = uv_fs_open(loop, &open_req1, "test_file", O_WRONLY | O_CREAT, S_IREAD | S_IWRITE, create_cb); ASSERT(r == 0); - uv_run(); + uv_run(loop); ASSERT(create_cb_count == 1); ASSERT(write_cb_count == 1); @@ -269,19 +275,19 @@ TEST_IMPL(fs_file_async) { ASSERT(fdatasync_cb_count == 1); ASSERT(close_cb_count == 1); - r = uv_fs_rename(&rename_req, "test_file", "test_file2", rename_cb); + r = uv_fs_rename(loop, &rename_req, "test_file", "test_file2", rename_cb); ASSERT(r == 0); - uv_run(); + uv_run(loop); ASSERT(create_cb_count == 1); ASSERT(write_cb_count == 1); ASSERT(close_cb_count == 1); ASSERT(rename_cb_count == 1); - r = uv_fs_open(&open_req1, "test_file2", O_RDWR, 0, open_cb); + r = uv_fs_open(loop, &open_req1, "test_file2", O_RDWR, 0, open_cb); ASSERT(r == 0); - uv_run(); + uv_run(loop); ASSERT(open_cb_count == 1); ASSERT(read_cb_count == 1); ASSERT(close_cb_count == 2); @@ -290,10 +296,10 @@ TEST_IMPL(fs_file_async) { ASSERT(write_cb_count == 1); ASSERT(ftruncate_cb_count == 1); - r = uv_fs_open(&open_req1, "test_file2", O_RDONLY, 0, open_cb); + r = uv_fs_open(loop, &open_req1, "test_file2", O_RDONLY, 0, open_cb); ASSERT(r == 0); - - uv_run(); + + uv_run(loop); ASSERT(open_cb_count == 2); ASSERT(read_cb_count == 2); ASSERT(close_cb_count == 3); @@ -319,68 +325,71 @@ TEST_IMPL(fs_file_sync) { unlink("test_file2"); uv_init(); - - r = uv_fs_open(&open_req1, "test_file", O_WRONLY | O_CREAT, + loop = uv_default_loop(); + + r = uv_fs_open(loop, &open_req1, "test_file", O_WRONLY | O_CREAT, S_IWRITE | S_IREAD, NULL); ASSERT(r == 0); ASSERT(open_req1.result != -1); uv_fs_req_cleanup(&open_req1); - - r = uv_fs_write(&write_req, open_req1.result, test_buf, sizeof(test_buf), -1, - NULL); + + r = uv_fs_write(loop, &write_req, open_req1.result, test_buf, + sizeof(test_buf), -1, NULL); ASSERT(r == 0); ASSERT(write_req.result != -1); uv_fs_req_cleanup(&write_req); - r = uv_fs_close(&close_req, open_req1.result, NULL); + r = uv_fs_close(loop, &close_req, open_req1.result, NULL); ASSERT(r == 0); ASSERT(close_req.result != -1); uv_fs_req_cleanup(&close_req); - r = uv_fs_open(&open_req1, "test_file", O_RDWR, 0, NULL); + r = uv_fs_open(loop, &open_req1, "test_file", O_RDWR, 0, NULL); ASSERT(r == 0); ASSERT(open_req1.result != -1); uv_fs_req_cleanup(&open_req1); - r = uv_fs_read(&read_req, open_req1.result, buf, sizeof(buf), -1, NULL); + r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1, + NULL); ASSERT(r == 0); ASSERT(read_req.result != -1); ASSERT(strcmp(buf, test_buf) == 0); uv_fs_req_cleanup(&read_req); - r = uv_fs_ftruncate(&ftruncate_req, open_req1.result, 7, NULL); + r = uv_fs_ftruncate(loop, &ftruncate_req, open_req1.result, 7, NULL); ASSERT(r == 0); ASSERT(ftruncate_req.result != -1); uv_fs_req_cleanup(&ftruncate_req); - r = uv_fs_close(&close_req, open_req1.result, NULL); + r = uv_fs_close(loop, &close_req, open_req1.result, NULL); ASSERT(r == 0); ASSERT(close_req.result != -1); uv_fs_req_cleanup(&close_req); - r = uv_fs_rename(&rename_req, "test_file", "test_file2", NULL); + r = uv_fs_rename(loop, &rename_req, "test_file", "test_file2", NULL); ASSERT(r == 0); ASSERT(rename_req.result != -1); uv_fs_req_cleanup(&rename_req); - r = uv_fs_open(&open_req1, "test_file2", O_RDONLY, 0, NULL); + r = uv_fs_open(loop, &open_req1, "test_file2", O_RDONLY, 0, NULL); ASSERT(r == 0); ASSERT(open_req1.result != -1); uv_fs_req_cleanup(&open_req1); memset(buf, 0, sizeof(buf)); - r = uv_fs_read(&read_req, open_req1.result, buf, sizeof(buf), -1, NULL); + r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1, + NULL); ASSERT(r == 0); ASSERT(read_req.result != -1); ASSERT(strcmp(buf, "test-bu") == 0); uv_fs_req_cleanup(&read_req); - r = uv_fs_close(&close_req, open_req1.result, NULL); + r = uv_fs_close(loop, &close_req, open_req1.result, NULL); ASSERT(r == 0); ASSERT(close_req.result != -1); uv_fs_req_cleanup(&close_req); - r = uv_fs_unlink(&unlink_req, "test_file2", NULL); + r = uv_fs_unlink(loop, &unlink_req, "test_file2", NULL); ASSERT(r == 0); ASSERT(unlink_req.result != -1); uv_fs_req_cleanup(&unlink_req); @@ -402,67 +411,68 @@ TEST_IMPL(fs_async_dir) { rmdir("test_dir"); uv_init(); + loop = uv_default_loop(); - r = uv_fs_mkdir(&mkdir_req, "test_dir", 0755, mkdir_cb); + r = uv_fs_mkdir(loop, &mkdir_req, "test_dir", 0755, mkdir_cb); ASSERT(r == 0); - uv_run(); + uv_run(loop); ASSERT(mkdir_cb_count == 1); /* Create 2 files synchronously. */ - r = uv_fs_open(&open_req1, "test_dir/file1", O_WRONLY | O_CREAT, + r = uv_fs_open(loop, &open_req1, "test_dir/file1", O_WRONLY | O_CREAT, S_IWRITE | S_IREAD, NULL); ASSERT(r == 0); uv_fs_req_cleanup(&open_req1); - r = uv_fs_close(&close_req, open_req1.result, NULL); + r = uv_fs_close(loop, &close_req, open_req1.result, NULL); ASSERT(r == 0); uv_fs_req_cleanup(&close_req); - r = uv_fs_open(&open_req1, "test_dir/file2", O_WRONLY | O_CREAT, + r = uv_fs_open(loop, &open_req1, "test_dir/file2", O_WRONLY | O_CREAT, S_IWRITE | S_IREAD, NULL); ASSERT(r == 0); uv_fs_req_cleanup(&open_req1); - r = uv_fs_close(&close_req, open_req1.result, NULL); + r = uv_fs_close(loop, &close_req, open_req1.result, NULL); ASSERT(r == 0); uv_fs_req_cleanup(&close_req); - r = uv_fs_readdir(&readdir_req, "test_dir", 0, readdir_cb); + r = uv_fs_readdir(loop, &readdir_req, "test_dir", 0, readdir_cb); ASSERT(r == 0); - uv_run(); + uv_run(loop); ASSERT(readdir_cb_count == 1); - r = uv_fs_stat(&stat_req, "test_dir", stat_cb); + r = uv_fs_stat(loop, &stat_req, "test_dir", stat_cb); ASSERT(r == 0); - uv_run(); + uv_run(loop); - r = uv_fs_stat(&stat_req, "test_dir\\", stat_cb); + r = uv_fs_stat(loop, &stat_req, "test_dir\\", stat_cb); ASSERT(r == 0); - uv_run(); + uv_run(loop); - r = uv_fs_lstat(&stat_req, "test_dir", stat_cb); + r = uv_fs_lstat(loop, &stat_req, "test_dir", stat_cb); ASSERT(r == 0); - uv_run(); + uv_run(loop); - r = uv_fs_lstat(&stat_req, "test_dir\\", stat_cb); + r = uv_fs_lstat(loop, &stat_req, "test_dir\\", stat_cb); ASSERT(r == 0); - uv_run(); + uv_run(loop); ASSERT(stat_cb_count == 4); - r = uv_fs_unlink(&unlink_req, "test_dir/file1", unlink_cb); + r = uv_fs_unlink(loop, &unlink_req, "test_dir/file1", unlink_cb); ASSERT(r == 0); - uv_run(); + uv_run(loop); ASSERT(unlink_cb_count == 1); - r = uv_fs_unlink(&unlink_req, "test_dir/file2", unlink_cb); + r = uv_fs_unlink(loop, &unlink_req, "test_dir/file2", unlink_cb); ASSERT(r == 0); - uv_run(); + uv_run(loop); ASSERT(unlink_cb_count == 2); - r = uv_fs_rmdir(&rmdir_req, "test_dir", rmdir_cb); + r = uv_fs_rmdir(loop, &rmdir_req, "test_dir", rmdir_cb); ASSERT(r == 0); - uv_run(); + uv_run(loop); ASSERT(rmdir_cb_count == 1); /* Cleanup */ @@ -485,7 +495,7 @@ TEST_IMPL(fs_async_sendfile) { f = open("test_file", O_WRONLY | O_CREAT, S_IWRITE | S_IREAD); ASSERT(f != -1); - + r = write(f, "begin\n", 6); ASSERT(r == 6); @@ -500,29 +510,30 @@ TEST_IMPL(fs_async_sendfile) { /* Test starts here. */ uv_init(); + loop = uv_default_loop(); - r = uv_fs_open(&open_req1, "test_file", O_RDWR, 0, NULL); + r = uv_fs_open(loop, &open_req1, "test_file", O_RDWR, 0, NULL); ASSERT(r == 0); ASSERT(open_req1.result != -1); uv_fs_req_cleanup(&open_req1); - r = uv_fs_open(&open_req2, "test_file2", O_WRONLY | O_CREAT, + r = uv_fs_open(loop, &open_req2, "test_file2", O_WRONLY | O_CREAT, S_IWRITE | S_IREAD, NULL); ASSERT(r == 0); ASSERT(open_req2.result != -1); uv_fs_req_cleanup(&open_req2); - r = uv_fs_sendfile(&sendfile_req, open_req2.result, open_req1.result, 0, - 131072, sendfile_cb); + r = uv_fs_sendfile(loop, &sendfile_req, open_req2.result, open_req1.result, + 0, 131072, sendfile_cb); ASSERT(r == 0); - uv_run(); + uv_run(loop); ASSERT(sendfile_cb_count == 1); - r = uv_fs_close(&close_req, open_req1.result, NULL); + r = uv_fs_close(loop, &close_req, open_req1.result, NULL); ASSERT(r == 0); uv_fs_req_cleanup(&close_req); - r = uv_fs_close(&close_req, open_req2.result, NULL); + r = uv_fs_close(loop, &close_req, open_req2.result, NULL); ASSERT(r == 0); uv_fs_req_cleanup(&close_req); diff --git a/deps/uv/test/test-getaddrinfo.c b/deps/uv/test/test-getaddrinfo.c index a33e3d075..a66941d45 100644 --- a/deps/uv/test/test-getaddrinfo.c +++ b/deps/uv/test/test-getaddrinfo.c @@ -69,14 +69,16 @@ TEST_IMPL(getaddrinfo_basic) { uv_init(); - r = uv_getaddrinfo(&getaddrinfo_handle, + + r = uv_getaddrinfo(uv_default_loop(), + &getaddrinfo_handle, &getaddrinfo_basic_cb, name, NULL, NULL); ASSERT(r == 0); - uv_run(); + uv_run(uv_default_loop()); ASSERT(getaddrinfo_cbs == 1); @@ -92,15 +94,16 @@ TEST_IMPL(getaddrinfo_concurrent) { for (i = 0; i < CONCURRENT_COUNT; i++) { callback_counts[i] = 0; - r = uv_getaddrinfo(&getaddrinfo_handles[i], - &getaddrinfo_cuncurrent_cb, - name, - NULL, - NULL); + r = uv_getaddrinfo(uv_default_loop(), + &getaddrinfo_handles[i], + &getaddrinfo_cuncurrent_cb, + name, + NULL, + NULL); ASSERT(r == 0); } - uv_run(); + uv_run(uv_default_loop()); for (i = 0; i < CONCURRENT_COUNT; i++) { ASSERT(callback_counts[i] == 1); diff --git a/deps/uv/test/test-gethostbyname.c b/deps/uv/test/test-gethostbyname.c index cbd25343b..689cc2f3b 100644 --- a/deps/uv/test/test-gethostbyname.c +++ b/deps/uv/test/test-gethostbyname.c @@ -74,7 +74,7 @@ static void prep_tcploopback() { options.tcp_port = htons(TEST_PORT); options.flags = ARES_FLAG_USEVC; - rc = uv_ares_init_options(&channel, &options, optmask); + rc = uv_ares_init_options(uv_default_loop(), &channel, &options, optmask); ASSERT(rc == ARES_SUCCESS); } @@ -104,11 +104,11 @@ TEST_IMPL(gethostbyname) { AF_INET, &aresbynamecallback, &bynamecallbacksig); - uv_run(); + uv_run(uv_default_loop()); ASSERT(ares_bynamecallbacks == 1); - uv_ares_destroy(channel); + uv_ares_destroy(uv_default_loop(), channel); printf("Done basic gethostbyname test\n"); @@ -125,7 +125,7 @@ TEST_IMPL(gethostbyname) { AF_INET, &aresbynamecallback, &bynamecallbacksig); - uv_run(); + uv_run(uv_default_loop()); ASSERT(ares_bynamecallbacks == 1); @@ -143,11 +143,11 @@ TEST_IMPL(gethostbyname) { &aresbyaddrcallback, &byaddrcallbacksig); - uv_run(); + uv_run(uv_default_loop()); ASSERT(ares_byaddrcallbacks == 1); - uv_ares_destroy(channel); + uv_ares_destroy(uv_default_loop(), channel); printf("Done gethostbyname and gethostbyaddr sequential test\n"); @@ -179,13 +179,13 @@ TEST_IMPL(gethostbyname) { &aresbyaddrcallback, &byaddrcallbacksig); - uv_run(); + uv_run(uv_default_loop()); ASSERT(ares_bynamecallbacks == 1); ASSERT(ares_byaddrcallbacks == 1); - uv_ares_destroy(channel); + uv_ares_destroy(uv_default_loop(), channel); printf("Done gethostbyname and gethostbyaddr concurrent test\n"); return 0; diff --git a/deps/uv/test/test-getsockname.c b/deps/uv/test/test-getsockname.c index c1fa8215a..cf0b933e1 100644 --- a/deps/uv/test/test-getsockname.c +++ b/deps/uv/test/test-getsockname.c @@ -29,6 +29,7 @@ static int getsocknamecount = 0; +static uv_loop_t* loop; static uv_tcp_t tcp; static uv_udp_t udp; static uv_connect_t connect_req; @@ -78,14 +79,15 @@ static void on_connection(uv_stream_t* server, int status) { int r; if (status != 0) { - fprintf(stderr, "Connect error %d\n", uv_last_error().code); + fprintf(stderr, "Connect error %d\n", + uv_last_error(loop).code); } ASSERT(status == 0); handle = (uv_handle_t*) malloc(sizeof(uv_tcp_t)); ASSERT(handle != NULL); - uv_tcp_init((uv_tcp_t*)handle); + uv_tcp_init(loop, (uv_tcp_t*)handle); /* associate server with stream */ handle->data = server; @@ -95,7 +97,8 @@ static void on_connection(uv_stream_t* server, int status) { status = uv_getsockname(handle, &sockname, &namelen); if (status != 0) { - fprintf(stderr, "uv_getsockname error (accepted) %d\n", uv_last_error().code); + fprintf(stderr, "uv_getsockname error (accepted) %d\n", + uv_last_error(loop).code); } ASSERT(status == 0); @@ -115,7 +118,8 @@ static void on_connect(uv_connect_t* req, int status) { r = uv_getsockname((uv_handle_t*)&tcp, &sockname, &namelen); if (r != 0) { - fprintf(stderr, "uv_getsockname error (connector) %d\n", uv_last_error().code); + fprintf(stderr, "uv_getsockname error (connector) %d\n", + uv_last_error(loop).code); } ASSERT(r == 0); @@ -132,7 +136,7 @@ static int tcp_listener(int port) { char ip[20]; int r; - r = uv_tcp_init(&tcpServer); + r = uv_tcp_init(loop, &tcpServer); if (r) { fprintf(stderr, "Socket creation error\n"); return 1; @@ -154,7 +158,8 @@ static int tcp_listener(int port) { r = uv_getsockname((uv_handle_t*)&tcpServer, &sockname, &namelen); if (r != 0) { - fprintf(stderr, "uv_getsockname error (listening) %d\n", uv_last_error().code); + fprintf(stderr, "uv_getsockname error (listening) %d\n", + uv_last_error(loop).code); } ASSERT(r == 0); @@ -175,7 +180,7 @@ static void tcp_connector() { int r; struct sockaddr_in server_addr = uv_ip4_addr("127.0.0.1", TEST_PORT); - r = uv_tcp_init(&tcp); + r = uv_tcp_init(loop, &tcp); tcp.data = &connect_req; ASSERT(!r); @@ -197,7 +202,6 @@ static void udp_recv(uv_udp_t* handle, ASSERT(nread >= 0); if (nread == 0) { - uv_close((uv_handle_t*)handle, NULL); free(buf.base); return; } @@ -205,7 +209,7 @@ static void udp_recv(uv_udp_t* handle, namelen = sizeof(sockname); r = uv_getsockname((uv_handle_t*)&udp, &sockname, &namelen); if (r != 0) { - fprintf(stderr, "uv_getsockname error (connector) %d\n", uv_last_error().code); + fprintf(stderr, "uv_getsockname error (connector) %d\n", uv_last_error(loop).code); } ASSERT(r == 0); @@ -215,7 +219,8 @@ static void udp_recv(uv_udp_t* handle, getsocknamecount++; - uv_close((uv_handle_t*)&udp, NULL); + uv_close((uv_handle_t*) &udp, NULL); + uv_close((uv_handle_t*) handle, NULL); } @@ -231,7 +236,7 @@ static int udp_listener(int port) { char ip[20]; int r; - r = uv_udp_init(&udpServer); + r = uv_udp_init(loop, &udpServer); if (r) { fprintf(stderr, "Socket creation error\n"); return 1; @@ -247,7 +252,7 @@ static int udp_listener(int port) { r = uv_getsockname((uv_handle_t*)&udpServer, &sockname, &namelen); if (r != 0) { - fprintf(stderr, "uv_getsockname error (listening) %d\n", uv_last_error().code); + fprintf(stderr, "uv_getsockname error (listening) %d\n", uv_last_error(loop).code); } ASSERT(r == 0); @@ -272,7 +277,7 @@ static void udp_sender(void) { uv_buf_t buf; int r; - r = uv_udp_init(&udp); + r = uv_udp_init(loop, &udp); ASSERT(!r); buf = uv_buf_init("PING", 4); @@ -285,13 +290,14 @@ static void udp_sender(void) { TEST_IMPL(getsockname_tcp) { uv_init(); + loop = uv_default_loop(); if (tcp_listener(TEST_PORT)) return 1; tcp_connector(); - uv_run(); + uv_run(loop); ASSERT(getsocknamecount == 3); @@ -301,13 +307,14 @@ TEST_IMPL(getsockname_tcp) { TEST_IMPL(getsockname_udp) { uv_init(); + loop = uv_default_loop(); if (udp_listener(TEST_PORT)) return 1; udp_sender(); - uv_run(); + uv_run(loop); ASSERT(getsocknamecount == 2); diff --git a/deps/uv/test/test-idle.c b/deps/uv/test/test-idle.c index 46917d046..6e959b975 100644 --- a/deps/uv/test/test-idle.c +++ b/deps/uv/test/test-idle.c @@ -62,17 +62,18 @@ TEST_IMPL(idle_starvation) { uv_init(); - r = uv_idle_init(&idle_handle); + + r = uv_idle_init(uv_default_loop(), &idle_handle); ASSERT(r == 0); r = uv_idle_start(&idle_handle, idle_cb); ASSERT(r == 0); - r = uv_timer_init(&timer_handle); + r = uv_timer_init(uv_default_loop(), &timer_handle); ASSERT(r == 0); r = uv_timer_start(&timer_handle, timer_cb, 50, 0); ASSERT(r == 0); - r = uv_run(); + r = uv_run(uv_default_loop()); ASSERT(r == 0); ASSERT(idle_cb_called > 0); diff --git a/deps/uv/test/test-loop-handles.c b/deps/uv/test/test-loop-handles.c index 8db6c8c17..b9f3be210 100644 --- a/deps/uv/test/test-loop-handles.c +++ b/deps/uv/test/test-loop-handles.c @@ -153,7 +153,7 @@ static void idle_1_cb(uv_idle_t* handle, int status) { /* Init idle_2 and make it active */ if (!idle_2_is_active) { - r = uv_idle_init(&idle_2_handle); + r = uv_idle_init(uv_default_loop(), &idle_2_handle); ASSERT(r == 0); r = uv_idle_start(&idle_2_handle, idle_2_cb); ASSERT(r == 0); @@ -301,23 +301,24 @@ TEST_IMPL(loop_handles) { uv_init(); - r = uv_prepare_init(&prepare_1_handle); + + r = uv_prepare_init(uv_default_loop(), &prepare_1_handle); ASSERT(r == 0); r = uv_prepare_start(&prepare_1_handle, prepare_1_cb); ASSERT(r == 0); - r = uv_check_init(&check_handle); + r = uv_check_init(uv_default_loop(), &check_handle); ASSERT(r == 0); r = uv_check_start(&check_handle, check_cb); ASSERT(r == 0); /* initialize only, prepare_2 is started by prepare_1_cb */ - r = uv_prepare_init(&prepare_2_handle); + r = uv_prepare_init(uv_default_loop(), &prepare_2_handle); ASSERT(r == 0); for (i = 0; i < IDLE_COUNT; i++) { /* initialize only, idle_1 handles are started by check_cb */ - r = uv_idle_init(&idle_1_handles[i]); + r = uv_idle_init(uv_default_loop(), &idle_1_handles[i]); ASSERT(r == 0); } @@ -325,13 +326,13 @@ TEST_IMPL(loop_handles) { /* the timer callback is there to keep the event loop polling */ /* unref it as it is not supposed to keep the loop alive */ - r = uv_timer_init(&timer_handle); + r = uv_timer_init(uv_default_loop(), &timer_handle); ASSERT(r == 0); r = uv_timer_start(&timer_handle, timer_cb, TIMEOUT, TIMEOUT); ASSERT(r == 0); - uv_unref(); + uv_unref(uv_default_loop()); - r = uv_run(); + r = uv_run(uv_default_loop()); ASSERT(r == 0); ASSERT(loop_iteration == ITERATIONS); diff --git a/deps/uv/test/test-ping-pong.c b/deps/uv/test/test-ping-pong.c index e9af29ae2..700e5e930 100644 --- a/deps/uv/test/test-ping-pong.c +++ b/deps/uv/test/test-ping-pong.c @@ -100,7 +100,7 @@ static void pinger_read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) { pinger = (pinger_t*)stream->data; if (nread < 0) { - ASSERT(uv_last_error().code == UV_EOF); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EOF); puts("got EOF"); @@ -155,7 +155,7 @@ static void tcp_pinger_v6_new() { pinger->pongs = 0; /* Try to connec to the server and do NUM_PINGS ping-pongs. */ - r = uv_tcp_init(&pinger->tcp); + r = uv_tcp_init(uv_default_loop(), &pinger->tcp); pinger->tcp.data = pinger; ASSERT(!r); @@ -180,7 +180,7 @@ static void tcp_pinger_new() { pinger->pongs = 0; /* Try to connec to the server and do NUM_PINGS ping-pongs. */ - r = uv_tcp_init(&pinger->tcp); + r = uv_tcp_init(uv_default_loop(), &pinger->tcp); pinger->tcp.data = pinger; ASSERT(!r); @@ -204,7 +204,7 @@ static void pipe_pinger_new() { pinger->pongs = 0; /* Try to connec to the server and do NUM_PINGS ping-pongs. */ - r = uv_pipe_init(&pinger->pipe); + r = uv_pipe_init(uv_default_loop(), &pinger->pipe); pinger->pipe.data = pinger; ASSERT(!r); @@ -224,7 +224,7 @@ TEST_IMPL(tcp_ping_pong) { uv_init(); tcp_pinger_new(); - uv_run(); + uv_run(uv_default_loop()); ASSERT(completed_pingers == 1); @@ -236,7 +236,7 @@ TEST_IMPL(tcp_ping_pong_v6) { uv_init(); tcp_pinger_v6_new(); - uv_run(); + uv_run(uv_default_loop()); ASSERT(completed_pingers == 1); @@ -248,7 +248,7 @@ TEST_IMPL(pipe_ping_pong) { uv_init(); pipe_pinger_new(); - uv_run(); + uv_run(uv_default_loop()); ASSERT(completed_pingers == 1); diff --git a/deps/uv/test/test-pipe-bind-error.c b/deps/uv/test/test-pipe-bind-error.c index 80c76da8d..961bb870a 100644 --- a/deps/uv/test/test-pipe-bind-error.c +++ b/deps/uv/test/test-pipe-bind-error.c @@ -47,29 +47,30 @@ TEST_IMPL(pipe_bind_error_addrinuse) { uv_init(); - r = uv_pipe_init(&server1); + + r = uv_pipe_init(uv_default_loop(), &server1); ASSERT(r == 0); r = uv_pipe_bind(&server1, TEST_PIPENAME); ASSERT(r == 0); - r = uv_pipe_init(&server2); + r = uv_pipe_init(uv_default_loop(), &server2); ASSERT(r == 0); r = uv_pipe_bind(&server2, TEST_PIPENAME); ASSERT(r == -1); - ASSERT(uv_last_error().code == UV_EADDRINUSE); + ASSERT(uv_last_error(uv_default_loop()).code == 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().code == UV_EINVAL); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL); uv_close((uv_handle_t*)&server1, close_cb); uv_close((uv_handle_t*)&server2, close_cb); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 2); @@ -83,16 +84,17 @@ TEST_IMPL(pipe_bind_error_addrnotavail) { uv_init(); - r = uv_pipe_init(&server); + + r = uv_pipe_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_pipe_bind(&server, BAD_PIPENAME); ASSERT(r == -1); - ASSERT(uv_last_error().code == UV_EACCESS); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EACCESS); uv_close((uv_handle_t*)&server, close_cb); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 1); @@ -106,18 +108,19 @@ TEST_IMPL(pipe_bind_error_inval) { uv_init(); - r = uv_pipe_init(&server); + + r = uv_pipe_init(uv_default_loop(), &server); ASSERT(r == 0); 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().code == UV_EINVAL); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL); uv_close((uv_handle_t*)&server, close_cb); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 1); @@ -131,16 +134,17 @@ TEST_IMPL(pipe_listen_without_bind) { uv_init(); - r = uv_pipe_init(&server); + + r = uv_pipe_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_listen((uv_stream_t*)&server, SOMAXCONN, NULL); ASSERT(r == -1); - ASSERT(uv_last_error().code == UV_EINVAL); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL); uv_close((uv_handle_t*)&server, close_cb); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 1); diff --git a/deps/uv/test/test-ref.c b/deps/uv/test/test-ref.c index d61b3a6f5..69dad1c00 100644 --- a/deps/uv/test/test-ref.c +++ b/deps/uv/test/test-ref.c @@ -25,7 +25,7 @@ TEST_IMPL(ref) { uv_init(); - uv_run(); + uv_run(uv_default_loop()); return 0; } @@ -33,10 +33,10 @@ TEST_IMPL(ref) { TEST_IMPL(idle_ref) { uv_idle_t h; uv_init(); - uv_idle_init(&h); + uv_idle_init(uv_default_loop(), &h); uv_idle_start(&h, NULL); - uv_unref(); - uv_run(); + uv_unref(uv_default_loop()); + uv_run(uv_default_loop()); return 0; } @@ -44,9 +44,9 @@ TEST_IMPL(idle_ref) { TEST_IMPL(async_ref) { uv_async_t h; uv_init(); - uv_async_init(&h, NULL); - uv_unref(); - uv_run(); + uv_async_init(uv_default_loop(), &h, NULL); + uv_unref(uv_default_loop()); + uv_run(uv_default_loop()); return 0; } @@ -54,10 +54,10 @@ TEST_IMPL(async_ref) { TEST_IMPL(prepare_ref) { uv_prepare_t h; uv_init(); - uv_prepare_init(&h); + uv_prepare_init(uv_default_loop(), &h); uv_prepare_start(&h, NULL); - uv_unref(); - uv_run(); + uv_unref(uv_default_loop()); + uv_run(uv_default_loop()); return 0; } @@ -65,10 +65,10 @@ TEST_IMPL(prepare_ref) { TEST_IMPL(check_ref) { uv_check_t h; uv_init(); - uv_check_init(&h); + uv_check_init(uv_default_loop(), &h); uv_check_start(&h, NULL); - uv_unref(); - uv_run(); + uv_unref(uv_default_loop()); + uv_run(uv_default_loop()); return 0; } @@ -77,15 +77,16 @@ static void prepare_cb(uv_prepare_t* handle, int status) { ASSERT(handle != NULL); ASSERT(status == 0); - uv_unref(); + uv_unref(uv_default_loop()); } TEST_IMPL(unref_in_prepare_cb) { uv_prepare_t h; uv_init(); - uv_prepare_init(&h); + + uv_prepare_init(uv_default_loop(), &h); uv_prepare_start(&h, prepare_cb); - uv_run(); + uv_run(uv_default_loop()); return 0; } diff --git a/deps/uv/test/test-shutdown-eof.c b/deps/uv/test/test-shutdown-eof.c index cb57ad1eb..f7ea80df6 100644 --- a/deps/uv/test/test-shutdown-eof.c +++ b/deps/uv/test/test-shutdown-eof.c @@ -48,7 +48,7 @@ static uv_buf_t alloc_cb(uv_handle_t* handle, size_t size) { static void read_cb(uv_stream_t* t, ssize_t nread, uv_buf_t buf) { - uv_err_t err = uv_last_error(); + uv_err_t err = uv_last_error(uv_default_loop()); ASSERT((uv_tcp_t*)t == &tcp); @@ -158,17 +158,17 @@ TEST_IMPL(shutdown_eof) { qbuf.base = "Q"; qbuf.len = 1; - uv_timer_init(&timer); + uv_timer_init(uv_default_loop(), &timer); uv_timer_start(&timer, timer_cb, 100, 0); server_addr = uv_ip4_addr("127.0.0.1", TEST_PORT); - r = uv_tcp_init(&tcp); + r = uv_tcp_init(uv_default_loop(), &tcp); ASSERT(!r); r = uv_tcp_connect(&connect_req, &tcp, server_addr, connect_cb); ASSERT(!r); - uv_run(); + uv_run(uv_default_loop()); ASSERT(called_connect_cb == 1); ASSERT(called_shutdown_cb == 1); diff --git a/deps/uv/test/test-spawn.c b/deps/uv/test/test-spawn.c index f2d84694c..13987744c 100644 --- a/deps/uv/test/test-spawn.c +++ b/deps/uv/test/test-spawn.c @@ -75,7 +75,7 @@ uv_buf_t on_alloc(uv_handle_t* handle, size_t suggested_size) { void on_read(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) { - uv_err_t err = uv_last_error(); + uv_err_t err = uv_last_error(uv_default_loop()); if (nread > 0) { output_used += nread; @@ -120,10 +120,10 @@ TEST_IMPL(spawn_exit_code) { init_process_options("spawn_helper1", exit_cb); - r = uv_spawn(&process, options); + r = uv_spawn(uv_default_loop(), &process, options); ASSERT(r == 0); - r = uv_run(); + r = uv_run(uv_default_loop()); ASSERT(r == 0); ASSERT(exit_cb_called == 1); @@ -141,16 +141,16 @@ TEST_IMPL(spawn_stdout) { init_process_options("spawn_helper2", exit_cb); - uv_pipe_init(&out); + uv_pipe_init(uv_default_loop(), &out); options.stdout_stream = &out; - r = uv_spawn(&process, options); + r = uv_spawn(uv_default_loop(), &process, options); ASSERT(r == 0); r = uv_read_start((uv_stream_t*) &out, on_alloc, on_read); ASSERT(r == 0); - r = uv_run(); + r = uv_run(uv_default_loop()); ASSERT(r == 0); ASSERT(exit_cb_called == 1); @@ -174,12 +174,12 @@ int r; init_process_options("spawn_helper3", exit_cb); - uv_pipe_init(&out); - uv_pipe_init(&in); + uv_pipe_init(uv_default_loop(), &out); + uv_pipe_init(uv_default_loop(), &in); options.stdout_stream = &out; options.stdin_stream = ∈ - r = uv_spawn(&process, options); + r = uv_spawn(uv_default_loop(), &process, options); ASSERT(r == 0); buf.base = buffer; @@ -190,7 +190,7 @@ int r; r = uv_read_start((uv_stream_t*) &out, on_alloc, on_read); ASSERT(r == 0); - r = uv_run(); + r = uv_run(uv_default_loop()); ASSERT(r == 0); ASSERT(exit_cb_called == 1); @@ -208,16 +208,16 @@ TEST_IMPL(spawn_and_kill) { init_process_options("spawn_helper4", kill_cb); - r = uv_spawn(&process, options); + r = uv_spawn(uv_default_loop(), &process, options); ASSERT(r == 0); - r = uv_timer_init(&timer); + r = uv_timer_init(uv_default_loop(), &timer); ASSERT(r == 0); r = uv_timer_start(&timer, timer_cb, 500, 0); ASSERT(r == 0); - r = uv_run(); + r = uv_run(uv_default_loop()); ASSERT(r == 0); ASSERT(exit_cb_called == 1); @@ -238,7 +238,7 @@ TEST_IMPL(spawn_detect_pipe_name_collisions_on_windows) { init_process_options("spawn_helper2", exit_cb); - uv_pipe_init(&out); + uv_pipe_init(uv_default_loop(), &out); options.stdout_stream = &out; /* Create a pipe that'll cause a collision. */ @@ -253,13 +253,13 @@ TEST_IMPL(spawn_detect_pipe_name_collisions_on_windows) { NULL); ASSERT(pipe_handle != INVALID_HANDLE_VALUE); - r = uv_spawn(&process, options); + r = uv_spawn(uv_default_loop(), &process, options); ASSERT(r == 0); r = uv_read_start((uv_stream_t*) &out, on_alloc, on_read); ASSERT(r == 0); - r = uv_run(); + r = uv_run(uv_default_loop()); ASSERT(r == 0); ASSERT(exit_cb_called == 1); diff --git a/deps/uv/test/test-tcp-bind-error.c b/deps/uv/test/test-tcp-bind-error.c index b466ef8b4..28c2f6122 100644 --- a/deps/uv/test/test-tcp-bind-error.c +++ b/deps/uv/test/test-tcp-bind-error.c @@ -41,12 +41,13 @@ TEST_IMPL(tcp_bind_error_addrinuse) { uv_init(); - r = uv_tcp_init(&server1); + + r = uv_tcp_init(uv_default_loop(), &server1); ASSERT(r == 0); r = uv_tcp_bind(&server1, addr); ASSERT(r == 0); - r = uv_tcp_init(&server2); + r = uv_tcp_init(uv_default_loop(), &server2); ASSERT(r == 0); r = uv_tcp_bind(&server2, addr); ASSERT(r == 0); @@ -56,12 +57,12 @@ TEST_IMPL(tcp_bind_error_addrinuse) { r = uv_listen((uv_stream_t*)&server2, 128, NULL); ASSERT(r == -1); - ASSERT(uv_last_error().code == UV_EADDRINUSE); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EADDRINUSE); uv_close((uv_handle_t*)&server1, close_cb); uv_close((uv_handle_t*)&server2, close_cb); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 2); @@ -76,18 +77,19 @@ TEST_IMPL(tcp_bind_error_addrnotavail_1) { uv_init(); - r = uv_tcp_init(&server); + + 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().code == UV_EADDRNOTAVAIL); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EADDRNOTAVAIL); } uv_close((uv_handle_t*)&server, close_cb); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 1); @@ -102,15 +104,15 @@ TEST_IMPL(tcp_bind_error_addrnotavail_2) { uv_init(); - r = uv_tcp_init(&server); + r = uv_tcp_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_tcp_bind(&server, addr); ASSERT(r == -1); - ASSERT(uv_last_error().code == UV_EADDRNOTAVAIL); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EADDRNOTAVAIL); uv_close((uv_handle_t*)&server, close_cb); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 1); @@ -128,16 +130,17 @@ TEST_IMPL(tcp_bind_error_fault) { uv_init(); - r = uv_tcp_init(&server); + + 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().code == UV_EFAULT); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EFAULT); uv_close((uv_handle_t*)&server, close_cb); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 1); @@ -154,18 +157,19 @@ TEST_IMPL(tcp_bind_error_inval) { uv_init(); - r = uv_tcp_init(&server); + + r = uv_tcp_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_tcp_bind(&server, addr1); ASSERT(r == 0); r = uv_tcp_bind(&server, addr2); ASSERT(r == -1); - ASSERT(uv_last_error().code == UV_EINVAL); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL); uv_close((uv_handle_t*)&server, close_cb); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 1); @@ -181,7 +185,8 @@ TEST_IMPL(tcp_bind_localhost_ok) { uv_init(); - r = uv_tcp_init(&server); + + r = uv_tcp_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_tcp_bind(&server, addr); ASSERT(r == 0); @@ -195,7 +200,8 @@ TEST_IMPL(tcp_listen_without_bind) { uv_tcp_t server; uv_init(); - r = uv_tcp_init(&server); + + r = uv_tcp_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_listen((uv_stream_t*)&server, 128, NULL); ASSERT(r == 0); diff --git a/deps/uv/test/test-tcp-bind6-error.c b/deps/uv/test/test-tcp-bind6-error.c index cf283fa00..74b930d62 100644 --- a/deps/uv/test/test-tcp-bind6-error.c +++ b/deps/uv/test/test-tcp-bind6-error.c @@ -41,12 +41,13 @@ TEST_IMPL(tcp_bind6_error_addrinuse) { uv_init(); - r = uv_tcp_init(&server1); + + r = uv_tcp_init(uv_default_loop(), &server1); ASSERT(r == 0); r = uv_tcp_bind6(&server1, addr); ASSERT(r == 0); - r = uv_tcp_init(&server2); + r = uv_tcp_init(uv_default_loop(), &server2); ASSERT(r == 0); r = uv_tcp_bind6(&server2, addr); ASSERT(r == 0); @@ -56,12 +57,12 @@ TEST_IMPL(tcp_bind6_error_addrinuse) { r = uv_listen((uv_stream_t*)&server2, 128, NULL); ASSERT(r == -1); - ASSERT(uv_last_error().code == UV_EADDRINUSE); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EADDRINUSE); uv_close((uv_handle_t*)&server1, close_cb); uv_close((uv_handle_t*)&server2, close_cb); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 2); @@ -76,15 +77,16 @@ TEST_IMPL(tcp_bind6_error_addrnotavail) { uv_init(); - r = uv_tcp_init(&server); + + r = uv_tcp_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_tcp_bind6(&server, addr); ASSERT(r == -1); - ASSERT(uv_last_error().code == UV_EADDRNOTAVAIL); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EADDRNOTAVAIL); uv_close((uv_handle_t*)&server, close_cb); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 1); @@ -102,16 +104,17 @@ TEST_IMPL(tcp_bind6_error_fault) { uv_init(); - r = uv_tcp_init(&server); + + 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().code == UV_EFAULT); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EFAULT); uv_close((uv_handle_t*)&server, close_cb); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 1); @@ -128,18 +131,19 @@ TEST_IMPL(tcp_bind6_error_inval) { uv_init(); - r = uv_tcp_init(&server); + + r = uv_tcp_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_tcp_bind6(&server, addr1); ASSERT(r == 0); r = uv_tcp_bind6(&server, addr2); ASSERT(r == -1); - ASSERT(uv_last_error().code == UV_EINVAL); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL); uv_close((uv_handle_t*)&server, close_cb); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 1); @@ -155,7 +159,8 @@ TEST_IMPL(tcp_bind6_localhost_ok) { uv_init(); - r = uv_tcp_init(&server); + + r = uv_tcp_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_tcp_bind6(&server, addr); ASSERT(r == 0); diff --git a/deps/uv/test/test-tcp-writealot.c b/deps/uv/test/test-tcp-writealot.c index 6cb5e0992..1b1a03bf5 100644 --- a/deps/uv/test/test-tcp-writealot.c +++ b/deps/uv/test/test-tcp-writealot.c @@ -87,7 +87,7 @@ static void read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) { ASSERT(tcp != NULL); if (nread < 0) { - ASSERT(uv_last_error().code == UV_EOF); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EOF); printf("GOT EOF\n"); if (buf.base) { @@ -108,7 +108,7 @@ static void write_cb(uv_write_t* req, int status) { ASSERT(req != NULL); if (status) { - uv_err_t err = uv_last_error(); + uv_err_t err = uv_last_error(uv_default_loop()); fprintf(stderr, "uv_write error: %s\n", uv_strerror(err)); ASSERT(0); } @@ -178,13 +178,14 @@ TEST_IMPL(tcp_writealot) { uv_init(); - r = uv_tcp_init(client); + + r = uv_tcp_init(uv_default_loop(), client); ASSERT(r == 0); r = uv_tcp_connect(connect_req, client, addr, connect_cb); ASSERT(r == 0); - uv_run(); + uv_run(uv_default_loop()); ASSERT(shutdown_cb_called == 1); ASSERT(connect_cb_called == 1); diff --git a/deps/uv/test/test-threadpool.c b/deps/uv/test/test-threadpool.c index 19742f238..4f0be0cd4 100644 --- a/deps/uv/test/test-threadpool.c +++ b/deps/uv/test/test-threadpool.c @@ -48,9 +48,9 @@ TEST_IMPL(threadpool_queue_work_simple) { uv_init(); work_req.data = &data; - r = uv_queue_work(&work_req, work_cb, after_work_cb); + r = uv_queue_work(uv_default_loop(), &work_req, work_cb, after_work_cb); ASSERT(r == 0); - uv_run(); + uv_run(uv_default_loop()); ASSERT(work_cb_count == 1); ASSERT(after_work_cb_count == 1); diff --git a/deps/uv/test/test-timer-again.c b/deps/uv/test/test-timer-again.c index e083b01ce..49cecf877 100644 --- a/deps/uv/test/test-timer-again.c +++ b/deps/uv/test/test-timer-again.c @@ -49,14 +49,15 @@ static void repeat_1_cb(uv_timer_t* handle, int status) { ASSERT(uv_timer_get_repeat((uv_timer_t*)handle) == 50); - LOGF("repeat_1_cb called after %ld ms\n", (long int)(uv_now() - start_time)); + LOGF("repeat_1_cb called after %ld ms\n", + (long int)(uv_now(uv_default_loop()) - start_time)); repeat_1_cb_called++; r = uv_timer_again(&repeat_2); ASSERT(r == 0); - if (uv_now() >= start_time + 500) { + if (uv_now(uv_default_loop()) >= start_time + 500) { uv_close((uv_handle_t*)handle, close_cb); /* We're not calling uv_timer_again on repeat_2 any more, so after this */ /* timer_2_cb is expected. */ @@ -71,7 +72,8 @@ static void repeat_2_cb(uv_timer_t* handle, int status) { ASSERT(status == 0); ASSERT(repeat_2_cb_allowed); - LOGF("repeat_2_cb called after %ld ms\n", (long int)(uv_now() - start_time)); + LOGF("repeat_2_cb called after %ld ms\n", + (long int)(uv_now(uv_default_loop()) - start_time)); repeat_2_cb_called++; @@ -95,19 +97,20 @@ TEST_IMPL(timer_again) { uv_init(); - start_time = uv_now(); + + start_time = uv_now(uv_default_loop()); ASSERT(0 < start_time); /* Verify that it is not possible to uv_timer_again a never-started timer. */ - r = uv_timer_init(&dummy); + r = uv_timer_init(uv_default_loop(), &dummy); ASSERT(r == 0); r = uv_timer_again(&dummy); ASSERT(r == -1); - ASSERT(uv_last_error().code == UV_EINVAL); - uv_unref(); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL); + uv_unref(uv_default_loop()); /* Start timer repeat_1. */ - r = uv_timer_init(&repeat_1); + r = uv_timer_init(uv_default_loop(), &repeat_1); ASSERT(r == 0); r = uv_timer_start(&repeat_1, repeat_1_cb, 50, 0); ASSERT(r == 0); @@ -121,21 +124,21 @@ TEST_IMPL(timer_again) { * Start another repeating timer. It'll be again()ed by the repeat_1 so * it should not time out until repeat_1 stops. */ - r = uv_timer_init(&repeat_2); + r = uv_timer_init(uv_default_loop(), &repeat_2); ASSERT(r == 0); r = uv_timer_start(&repeat_2, repeat_2_cb, 100, 100); ASSERT(r == 0); ASSERT(uv_timer_get_repeat(&repeat_2) == 100); - uv_run(); + uv_run(uv_default_loop()); ASSERT(repeat_1_cb_called == 10); ASSERT(repeat_2_cb_called == 2); ASSERT(close_cb_called == 2); LOGF("Test took %ld ms (expected ~700 ms)\n", - (long int)(uv_now() - start_time)); - ASSERT(700 <= uv_now() - start_time); + (long int)(uv_now(uv_default_loop()) - start_time)); + ASSERT(700 <= uv_now(uv_default_loop()) - start_time); return 0; } diff --git a/deps/uv/test/test-timer.c b/deps/uv/test/test-timer.c index c62a8c68d..9e624cb10 100644 --- a/deps/uv/test/test-timer.c +++ b/deps/uv/test/test-timer.c @@ -53,7 +53,7 @@ static void once_cb(uv_timer_t* handle, int status) { uv_close((uv_handle_t*)handle, once_close_cb); /* Just call this randomly for the code coverage. */ - uv_update_time(); + uv_update_time(uv_default_loop()); } @@ -92,35 +92,35 @@ TEST_IMPL(timer) { uv_init(); - start_time = uv_now(); + start_time = uv_now(uv_default_loop()); ASSERT(0 < start_time); /* Let 10 timers time out in 500 ms total. */ for (i = 0; i < 10; i++) { once = (uv_timer_t*)malloc(sizeof(*once)); ASSERT(once != NULL); - r = uv_timer_init(once); + r = uv_timer_init(uv_default_loop(), once); ASSERT(r == 0); r = uv_timer_start(once, once_cb, i * 50, 0); ASSERT(r == 0); } /* The 11th timer is a repeating timer that runs 4 times */ - r = uv_timer_init(&repeat); + r = uv_timer_init(uv_default_loop(), &repeat); ASSERT(r == 0); r = uv_timer_start(&repeat, repeat_cb, 100, 100); ASSERT(r == 0); /* The 12th timer should not do anything. */ - r = uv_timer_init(&never); + r = uv_timer_init(uv_default_loop(), &never); ASSERT(r == 0); r = uv_timer_start(&never, never_cb, 100, 100); ASSERT(r == 0); r = uv_timer_stop(&never); ASSERT(r == 0); - uv_unref(); + uv_unref(uv_default_loop()); - uv_run(); + uv_run(uv_default_loop()); ASSERT(once_cb_called == 10); ASSERT(once_close_cb_called == 10); @@ -128,7 +128,7 @@ TEST_IMPL(timer) { ASSERT(repeat_cb_called == 5); ASSERT(repeat_close_cb_called == 1); - ASSERT(500 <= uv_now() - start_time); + ASSERT(500 <= uv_now(uv_default_loop()) - start_time); return 0; } diff --git a/deps/uv/test/test-udp-dgram-too-big.c b/deps/uv/test/test-udp-dgram-too-big.c index 7de9b49a9..92eb055eb 100644 --- a/deps/uv/test/test-udp-dgram-too-big.c +++ b/deps/uv/test/test-udp-dgram-too-big.c @@ -50,7 +50,7 @@ static void send_cb(uv_udp_send_t* req, int status) { CHECK_HANDLE(req->handle); ASSERT(status == -1); - ASSERT(uv_last_error().code == UV_EMSGSIZE); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EMSGSIZE); uv_close((uv_handle_t*)req->handle, close_cb); send_cb_called++; @@ -67,7 +67,7 @@ TEST_IMPL(udp_dgram_too_big) { uv_init(); - r = uv_udp_init(&handle_); + r = uv_udp_init(uv_default_loop(), &handle_); ASSERT(r == 0); buf = uv_buf_init(dgram, sizeof dgram); @@ -79,7 +79,7 @@ TEST_IMPL(udp_dgram_too_big) { ASSERT(close_cb_called == 0); ASSERT(send_cb_called == 0); - uv_run(); + uv_run(uv_default_loop()); ASSERT(send_cb_called == 1); ASSERT(close_cb_called == 1); diff --git a/deps/uv/test/test-udp-ipv6.c b/deps/uv/test/test-udp-ipv6.c index 489c17cce..a32ba14d0 100644 --- a/deps/uv/test/test-udp-ipv6.c +++ b/deps/uv/test/test-udp-ipv6.c @@ -104,7 +104,7 @@ static void do_test(uv_udp_recv_cb recv_cb, int bind_flags) { addr6 = uv_ip6_addr("::0", TEST_PORT); - r = uv_udp_init(&server); + r = uv_udp_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_udp_bind6(&server, addr6, bind_flags); @@ -113,7 +113,7 @@ static void do_test(uv_udp_recv_cb recv_cb, int bind_flags) { r = uv_udp_recv_start(&server, alloc_cb, recv_cb); ASSERT(r == 0); - r = uv_udp_init(&client); + r = uv_udp_init(uv_default_loop(), &client); ASSERT(r == 0); buf = uv_buf_init("PING", 4); @@ -122,7 +122,7 @@ static void do_test(uv_udp_recv_cb recv_cb, int bind_flags) { r = uv_udp_send(&req_, &client, &buf, 1, addr, send_cb); ASSERT(r == 0); - r = uv_timer_init(&timeout); + r = uv_timer_init(uv_default_loop(), &timeout); ASSERT(r == 0); r = uv_timer_start(&timeout, timeout_cb, 500, 0); @@ -132,7 +132,7 @@ static void do_test(uv_udp_recv_cb recv_cb, int bind_flags) { ASSERT(send_cb_called == 0); ASSERT(recv_cb_called == 0); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 3); } diff --git a/deps/uv/test/test-udp-send-and-recv.c b/deps/uv/test/test-udp-send-and-recv.c index 6d61e83f9..bf73a5630 100644 --- a/deps/uv/test/test-udp-send-and-recv.c +++ b/deps/uv/test/test-udp-send-and-recv.c @@ -172,7 +172,7 @@ TEST_IMPL(udp_send_and_recv) { uv_init(); - r = uv_udp_init(&server); + r = uv_udp_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_udp_bind(&server, addr, 0); @@ -183,7 +183,7 @@ TEST_IMPL(udp_send_and_recv) { addr = uv_ip4_addr("127.0.0.1", TEST_PORT); - r = uv_udp_init(&client); + r = uv_udp_init(uv_default_loop(), &client); ASSERT(r == 0); /* client sends "PING", expects "PONG" */ @@ -198,7 +198,7 @@ TEST_IMPL(udp_send_and_recv) { ASSERT(sv_send_cb_called == 0); ASSERT(sv_recv_cb_called == 0); - uv_run(); + uv_run(uv_default_loop()); ASSERT(cl_send_cb_called == 1); ASSERT(cl_recv_cb_called == 1); diff --git a/deps/uv/uv.gyp b/deps/uv/uv.gyp index ab93f1d97..d345a59db 100644 --- a/deps/uv/uv.gyp +++ b/deps/uv/uv.gyp @@ -5,6 +5,7 @@ 'type': '<(library)', 'include_dirs': [ 'include', + 'include/uv-private', 'src/', ], 'direct_dependent_settings': { @@ -94,8 +95,8 @@ '_GNU_SOURCE', ], 'sources': [ - 'include/tree.h', - 'include/uv-win.h', + 'include/uv-private/tree.h', + 'include/uv-private/uv-win.h', 'src/ares/config_win32/ares_config.h', 'src/win/async.c', 'src/win/cares.c', @@ -136,22 +137,22 @@ '-Wno-unused-parameter' ], 'sources': [ - 'include/eio.h', - 'include/ev.h', - 'include/ngx-queue.h', - 'include/uv-unix.h', - 'src/uv-eio.c', - 'src/uv-eio.h', + 'include/uv-private/eio.h', + 'include/uv-private/ev.h', + 'include/uv-private/ngx-queue.h', + 'include/uv-private/uv-unix.h', 'src/uv-unix.c', + 'src/unix/uv-eio.c', + 'src/unix/uv-eio.h', 'src/unix/fs.c', 'src/unix/internal.h', - 'src/eio/ecb.h', - 'src/eio/eio.c', - 'src/eio/xthread.h', - 'src/ev/ev.c', - 'src/ev/ev_vars.h', - 'src/ev/ev_wrap.h', - 'src/ev/event.h', + 'src/unix/eio/ecb.h', + 'src/unix/eio/eio.c', + 'src/unix/eio/xthread.h', + 'src/unix/ev/ev.c', + 'src/unix/ev/ev_vars.h', + 'src/unix/ev/ev_wrap.h', + 'src/unix/ev/event.h', # TODO: conditionally include the following based on OS? 'src/ares/config_cygwin/ares_config.h', 'src/ares/config_darwin/ares_config.h', @@ -159,18 +160,18 @@ 'src/ares/config_linux/ares_config.h', 'src/ares/config_openbsd/ares_config.h', 'src/ares/config_sunos/ares_config.h', - 'src/eio/config_cygwin.h', - 'src/eio/config_darwin.h', - 'src/eio/config_freebsd.h', - 'src/eio/config_linux.h', - 'src/eio/config_sunos.h', - 'src/ev/config_cygwin.h', - 'src/ev/config_darwin.h', - 'src/ev/config_freebsd.h', - 'src/ev/config_linux.h', - 'src/ev/config_sunos.h', + 'src/unix/eio/config_cygwin.h', + 'src/unix/eio/config_darwin.h', + 'src/unix/eio/config_freebsd.h', + 'src/unix/eio/config_linux.h', + 'src/unix/eio/config_sunos.h', + 'src/unix/ev/config_cygwin.h', + 'src/unix/ev/config_darwin.h', + 'src/unix/ev/config_freebsd.h', + 'src/unix/ev/config_linux.h', + 'src/unix/ev/config_sunos.h', ], - 'include_dirs': [ 'src/ev', ], + 'include_dirs': [ 'src/unix/ev', ], 'defines': [ '_LARGEFILE_SOURCE', '_FILE_OFFSET_BITS=64', @@ -181,7 +182,7 @@ }], [ 'OS=="mac"', { 'include_dirs': [ 'src/ares/config_darwin' ], - 'sources': [ 'src/uv-darwin.c' ], + 'sources': [ 'src/unix/darwin.c' ], 'direct_dependent_settings': { 'libraries': [ '-framework CoreServices' ], }, @@ -192,7 +193,7 @@ }], [ 'OS=="linux"', { 'include_dirs': [ 'src/ares/config_linux' ], - 'sources': [ 'src/uv-linux.c' ], + 'sources': [ 'src/unix/linux.c' ], 'defines': [ 'EV_CONFIG_H="config_linux.h"', 'EIO_CONFIG_H="config_linux.h"', |