├── test ├── fixtures │ ├── empty_file │ └── load_error.node ├── test-pass-always.c ├── test-fail-always.c ├── test-get-loadavg.c ├── test-loop-time.c ├── runner-unix.h ├── test-get-memory.c ├── runner-win.h ├── test-run-nowait.c ├── test-run-once.c ├── test-tcp-flags.c ├── test-loop-close.c ├── test-ip4-addr.c ├── test-process-title.c ├── test-hrtime.c ├── test-error.c ├── test-mutexes.c ├── test-dlerror.c ├── run-benchmarks.c ├── benchmark-thread.c ├── test-async-null-cb.c ├── test-cwd-and-chdir.c ├── test-loop-alive.c ├── test-poll-close.c ├── test-get-currentexe.c ├── test-tcp-connect6-error.c ├── test-tcp-connect-error.c ├── test-threadpool.c ├── benchmark-sizes.c ├── test-loop-stop.c ├── test-callback-order.c ├── test-osx-select.c ├── test-walk-handles.c ├── test-shutdown-twice.c ├── test-poll-closesocket.c ├── benchmark-loop-count.c ├── test-close-order.c ├── test-getnameinfo.c ├── test-active.c ├── benchmark-getaddrinfo.c ├── test-udp-bind.c ├── test-udp-dgram-too-big.c ├── benchmark-million-timers.c ├── test-tcp-read-stop.c ├── test-close-fd.c ├── test-tcp-connect-timeout.c ├── test-tcp-close-while-connecting.c ├── test-pipe-connect-error.c ├── test-udp-multicast-ttl.c ├── test-idle.c ├── test-pipe-server-close.c ├── test-timer-from-check.c ├── test-tcp-connect-error-after-write.c ├── test-udp-multicast-interface.c ├── test-udp-multicast-interface6.c ├── test-barrier.c └── test-semaphore.c ├── m4 ├── .gitignore ├── as_case.m4 └── dtrace.m4 ├── src ├── win │ ├── fs.c │ ├── psapi │ │ ├── psapi.dll │ │ ├── psapi.lib │ │ └── readme.txt │ ├── Iphlpapi │ │ └── IPHlpApi.lib │ ├── req.c │ ├── stream-inl.h │ ├── atomicops-inl.h │ ├── dl.c │ └── async.c ├── unix │ ├── uv-dtrace.d │ ├── spinlock.h │ ├── atomic-ops.h │ ├── dl.c │ └── proctitle.c └── version.c ├── libuv.pc.in ├── android-configure ├── win32 └── libuv.dsw ├── .gitignore ├── samples ├── .gitignore └── socks5-proxy │ ├── .gitignore │ ├── build.gyp │ ├── Makefile │ ├── util.c │ ├── LICENSE │ ├── main.c │ └── s5.h ├── CMakeLists.txt ├── .mailmap ├── include ├── uv-threadpool.h ├── uv-bsd.h ├── uv-version.h ├── uv-linux.h ├── android-ifaddrs.h ├── uv-sunos.h ├── pthread-fixes.h └── uv-darwin.h ├── autogen.sh ├── LICENSE ├── Makefile.mingw └── configure.ac /test/fixtures/empty_file: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/load_error.node: -------------------------------------------------------------------------------- 1 | foobar 2 | -------------------------------------------------------------------------------- /m4/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore libtoolize-generated files. 2 | *.m4 3 | -------------------------------------------------------------------------------- /src/win/fs.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liigo/libuv-vc6/HEAD/src/win/fs.c -------------------------------------------------------------------------------- /src/win/psapi/psapi.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liigo/libuv-vc6/HEAD/src/win/psapi/psapi.dll -------------------------------------------------------------------------------- /src/win/psapi/psapi.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liigo/libuv-vc6/HEAD/src/win/psapi/psapi.lib -------------------------------------------------------------------------------- /src/win/psapi/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liigo/libuv-vc6/HEAD/src/win/psapi/readme.txt -------------------------------------------------------------------------------- /src/win/Iphlpapi/IPHlpApi.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liigo/libuv-vc6/HEAD/src/win/Iphlpapi/IPHlpApi.lib -------------------------------------------------------------------------------- /libuv.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: @PACKAGE_NAME@ 7 | Version: @PACKAGE_VERSION@ 8 | Description: multi-platform support library with a focus on asynchronous I/O. 9 | 10 | Libs: -L${libdir} -luv @LIBS@ 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /m4/as_case.m4: -------------------------------------------------------------------------------- 1 | # AS_CASE(WORD, [PATTERN1], [IF-MATCHED1]...[DEFAULT]) 2 | # ---------------------------------------------------- 3 | # Expand into 4 | # | case WORD in 5 | # | PATTERN1) IF-MATCHED1 ;; 6 | # | ... 7 | # | *) DEFAULT ;; 8 | # | esac 9 | m4_define([_AS_CASE], 10 | [m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])], 11 | [$#], 1, [ *) $1 ;;], 12 | [$#], 2, [ $1) m4_default([$2], [:]) ;;], 13 | [ $1) m4_default([$2], [:]) ;; 14 | $0(m4_shiftn(2, $@))])dnl 15 | ]) 16 | m4_defun([AS_CASE], 17 | [m4_ifval([$2$3], 18 | [case $1 in 19 | _AS_CASE(m4_shift($@)) 20 | esac])]) 21 | 22 | -------------------------------------------------------------------------------- /android-configure: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export TOOLCHAIN=$PWD/android-toolchain 4 | mkdir -p $TOOLCHAIN 5 | $1/build/tools/make-standalone-toolchain.sh \ 6 | --toolchain=arm-linux-androideabi-4.8 \ 7 | --arch=arm \ 8 | --install-dir=$TOOLCHAIN \ 9 | --platform=android-9 10 | export PATH=$TOOLCHAIN/bin:$PATH 11 | export AR=arm-linux-androideabi-ar 12 | export CC=arm-linux-androideabi-gcc 13 | export CXX=arm-linux-androideabi-g++ 14 | export LINK=arm-linux-androideabi-g++ 15 | export PLATFORM=android 16 | 17 | if [ $2 -a $2 == 'gyp' ] 18 | then 19 | ./gyp_uv.py -Dtarget_arch=arm -DOS=android 20 | fi 21 | -------------------------------------------------------------------------------- /win32/libuv.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "libuv"=.\libuv.dsp - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.[oa] 3 | *.l[oa] 4 | *.opensdf 5 | *.orig 6 | *.pyc 7 | *.sdf 8 | *.suo 9 | core 10 | vgcore.* 11 | .buildstamp 12 | .dirstamp 13 | .deps/ 14 | /.libs/ 15 | /aclocal.m4 16 | /ar-lib 17 | /autom4te.cache/ 18 | /compile 19 | /config.guess 20 | /config.log 21 | /config.status 22 | /config.sub 23 | /configure 24 | /depcomp 25 | /install-sh 26 | /libtool 27 | /libuv.a 28 | /libuv.dylib 29 | /libuv.pc 30 | /libuv.so 31 | /ltmain.sh 32 | /missing 33 | /test-driver 34 | Makefile 35 | Makefile.in 36 | 37 | # Generated by dtrace(1) when doing an in-tree build. 38 | /include/uv-dtrace.h 39 | 40 | # Generated by gyp for android 41 | *.target.mk 42 | 43 | /out/ 44 | /build/gyp 45 | 46 | /test/.libs/ 47 | /test/run-tests 48 | /test/run-tests.exe 49 | /test/run-tests.dSYM 50 | /test/run-benchmarks 51 | /test/run-benchmarks.exe 52 | /test/run-benchmarks.dSYM 53 | 54 | *.sln 55 | *.vcproj 56 | *.vcxproj 57 | *.vcxproj.filters 58 | *.vcxproj.user 59 | _UpgradeReport_Files/ 60 | UpgradeLog*.XML 61 | Debug 62 | Release 63 | ipch 64 | -------------------------------------------------------------------------------- /samples/.gitignore: -------------------------------------------------------------------------------- 1 | # Copyright StrongLoop, Inc. All rights reserved. 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | *.mk 22 | *.Makefile 23 | -------------------------------------------------------------------------------- /samples/socks5-proxy/.gitignore: -------------------------------------------------------------------------------- 1 | # Copyright StrongLoop, Inc. All rights reserved. 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | /build/ 22 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | 3 | PROJECT(uv) 4 | 5 | SET(CMAKE_C_FLAGS "-std=c89 -O2 -pedantic -Wall -Wextra -Wno-unused-parameter -D_LARGEFILE_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64") 6 | 7 | SET(SOURCES 8 | src/unix/async.c 9 | src/unix/core.c 10 | src/unix/dl.c 11 | src/unix/fs.c 12 | src/unix/getaddrinfo.c 13 | src/unix/linux-core.c 14 | src/unix/linux-inotify.c 15 | src/unix/linux-syscalls.c 16 | src/unix/loop.c 17 | src/unix/loop-watcher.c 18 | src/unix/pipe.c 19 | src/unix/poll.c 20 | src/unix/process.c 21 | src/unix/proctitle.c 22 | src/unix/signal.c 23 | src/unix/stream.c 24 | src/unix/tcp.c 25 | src/unix/thread.c 26 | src/unix/timer.c 27 | src/unix/tty.c 28 | src/unix/udp.c 29 | src/fs-poll.c 30 | src/inet.c 31 | src/threadpool.c 32 | src/uv-common.c 33 | src/version.c 34 | ) 35 | # src/unix/aix.c src/unix/fsevents.c src/unix/kqueue.c 36 | 37 | ADD_LIBRARY(uv ${SOURCES}) 38 | 39 | INCLUDE_DIRECTORIES(include include/uv-private src) 40 | 41 | 42 | FILE(GLOB HEADERS "include/*.h") 43 | FILE(GLOB HEADERS_PRIVATE "include/uv-private/*.h") 44 | 45 | INSTALL(TARGETS uv DESTINATION lib) 46 | INSTALL(FILES ${HEADERS} DESTINATION include) 47 | INSTALL(FILES ${HEADERS_PRIVATE} DESTINATION include/uv-private) 48 | -------------------------------------------------------------------------------- /src/win/req.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include 23 | 24 | #include "uv.h" 25 | #include "internal.h" 26 | -------------------------------------------------------------------------------- /src/unix/uv-dtrace.d: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | provider uv { 23 | probe tick__start(void* loop, int mode); 24 | probe tick__stop(void* loop, int mode); 25 | }; 26 | -------------------------------------------------------------------------------- /test/test-pass-always.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "task.h" 23 | 24 | 25 | TEST_IMPL(pass_always) { 26 | /* This test always passes. It is used to test the test runner. */ 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /test/test-fail-always.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "task.h" 23 | 24 | 25 | TEST_IMPL(fail_always) { 26 | /* This test always fails. It is used to test the test runner. */ 27 | FATAL("Yes, it always fails"); 28 | return 2; 29 | } 30 | -------------------------------------------------------------------------------- /test/test-get-loadavg.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | TEST_IMPL(get_loadavg) { 26 | 27 | double avg[3]; 28 | uv_loadavg(avg); 29 | 30 | ASSERT(avg != NULL); 31 | ASSERT(avg[0] >= 0); 32 | ASSERT(avg[1] >= 0); 33 | ASSERT(avg[2] >= 0); 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /test/test-loop-time.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | 26 | TEST_IMPL(loop_update_time) { 27 | uint64_t start; 28 | 29 | start = uv_now(uv_default_loop()); 30 | while (uv_now(uv_default_loop()) - start < 1000) 31 | ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_NOWAIT)); 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /test/runner-unix.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef TEST_RUNNER_UNIX_H 23 | #define TEST_RUNNER_UNIX_H 24 | 25 | #include 26 | #include /* FILE */ 27 | 28 | typedef struct { 29 | FILE* stdout_file; 30 | pid_t pid; 31 | char* name; 32 | int status; 33 | int terminated; 34 | } process_info_t; 35 | 36 | #endif /* TEST_RUNNER_UNIX_H */ 37 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | Alan Gutierrez 2 | Andrius Bentkus 3 | Bert Belder 4 | Bert Belder 5 | Brandon Philips 6 | Brian White 7 | Brian White 8 | Christoph Iserlohn 9 | Fedor Indutny 10 | Frank Denis 11 | Isaac Z. Schlueter 12 | Justin Venus 13 | Keno Fischer 14 | Keno Fischer 15 | Maciej Małecki 16 | Marc Schlaich 17 | Rasmus Christian Pedersen 18 | Rasmus Christian Pedersen 19 | Rasmus Pedersen 20 | Robert Mustacchi 21 | Ryan Dahl 22 | Ryan Emery 23 | Sam Roberts 24 | San-Tai Hsu 25 | Saúl Ibarra Corretgé 26 | Shigeki Ohtsu 27 | Timothy J. Fontaine 28 | Yasuhiro Matsumoto 29 | Yazhong Liu 30 | Yuki Okumura 31 | -------------------------------------------------------------------------------- /include/uv-threadpool.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | /* 23 | * This file is private to libuv. It provides common functionality to both 24 | * Windows and Unix backends. 25 | */ 26 | 27 | #ifndef UV_THREADPOOL_H_ 28 | #define UV_THREADPOOL_H_ 29 | 30 | struct uv__work { 31 | void (*work)(struct uv__work *w); 32 | void (*done)(struct uv__work *w, int status); 33 | struct uv_loop_s* loop; 34 | void* wq[2]; 35 | }; 36 | 37 | #endif /* UV_THREADPOOL_H_ */ 38 | -------------------------------------------------------------------------------- /test/test-get-memory.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | TEST_IMPL(get_memory) { 26 | uint64_t free_mem = uv_get_free_memory(); 27 | uint64_t total_mem = uv_get_total_memory(); 28 | 29 | printf("free_mem=%llu, total_mem=%llu\n", 30 | (unsigned long long) free_mem, 31 | (unsigned long long) total_mem); 32 | 33 | ASSERT(free_mem > 0); 34 | ASSERT(total_mem > 0); 35 | ASSERT(total_mem > free_mem); 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /test/runner-win.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | /* Don't complain about _snprintf being insecure. */ 23 | #define _CRT_SECURE_NO_WARNINGS 24 | 25 | /* Don't complain about write(), fileno() etc. being deprecated. */ 26 | #pragma warning(disable : 4996) 27 | 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | 34 | /* Windows has no snprintf, only _snprintf. */ 35 | #define snprintf _snprintf 36 | 37 | 38 | typedef struct { 39 | HANDLE process; 40 | HANDLE stdio_in; 41 | HANDLE stdio_out; 42 | char *name; 43 | } process_info_t; 44 | -------------------------------------------------------------------------------- /include/uv-bsd.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UV_BSD_H 23 | #define UV_BSD_H 24 | 25 | #define UV_PLATFORM_FS_EVENT_FIELDS \ 26 | uv__io_t event_watcher; \ 27 | 28 | #define UV_IO_PRIVATE_PLATFORM_FIELDS \ 29 | int rcount; \ 30 | int wcount; \ 31 | 32 | #define UV_HAVE_KQUEUE 1 33 | 34 | #endif /* UV_BSD_H */ 35 | -------------------------------------------------------------------------------- /test/test-run-nowait.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | static uv_timer_t timer_handle; 26 | static int timer_called = 0; 27 | 28 | 29 | static void timer_cb(uv_timer_t* handle) { 30 | ASSERT(handle == &timer_handle); 31 | timer_called = 1; 32 | } 33 | 34 | 35 | TEST_IMPL(run_nowait) { 36 | int r; 37 | uv_timer_init(uv_default_loop(), &timer_handle); 38 | uv_timer_start(&timer_handle, timer_cb, 100, 100); 39 | 40 | r = uv_run(uv_default_loop(), UV_RUN_NOWAIT); 41 | ASSERT(r != 0); 42 | ASSERT(timer_called == 0); 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /samples/socks5-proxy/build.gyp: -------------------------------------------------------------------------------- 1 | # Copyright StrongLoop, Inc. All rights reserved. 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | { 22 | 'targets': [ 23 | { 24 | 'dependencies': ['../../uv.gyp:libuv'], 25 | 'target_name': 's5-proxy', 26 | 'type': 'executable', 27 | 'sources': [ 28 | 'client.c', 29 | 'defs.h', 30 | 'main.c', 31 | 's5.c', 32 | 's5.h', 33 | 'server.c', 34 | 'util.c', 35 | ], 36 | 'conditions': [ 37 | ['OS=="win"', { 38 | 'defines': ['HAVE_UNISTD_H=0'], 39 | 'sources': ['getopt.c'] 40 | }, { 41 | 'defines': ['HAVE_UNISTD_H=1'] 42 | }] 43 | ] 44 | } 45 | ] 46 | } 47 | -------------------------------------------------------------------------------- /include/uv-version.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UV_VERSION_H 23 | #define UV_VERSION_H 24 | 25 | /* 26 | * Versions with an even minor version (e.g. 0.6.1 or 1.0.4) are API and ABI 27 | * stable. When the minor version is odd, the API can change between patch 28 | * releases. Make sure you update the -soname directives in configure.ac 29 | * and uv.gyp whenever you bump UV_VERSION_MAJOR or UV_VERSION_MINOR (but 30 | * not UV_VERSION_PATCH.) 31 | */ 32 | 33 | #define UV_VERSION_MAJOR 0 34 | #define UV_VERSION_MINOR 11 35 | #define UV_VERSION_PATCH 27 36 | #define UV_VERSION_IS_RELEASE 0 37 | 38 | #endif /* UV_VERSION_H */ 39 | -------------------------------------------------------------------------------- /samples/socks5-proxy/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright StrongLoop, Inc. All rights reserved. 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | BUILDTYPE ?= Debug 22 | BUILDDIR ?= build 23 | GYP ?= gyp 24 | V ?= 25 | 26 | SOURCES := client.c defs.h getopt.c main.c s5.c s5.h server.c util.c 27 | 28 | .PHONY: all clean 29 | 30 | all: $(BUILDDIR)/$(BUILDTYPE)/s5-proxy 31 | 32 | clean: 33 | $(RM) $(BUILDDIR) 34 | 35 | $(BUILDDIR)/$(BUILDTYPE)/s5-proxy: $(BUILDDIR)/Makefile $(SOURCES) 36 | $(MAKE) -C $(BUILDDIR) V=$(V) 37 | 38 | $(BUILDDIR)/Makefile: ../../common.gypi build.gyp 39 | $(GYP) \ 40 | -Duv_library=static_library \ 41 | -Goutput_dir=. \ 42 | -I../../common.gypi \ 43 | -f make \ 44 | --depth=. \ 45 | --generator-output=$(BUILDDIR) \ 46 | build.gyp 47 | -------------------------------------------------------------------------------- /test/test-run-once.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | #define NUM_TICKS 64 26 | 27 | static uv_idle_t idle_handle; 28 | static int idle_counter; 29 | 30 | 31 | static void idle_cb(uv_idle_t* handle) { 32 | ASSERT(handle == &idle_handle); 33 | 34 | if (++idle_counter == NUM_TICKS) 35 | uv_idle_stop(handle); 36 | } 37 | 38 | 39 | TEST_IMPL(run_once) { 40 | uv_idle_init(uv_default_loop(), &idle_handle); 41 | uv_idle_start(&idle_handle, idle_cb); 42 | 43 | while (uv_run(uv_default_loop(), UV_RUN_ONCE)); 44 | ASSERT(idle_counter == NUM_TICKS); 45 | 46 | MAKE_VALGRIND_HAPPY(); 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /test/test-tcp-flags.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | #include 26 | #include 27 | 28 | 29 | TEST_IMPL(tcp_flags) { 30 | uv_loop_t* loop; 31 | uv_tcp_t handle; 32 | int r; 33 | 34 | loop = uv_default_loop(); 35 | 36 | r = uv_tcp_init(loop, &handle); 37 | ASSERT(r == 0); 38 | 39 | r = uv_tcp_nodelay(&handle, 1); 40 | ASSERT(r == 0); 41 | 42 | r = uv_tcp_keepalive(&handle, 1, 60); 43 | ASSERT(r == 0); 44 | 45 | uv_close((uv_handle_t*)&handle, NULL); 46 | 47 | r = uv_run(loop, UV_RUN_DEFAULT); 48 | ASSERT(r == 0); 49 | 50 | MAKE_VALGRIND_HAPPY(); 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright (c) 2013, Ben Noordhuis 4 | # 5 | # Permission to use, copy, modify, and/or distribute this software for any 6 | # purpose with or without fee is hereby granted, provided that the above 7 | # copyright notice and this permission notice appear in all copies. 8 | # 9 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | 17 | cd `dirname "$0"` 18 | 19 | if [ "$LIBTOOLIZE" = "" ] && [ "`uname`" = "Darwin" ]; then 20 | LIBTOOLIZE=glibtoolize 21 | fi 22 | 23 | ACLOCAL=${ACLOCAL:-aclocal} 24 | AUTOCONF=${AUTOCONF:-autoconf} 25 | AUTOMAKE=${AUTOMAKE:-automake} 26 | LIBTOOLIZE=${LIBTOOLIZE:-libtoolize} 27 | 28 | automake_version=`"$AUTOMAKE" --version | head -n 1 | sed 's/[^.0-9]//g'` 29 | automake_version_major=`echo "$automake_version" | cut -d. -f1` 30 | automake_version_minor=`echo "$automake_version" | cut -d. -f2` 31 | 32 | UV_EXTRA_AUTOMAKE_FLAGS= 33 | if test "$automake_version_major" -gt 1 || \ 34 | test "$automake_version_major" -eq 1 && \ 35 | test "$automake_version_minor" -gt 11; then 36 | # serial-tests is available in v0.12 and newer. 37 | UV_EXTRA_AUTOMAKE_FLAGS="$UV_EXTRA_AUTOMAKE_FLAGS serial-tests" 38 | fi 39 | echo "m4_define([UV_EXTRA_AUTOMAKE_FLAGS], [$UV_EXTRA_AUTOMAKE_FLAGS])" \ 40 | > m4/libuv-extra-automake-flags.m4 41 | 42 | set -ex 43 | "$LIBTOOLIZE" 44 | "$ACLOCAL" -I m4 45 | "$AUTOCONF" 46 | "$AUTOMAKE" --add-missing --copy 47 | -------------------------------------------------------------------------------- /include/uv-linux.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UV_LINUX_H 23 | #define UV_LINUX_H 24 | 25 | #define UV_PLATFORM_LOOP_FIELDS \ 26 | uv__io_t inotify_read_watcher; \ 27 | void* inotify_watchers; \ 28 | int inotify_fd; \ 29 | 30 | #define UV_PLATFORM_FS_EVENT_FIELDS \ 31 | void* watchers[2]; \ 32 | int wd; \ 33 | 34 | #endif /* UV_LINUX_H */ 35 | -------------------------------------------------------------------------------- /test/test-loop-close.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | static uv_timer_t timer_handle; 26 | 27 | static void timer_cb(uv_timer_t* handle) { 28 | ASSERT(handle); 29 | uv_stop(handle->loop); 30 | } 31 | 32 | 33 | TEST_IMPL(loop_close) { 34 | int r; 35 | uv_loop_t loop; 36 | 37 | ASSERT(0 == uv_loop_init(&loop)); 38 | 39 | uv_timer_init(&loop, &timer_handle); 40 | uv_timer_start(&timer_handle, timer_cb, 100, 100); 41 | 42 | ASSERT(UV_EBUSY == uv_loop_close(&loop)); 43 | 44 | uv_run(&loop, UV_RUN_DEFAULT); 45 | 46 | uv_close((uv_handle_t*) &timer_handle, NULL); 47 | r = uv_run(&loop, UV_RUN_DEFAULT); 48 | ASSERT(r == 0); 49 | 50 | ASSERT(0 == uv_loop_close(&loop)); 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /test/test-ip4-addr.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | #include 26 | #include 27 | 28 | 29 | TEST_IMPL(ip4_addr) { 30 | 31 | struct sockaddr_in addr; 32 | 33 | ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr)); 34 | ASSERT(0 == uv_ip4_addr("255.255.255.255", TEST_PORT, &addr)); 35 | ASSERT(UV_EINVAL == uv_ip4_addr("255.255.255*000", TEST_PORT, &addr)); 36 | ASSERT(UV_EINVAL == uv_ip4_addr("255.255.255.256", TEST_PORT, &addr)); 37 | ASSERT(UV_EINVAL == uv_ip4_addr("2555.0.0.0", TEST_PORT, &addr)); 38 | ASSERT(UV_EINVAL == uv_ip4_addr("255", TEST_PORT, &addr)); 39 | 40 | /* for broken address family */ 41 | ASSERT(UV_EAFNOSUPPORT == uv_inet_pton(42, "127.0.0.1", 42 | &addr.sin_addr.s_addr)); 43 | 44 | MAKE_VALGRIND_HAPPY(); 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /test/test-process-title.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | #include 25 | 26 | 27 | static void set_title(const char* title) { 28 | char buffer[512]; 29 | int err; 30 | 31 | err = uv_get_process_title(buffer, sizeof(buffer)); 32 | ASSERT(err == 0); 33 | 34 | err = uv_set_process_title(title); 35 | ASSERT(err == 0); 36 | 37 | err = uv_get_process_title(buffer, sizeof(buffer)); 38 | ASSERT(err == 0); 39 | 40 | ASSERT(strcmp(buffer, title) == 0); 41 | } 42 | 43 | 44 | TEST_IMPL(process_title) { 45 | #if defined(__sun) 46 | RETURN_SKIP("uv_(get|set)_process_title is not implemented."); 47 | #else 48 | /* Check for format string vulnerabilities. */ 49 | set_title("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"); 50 | set_title("new title"); 51 | return 0; 52 | #endif 53 | } 54 | -------------------------------------------------------------------------------- /src/version.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | 24 | #define UV_VERSION ((UV_VERSION_MAJOR << 16) | \ 25 | (UV_VERSION_MINOR << 8) | \ 26 | (UV_VERSION_PATCH)) 27 | 28 | #define UV_STRINGIFY(v) UV_STRINGIFY_HELPER(v) 29 | #define UV_STRINGIFY_HELPER(v) #v 30 | 31 | #define UV_VERSION_STRING_BASE UV_STRINGIFY(UV_VERSION_MAJOR) "." \ 32 | UV_STRINGIFY(UV_VERSION_MINOR) "." \ 33 | UV_STRINGIFY(UV_VERSION_PATCH) 34 | 35 | #if UV_VERSION_IS_RELEASE 36 | # define UV_VERSION_STRING UV_VERSION_STRING_BASE 37 | #else 38 | # define UV_VERSION_STRING UV_VERSION_STRING_BASE "-pre" 39 | #endif 40 | 41 | 42 | unsigned int uv_version(void) { 43 | return UV_VERSION; 44 | } 45 | 46 | 47 | const char* uv_version_string(void) { 48 | return UV_VERSION_STRING; 49 | } 50 | -------------------------------------------------------------------------------- /include/android-ifaddrs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995, 1999 3 | * Berkeley Software Design, Inc. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND 12 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | * ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE 15 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 16 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 17 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 19 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 20 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 21 | * SUCH DAMAGE. 22 | * 23 | * BSDI ifaddrs.h,v 2.5 2000/02/23 14:51:59 dab Exp 24 | */ 25 | 26 | #ifndef _IFADDRS_H_ 27 | #define _IFADDRS_H_ 28 | 29 | struct ifaddrs { 30 | struct ifaddrs *ifa_next; 31 | char *ifa_name; 32 | unsigned int ifa_flags; 33 | struct sockaddr *ifa_addr; 34 | struct sockaddr *ifa_netmask; 35 | struct sockaddr *ifa_dstaddr; 36 | void *ifa_data; 37 | }; 38 | 39 | /* 40 | * This may have been defined in . Note that if is 41 | * to be included it must be included before this header file. 42 | */ 43 | #ifndef ifa_broadaddr 44 | #define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ 45 | #endif 46 | 47 | #include 48 | 49 | __BEGIN_DECLS 50 | extern int getifaddrs(struct ifaddrs **ifap); 51 | extern void freeifaddrs(struct ifaddrs *ifa); 52 | __END_DECLS 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /test/test-hrtime.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | #ifndef MILLISEC 26 | # define MILLISEC 1000 27 | #endif 28 | 29 | #ifndef NANOSEC 30 | # define NANOSEC ((uint64_t) 1e9) 31 | #endif 32 | 33 | 34 | TEST_IMPL(hrtime) { 35 | uint64_t a, b, diff; 36 | int i = 75; 37 | while (i > 0) { 38 | a = uv_hrtime(); 39 | uv_sleep(45); 40 | b = uv_hrtime(); 41 | 42 | diff = b - a; 43 | 44 | /* printf("i= %d diff = %llu\n", i, (unsigned long long int) diff); */ 45 | 46 | /* The windows Sleep() function has only a resolution of 10-20 ms. */ 47 | /* Check that the difference between the two hrtime values is somewhat in */ 48 | /* the range we expect it to be. */ 49 | ASSERT(diff > (uint64_t) 25 * NANOSEC / MILLISEC); 50 | ASSERT(diff < (uint64_t) 80 * NANOSEC / MILLISEC); 51 | --i; 52 | } 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /test/test-error.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | 30 | /* 31 | * Synthetic errors (errors that originate from within libuv, not the system) 32 | * should produce sensible error messages when run through uv_strerror(). 33 | * 34 | * See https://github.com/joyent/libuv/issues/210 35 | */ 36 | TEST_IMPL(error_message) { 37 | /* Cop out. Can't do proper checks on systems with 38 | * i18n-ized error messages... 39 | */ 40 | if (strcmp(uv_strerror(0), "Success") != 0) { 41 | printf("i18n error messages detected, skipping test.\n"); 42 | return 0; 43 | } 44 | 45 | ASSERT(strstr(uv_strerror(UV_EINVAL), "Success") == NULL); 46 | ASSERT(strcmp(uv_strerror(1337), "Unknown error") == 0); 47 | ASSERT(strcmp(uv_strerror(-1337), "Unknown error") == 0); 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /test/test-mutexes.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | #include 26 | #include 27 | 28 | 29 | /* The mutex and rwlock tests are really poor. 30 | * They're very basic sanity checks and nothing more. 31 | * Apologies if that rhymes. 32 | */ 33 | 34 | TEST_IMPL(thread_mutex) { 35 | uv_mutex_t mutex; 36 | int r; 37 | 38 | r = uv_mutex_init(&mutex); 39 | ASSERT(r == 0); 40 | 41 | uv_mutex_lock(&mutex); 42 | uv_mutex_unlock(&mutex); 43 | uv_mutex_destroy(&mutex); 44 | 45 | return 0; 46 | } 47 | 48 | 49 | TEST_IMPL(thread_rwlock) { 50 | uv_rwlock_t rwlock; 51 | int r; 52 | 53 | r = uv_rwlock_init(&rwlock); 54 | ASSERT(r == 0); 55 | 56 | uv_rwlock_rdlock(&rwlock); 57 | uv_rwlock_rdunlock(&rwlock); 58 | uv_rwlock_wrlock(&rwlock); 59 | uv_rwlock_wrunlock(&rwlock); 60 | uv_rwlock_destroy(&rwlock); 61 | 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /include/uv-sunos.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UV_SUNOS_H 23 | #define UV_SUNOS_H 24 | 25 | #include 26 | #include 27 | 28 | /* For the sake of convenience and reduced #ifdef-ery in src/unix/sunos.c, 29 | * add the fs_event fields even when this version of SunOS doesn't support 30 | * file watching. 31 | */ 32 | #define UV_PLATFORM_LOOP_FIELDS \ 33 | uv__io_t fs_event_watcher; \ 34 | int fs_fd; \ 35 | 36 | #if defined(PORT_SOURCE_FILE) 37 | 38 | # define UV_PLATFORM_FS_EVENT_FIELDS \ 39 | file_obj_t fo; \ 40 | int fd; \ 41 | 42 | #endif /* defined(PORT_SOURCE_FILE) */ 43 | 44 | #endif /* UV_SUNOS_H */ 45 | -------------------------------------------------------------------------------- /src/unix/spinlock.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013, Ben Noordhuis 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | */ 15 | 16 | #ifndef UV_SPINLOCK_H_ 17 | #define UV_SPINLOCK_H_ 18 | 19 | #include "internal.h" /* ACCESS_ONCE, UV_UNUSED */ 20 | #include "atomic-ops.h" 21 | 22 | #define UV_SPINLOCK_INITIALIZER { 0 } 23 | 24 | typedef struct { 25 | int lock; 26 | } uv_spinlock_t; 27 | 28 | UV_UNUSED(static void uv_spinlock_init(uv_spinlock_t* spinlock)); 29 | UV_UNUSED(static void uv_spinlock_lock(uv_spinlock_t* spinlock)); 30 | UV_UNUSED(static void uv_spinlock_unlock(uv_spinlock_t* spinlock)); 31 | UV_UNUSED(static int uv_spinlock_trylock(uv_spinlock_t* spinlock)); 32 | 33 | UV_UNUSED(static void uv_spinlock_init(uv_spinlock_t* spinlock)) { 34 | ACCESS_ONCE(int, spinlock->lock) = 0; 35 | } 36 | 37 | UV_UNUSED(static void uv_spinlock_lock(uv_spinlock_t* spinlock)) { 38 | while (!uv_spinlock_trylock(spinlock)) cpu_relax(); 39 | } 40 | 41 | UV_UNUSED(static void uv_spinlock_unlock(uv_spinlock_t* spinlock)) { 42 | ACCESS_ONCE(int, spinlock->lock) = 0; 43 | } 44 | 45 | UV_UNUSED(static int uv_spinlock_trylock(uv_spinlock_t* spinlock)) { 46 | /* TODO(bnoordhuis) Maybe change to a ticket lock to guarantee fair queueing. 47 | * Not really critical until we have locks that are (frequently) contended 48 | * for by several threads. 49 | */ 50 | return 0 == cmpxchgi(&spinlock->lock, 0, 1); 51 | } 52 | 53 | #endif /* UV_SPINLOCK_H_ */ 54 | -------------------------------------------------------------------------------- /test/test-dlerror.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | #include 25 | 26 | 27 | TEST_IMPL(dlerror) { 28 | const char* path = "test/fixtures/load_error.node"; 29 | const char* msg; 30 | uv_lib_t lib; 31 | int r; 32 | 33 | #ifdef __linux__ 34 | const char* dlerror_desc = "file too short"; 35 | #elif defined (__sun__) 36 | const char* dlerror_desc = "unknown file type"; 37 | #elif defined (_WIN32) 38 | const char* dlerror_desc = "%1 is not a valid Win32 application"; 39 | #else 40 | const char* dlerror_desc = ""; 41 | #endif 42 | 43 | r = uv_dlopen(path, &lib); 44 | ASSERT(r == -1); 45 | 46 | msg = uv_dlerror(&lib); 47 | ASSERT(msg != NULL); 48 | ASSERT(strstr(msg, dlerror_desc) != NULL); 49 | 50 | /* Should return the same error twice in a row. */ 51 | msg = uv_dlerror(&lib); 52 | ASSERT(msg != NULL); 53 | ASSERT(strstr(msg, dlerror_desc) != NULL); 54 | 55 | uv_dlclose(&lib); 56 | 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /test/run-benchmarks.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | #include "runner.h" 26 | #include "task.h" 27 | 28 | /* Actual benchmarks and helpers are defined in benchmark-list.h */ 29 | #include "benchmark-list.h" 30 | 31 | 32 | static int maybe_run_test(int argc, char **argv); 33 | 34 | 35 | int main(int argc, char **argv) { 36 | platform_init(argc, argv); 37 | 38 | switch (argc) { 39 | case 1: return run_tests(1); 40 | case 2: return maybe_run_test(argc, argv); 41 | case 3: return run_test_part(argv[1], argv[2]); 42 | default: 43 | LOGF("Too many arguments.\n"); 44 | return 1; 45 | } 46 | } 47 | 48 | 49 | static int maybe_run_test(int argc, char **argv) { 50 | if (strcmp(argv[1], "--list") == 0) { 51 | print_tests(stdout); 52 | return 0; 53 | } 54 | 55 | if (strcmp(argv[1], "spawn_helper") == 0) { 56 | printf("hello world\n"); 57 | return 42; 58 | } 59 | 60 | return run_test(argv[1], 1, 1); 61 | } 62 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | libuv is part of the Node project: http://nodejs.org/ 2 | libuv may be distributed alone under Node's license: 3 | 4 | ==== 5 | 6 | Copyright Joyent, Inc. and other Node contributors. All rights reserved. 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to 9 | deal in the Software without restriction, including without limitation the 10 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 11 | sell copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 23 | IN THE SOFTWARE. 24 | 25 | ==== 26 | 27 | This license applies to all parts of libuv that are not externally 28 | maintained libraries. 29 | 30 | The externally maintained libraries used by libuv are: 31 | 32 | - tree.h (from FreeBSD), copyright Niels Provos. Two clause BSD license. 33 | 34 | - inet_pton and inet_ntop implementations, contained in src/inet.c, are 35 | copyright the Internet Systems Consortium, Inc., and licensed under the ISC 36 | license. 37 | 38 | - stdint-msvc2008.h (from msinttypes), copyright Alexander Chemeris. Three 39 | clause BSD license. 40 | 41 | - pthread-fixes.h, pthread-fixes.c, copyright Google Inc. and Sony Mobile 42 | Communications AB. Three clause BSD license. 43 | 44 | - android-ifaddrs.h, android-ifaddrs.c, copyright Berkeley Software Design 45 | Inc, Kenneth MacKay and Emergya (Cloud4all, FP7/2007-2013, grant agreement 46 | n° 289016). Three clause BSD license. 47 | -------------------------------------------------------------------------------- /test/benchmark-thread.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | #include 26 | #include 27 | 28 | #define NUM_THREADS (20 * 1000) 29 | 30 | static volatile int num_threads; 31 | 32 | 33 | static void thread_entry(void* arg) { 34 | ASSERT(arg == (void *) 42); 35 | num_threads++; 36 | /* FIXME write barrier? */ 37 | } 38 | 39 | 40 | BENCHMARK_IMPL(thread_create) { 41 | uint64_t start_time; 42 | double duration; 43 | uv_thread_t tid; 44 | int i, r; 45 | 46 | start_time = uv_hrtime(); 47 | 48 | for (i = 0; i < NUM_THREADS; i++) { 49 | r = uv_thread_create(&tid, thread_entry, (void *) 42); 50 | ASSERT(r == 0); 51 | 52 | r = uv_thread_join(&tid); 53 | ASSERT(r == 0); 54 | } 55 | 56 | duration = (uv_hrtime() - start_time) / 1e9; 57 | 58 | ASSERT(num_threads == NUM_THREADS); 59 | 60 | printf("%d threads created in %.2f seconds (%.0f/s)\n", 61 | NUM_THREADS, duration, NUM_THREADS / duration); 62 | 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /src/win/stream-inl.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UV_WIN_STREAM_INL_H_ 23 | #define UV_WIN_STREAM_INL_H_ 24 | 25 | #include 26 | 27 | #include "uv.h" 28 | #include "internal.h" 29 | #include "handle-inl.h" 30 | #include "req-inl.h" 31 | 32 | 33 | INLINE static void uv_stream_init(uv_loop_t* loop, 34 | uv_stream_t* handle, 35 | uv_handle_type type) { 36 | uv__handle_init(loop, (uv_handle_t*) handle, type); 37 | handle->write_queue_size = 0; 38 | handle->activecnt = 0; 39 | } 40 | 41 | 42 | INLINE static void uv_connection_init(uv_stream_t* handle) { 43 | handle->flags |= UV_HANDLE_CONNECTION; 44 | handle->write_reqs_pending = 0; 45 | 46 | uv_req_init(handle->loop, (uv_req_t*) &(handle->read_req)); 47 | handle->read_req.event_handle = NULL; 48 | handle->read_req.wait_handle = INVALID_HANDLE_VALUE; 49 | handle->read_req.type = UV_READ; 50 | handle->read_req.data = handle; 51 | 52 | handle->shutdown_req = NULL; 53 | } 54 | 55 | 56 | #endif /* UV_WIN_STREAM_INL_H_ */ 57 | -------------------------------------------------------------------------------- /test/test-async-null-cb.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | static uv_async_t async_handle; 26 | static uv_check_t check_handle; 27 | static int check_cb_called; 28 | static uv_thread_t thread; 29 | 30 | 31 | static void thread_cb(void* dummy) { 32 | (void) &dummy; 33 | uv_async_send(&async_handle); 34 | } 35 | 36 | 37 | static void check_cb(uv_check_t* handle) { 38 | ASSERT(check_cb_called == 0); 39 | uv_close((uv_handle_t*) &async_handle, NULL); 40 | uv_close((uv_handle_t*) &check_handle, NULL); 41 | check_cb_called++; 42 | } 43 | 44 | 45 | TEST_IMPL(async_null_cb) { 46 | ASSERT(0 == uv_async_init(uv_default_loop(), &async_handle, NULL)); 47 | ASSERT(0 == uv_check_init(uv_default_loop(), &check_handle)); 48 | ASSERT(0 == uv_check_start(&check_handle, check_cb)); 49 | ASSERT(0 == uv_thread_create(&thread, thread_cb, NULL)); 50 | ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT)); 51 | ASSERT(0 == uv_thread_join(&thread)); 52 | ASSERT(1 == check_cb_called); 53 | MAKE_VALGRIND_HAPPY(); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /test/test-cwd-and-chdir.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | #include 25 | 26 | #define PATHMAX 1024 27 | extern char executable_path[]; 28 | 29 | TEST_IMPL(cwd_and_chdir) { 30 | char buffer_orig[PATHMAX]; 31 | char buffer_new[PATHMAX]; 32 | size_t size; 33 | char* last_slash; 34 | int err; 35 | 36 | size = sizeof(buffer_orig); 37 | err = uv_cwd(buffer_orig, &size); 38 | ASSERT(err == 0); 39 | 40 | /* Remove trailing slash unless at a root directory. */ 41 | #ifdef _WIN32 42 | last_slash = strrchr(buffer_orig, '\\'); 43 | ASSERT(last_slash); 44 | if (last_slash > buffer_orig && *(last_slash - 1) != ':') { 45 | *last_slash = '\0'; 46 | } 47 | #else /* Unix */ 48 | last_slash = strrchr(buffer_orig, '/'); 49 | ASSERT(last_slash); 50 | if (last_slash != buffer_orig) { 51 | *last_slash = '\0'; 52 | } 53 | #endif 54 | 55 | err = uv_chdir(buffer_orig); 56 | ASSERT(err == 0); 57 | 58 | err = uv_cwd(buffer_new, &size); 59 | ASSERT(err == 0); 60 | 61 | ASSERT(strcmp(buffer_orig, buffer_new) == 0); 62 | 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /test/test-loop-alive.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | static uv_timer_t timer_handle; 26 | 27 | static void timer_cb(uv_timer_t* handle) { 28 | ASSERT(handle); 29 | } 30 | 31 | 32 | static uv_work_t work_req; 33 | 34 | static void work_cb(uv_work_t* req) { 35 | ASSERT(req); 36 | } 37 | 38 | static void after_work_cb(uv_work_t* req, int status) { 39 | ASSERT(req); 40 | ASSERT(status == 0); 41 | } 42 | 43 | 44 | TEST_IMPL(loop_alive) { 45 | int r; 46 | ASSERT(!uv_loop_alive(uv_default_loop())); 47 | 48 | /* loops with handles are alive */ 49 | uv_timer_init(uv_default_loop(), &timer_handle); 50 | uv_timer_start(&timer_handle, timer_cb, 100, 0); 51 | ASSERT(uv_loop_alive(uv_default_loop())); 52 | 53 | r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); 54 | ASSERT(r == 0); 55 | ASSERT(!uv_loop_alive(uv_default_loop())); 56 | 57 | /* loops with requests are alive */ 58 | r = uv_queue_work(uv_default_loop(), &work_req, work_cb, after_work_cb); 59 | ASSERT(r == 0); 60 | ASSERT(uv_loop_alive(uv_default_loop())); 61 | 62 | r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); 63 | ASSERT(r == 0); 64 | ASSERT(!uv_loop_alive(uv_default_loop())); 65 | 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /src/unix/atomic-ops.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013, Ben Noordhuis 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | */ 15 | 16 | #ifndef UV_ATOMIC_OPS_H_ 17 | #define UV_ATOMIC_OPS_H_ 18 | 19 | #include "internal.h" /* UV_UNUSED */ 20 | 21 | UV_UNUSED(static int cmpxchgi(int* ptr, int oldval, int newval)); 22 | UV_UNUSED(static long cmpxchgl(long* ptr, long oldval, long newval)); 23 | UV_UNUSED(static void cpu_relax(void)); 24 | 25 | /* Prefer hand-rolled assembly over the gcc builtins because the latter also 26 | * issue full memory barriers. 27 | */ 28 | UV_UNUSED(static int cmpxchgi(int* ptr, int oldval, int newval)) { 29 | #if defined(__i386__) || defined(__x86_64__) 30 | int out; 31 | __asm__ __volatile__ ("lock; cmpxchg %2, %1;" 32 | : "=a" (out), "+m" (*(volatile int*) ptr) 33 | : "r" (newval), "0" (oldval) 34 | : "memory"); 35 | return out; 36 | #else 37 | return __sync_val_compare_and_swap(ptr, oldval, newval); 38 | #endif 39 | } 40 | 41 | UV_UNUSED(static long cmpxchgl(long* ptr, long oldval, long newval)) { 42 | #if defined(__i386__) || defined(__x86_64__) 43 | long out; 44 | __asm__ __volatile__ ("lock; cmpxchg %2, %1;" 45 | : "=a" (out), "+m" (*(volatile long*) ptr) 46 | : "r" (newval), "0" (oldval) 47 | : "memory"); 48 | return out; 49 | #else 50 | return __sync_val_compare_and_swap(ptr, oldval, newval); 51 | #endif 52 | } 53 | 54 | UV_UNUSED(static void cpu_relax(void)) { 55 | #if defined(__i386__) || defined(__x86_64__) 56 | __asm__ __volatile__ ("rep; nop"); /* a.k.a. PAUSE */ 57 | #endif 58 | } 59 | 60 | #endif /* UV_ATOMIC_OPS_H_ */ 61 | -------------------------------------------------------------------------------- /test/test-poll-close.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include 23 | 24 | #ifndef _WIN32 25 | # include 26 | # include 27 | # include 28 | #endif 29 | 30 | #include "uv.h" 31 | #include "task.h" 32 | 33 | #define NUM_SOCKETS 64 34 | 35 | 36 | static int close_cb_called = 0; 37 | 38 | 39 | static void close_cb(uv_handle_t* handle) { 40 | close_cb_called++; 41 | } 42 | 43 | 44 | TEST_IMPL(poll_close) { 45 | uv_os_sock_t sockets[NUM_SOCKETS]; 46 | uv_poll_t poll_handles[NUM_SOCKETS]; 47 | int i; 48 | 49 | #ifdef _WIN32 50 | { 51 | struct WSAData wsa_data; 52 | int r = WSAStartup(MAKEWORD(2, 2), &wsa_data); 53 | ASSERT(r == 0); 54 | } 55 | #endif 56 | 57 | for (i = 0; i < NUM_SOCKETS; i++) { 58 | sockets[i] = socket(AF_INET, SOCK_STREAM, 0); 59 | uv_poll_init_socket(uv_default_loop(), &poll_handles[i], sockets[i]); 60 | uv_poll_start(&poll_handles[i], UV_READABLE | UV_WRITABLE, NULL); 61 | } 62 | 63 | for (i = 0; i < NUM_SOCKETS; i++) { 64 | uv_close((uv_handle_t*) &poll_handles[i], close_cb); 65 | } 66 | 67 | uv_run(uv_default_loop(), UV_RUN_DEFAULT); 68 | 69 | ASSERT(close_cb_called == NUM_SOCKETS); 70 | 71 | MAKE_VALGRIND_HAPPY(); 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /test/test-get-currentexe.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | #include 25 | 26 | #define PATHMAX 1024 27 | extern char executable_path[]; 28 | 29 | TEST_IMPL(get_currentexe) { 30 | char buffer[PATHMAX]; 31 | size_t size; 32 | char* match; 33 | char* path; 34 | int r; 35 | 36 | size = sizeof(buffer) / sizeof(buffer[0]); 37 | r = uv_exepath(buffer, &size); 38 | ASSERT(!r); 39 | 40 | /* uv_exepath can return an absolute path on darwin, so if the test runner 41 | * was run with a relative prefix of "./", we need to strip that prefix off 42 | * executable_path or we'll fail. */ 43 | if (executable_path[0] == '.' && executable_path[1] == '/') { 44 | path = executable_path + 2; 45 | } else { 46 | path = executable_path; 47 | } 48 | 49 | match = strstr(buffer, path); 50 | /* Verify that the path returned from uv_exepath is a subdirectory of 51 | * executable_path. 52 | */ 53 | ASSERT(match && !strcmp(match, path)); 54 | ASSERT(size == strlen(buffer)); 55 | 56 | /* Negative tests */ 57 | size = sizeof(buffer) / sizeof(buffer[0]); 58 | r = uv_exepath(NULL, &size); 59 | ASSERT(r == UV_EINVAL); 60 | 61 | r = uv_exepath(buffer, NULL); 62 | ASSERT(r == UV_EINVAL); 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /samples/socks5-proxy/util.c: -------------------------------------------------------------------------------- 1 | /* Copyright StrongLoop, Inc. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "defs.h" 23 | #include 24 | #include 25 | #include 26 | 27 | static void pr_do(FILE *stream, 28 | const char *label, 29 | const char *fmt, 30 | va_list ap); 31 | 32 | void *xmalloc(size_t size) { 33 | void *ptr; 34 | 35 | ptr = malloc(size); 36 | if (ptr == NULL) { 37 | pr_err("out of memory, need %lu bytes", (unsigned long) size); 38 | exit(1); 39 | } 40 | 41 | return ptr; 42 | } 43 | 44 | void pr_info(const char *fmt, ...) { 45 | va_list ap; 46 | va_start(ap, fmt); 47 | pr_do(stdout, "info", fmt, ap); 48 | va_end(ap); 49 | } 50 | 51 | void pr_warn(const char *fmt, ...) { 52 | va_list ap; 53 | va_start(ap, fmt); 54 | pr_do(stderr, "warn", fmt, ap); 55 | va_end(ap); 56 | } 57 | 58 | void pr_err(const char *fmt, ...) { 59 | va_list ap; 60 | va_start(ap, fmt); 61 | pr_do(stderr, "error", fmt, ap); 62 | va_end(ap); 63 | } 64 | 65 | static void pr_do(FILE *stream, 66 | const char *label, 67 | const char *fmt, 68 | va_list ap) { 69 | char fmtbuf[1024]; 70 | vsnprintf(fmtbuf, sizeof(fmtbuf), fmt, ap); 71 | fprintf(stream, "%s:%s: %s\n", _getprogname(), label, fmtbuf); 72 | } 73 | -------------------------------------------------------------------------------- /src/win/atomicops-inl.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UV_WIN_ATOMICOPS_INL_H_ 23 | #define UV_WIN_ATOMICOPS_INL_H_ 24 | 25 | #include "uv.h" 26 | 27 | 28 | /* Atomic set operation on char */ 29 | #ifdef _MSC_VER /* MSVC */ 30 | 31 | /* _InterlockedOr8 is supported by MSVC on x32 and x64. It is slightly less */ 32 | /* efficient than InterlockedExchange, but InterlockedExchange8 does not */ 33 | /* exist, and interlocked operations on larger targets might require the */ 34 | /* target to be aligned. */ 35 | //#pragma intrinsic(_InterlockedOr8) 36 | 37 | static char __declspec(inline) uv__atomic_exchange_set(char volatile* target) { 38 | //return _InterlockedOr8(target, 1); 39 | //__asm xor eax, eax 40 | __asm mov ecx, target 41 | __asm mov al, byte ptr [ecx] 42 | __asm lock or byte ptr [ecx], 1 43 | } 44 | 45 | #else /* GCC */ 46 | 47 | /* Mingw-32 version, hopefully this works for 64-bit gcc as well. */ 48 | static inline char uv__atomic_exchange_set(char volatile* target) { 49 | const char one = 1; 50 | char old_value; 51 | __asm__ __volatile__ ("lock xchgb %0, %1\n\t" 52 | : "=r"(old_value), "=m"(*target) 53 | : "0"(one), "m"(*target) 54 | : "memory"); 55 | return old_value; 56 | } 57 | 58 | #endif 59 | 60 | #endif /* UV_WIN_ATOMICOPS_INL_H_ */ 61 | -------------------------------------------------------------------------------- /test/test-tcp-connect6-error.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | #include 25 | #include 26 | 27 | 28 | static int connect_cb_called = 0; 29 | static int close_cb_called = 0; 30 | 31 | 32 | static void connect_cb(uv_connect_t* handle, int status) { 33 | ASSERT(handle != NULL); 34 | connect_cb_called++; 35 | } 36 | 37 | 38 | static void close_cb(uv_handle_t* handle) { 39 | ASSERT(handle != NULL); 40 | close_cb_called++; 41 | } 42 | 43 | 44 | TEST_IMPL(tcp_connect6_error_fault) { 45 | const char garbage[] = 46 | "blah blah blah blah blah blah blah blah blah blah blah blah"; 47 | const struct sockaddr_in6* garbage_addr; 48 | uv_tcp_t server; 49 | int r; 50 | uv_connect_t req; 51 | 52 | garbage_addr = (const struct sockaddr_in6*) &garbage; 53 | 54 | r = uv_tcp_init(uv_default_loop(), &server); 55 | ASSERT(r == 0); 56 | r = uv_tcp_connect(&req, 57 | &server, 58 | (const struct sockaddr*) garbage_addr, 59 | connect_cb); 60 | ASSERT(r == UV_EINVAL); 61 | 62 | uv_close((uv_handle_t*)&server, close_cb); 63 | 64 | uv_run(uv_default_loop(), UV_RUN_DEFAULT); 65 | 66 | ASSERT(connect_cb_called == 0); 67 | ASSERT(close_cb_called == 1); 68 | 69 | MAKE_VALGRIND_HAPPY(); 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /test/test-tcp-connect-error.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | #include 25 | #include 26 | 27 | 28 | static int connect_cb_called = 0; 29 | static int close_cb_called = 0; 30 | 31 | 32 | 33 | static void connect_cb(uv_connect_t* handle, int status) { 34 | ASSERT(handle != NULL); 35 | connect_cb_called++; 36 | } 37 | 38 | 39 | 40 | static void close_cb(uv_handle_t* handle) { 41 | ASSERT(handle != NULL); 42 | close_cb_called++; 43 | } 44 | 45 | 46 | TEST_IMPL(tcp_connect_error_fault) { 47 | const char garbage[] = 48 | "blah blah blah blah blah blah blah blah blah blah blah blah"; 49 | const struct sockaddr_in* garbage_addr; 50 | uv_tcp_t server; 51 | int r; 52 | uv_connect_t req; 53 | 54 | garbage_addr = (const struct sockaddr_in*) &garbage; 55 | 56 | r = uv_tcp_init(uv_default_loop(), &server); 57 | ASSERT(r == 0); 58 | r = uv_tcp_connect(&req, 59 | &server, 60 | (const struct sockaddr*) garbage_addr, 61 | connect_cb); 62 | ASSERT(r == UV_EINVAL); 63 | 64 | uv_close((uv_handle_t*)&server, close_cb); 65 | 66 | uv_run(uv_default_loop(), UV_RUN_DEFAULT); 67 | 68 | ASSERT(connect_cb_called == 0); 69 | ASSERT(close_cb_called == 1); 70 | 71 | MAKE_VALGRIND_HAPPY(); 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /test/test-threadpool.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | static int work_cb_count; 26 | static int after_work_cb_count; 27 | static uv_work_t work_req; 28 | static char data; 29 | 30 | 31 | static void work_cb(uv_work_t* req) { 32 | ASSERT(req == &work_req); 33 | ASSERT(req->data == &data); 34 | work_cb_count++; 35 | } 36 | 37 | 38 | static void after_work_cb(uv_work_t* req, int status) { 39 | ASSERT(status == 0); 40 | ASSERT(req == &work_req); 41 | ASSERT(req->data == &data); 42 | after_work_cb_count++; 43 | } 44 | 45 | 46 | TEST_IMPL(threadpool_queue_work_simple) { 47 | int r; 48 | 49 | work_req.data = &data; 50 | r = uv_queue_work(uv_default_loop(), &work_req, work_cb, after_work_cb); 51 | ASSERT(r == 0); 52 | uv_run(uv_default_loop(), UV_RUN_DEFAULT); 53 | 54 | ASSERT(work_cb_count == 1); 55 | ASSERT(after_work_cb_count == 1); 56 | 57 | MAKE_VALGRIND_HAPPY(); 58 | return 0; 59 | } 60 | 61 | 62 | TEST_IMPL(threadpool_queue_work_einval) { 63 | int r; 64 | 65 | work_req.data = &data; 66 | r = uv_queue_work(uv_default_loop(), &work_req, NULL, after_work_cb); 67 | ASSERT(r == UV_EINVAL); 68 | 69 | uv_run(uv_default_loop(), UV_RUN_DEFAULT); 70 | 71 | ASSERT(work_cb_count == 0); 72 | ASSERT(after_work_cb_count == 0); 73 | 74 | MAKE_VALGRIND_HAPPY(); 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /test/benchmark-sizes.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "task.h" 23 | #include "uv.h" 24 | 25 | 26 | BENCHMARK_IMPL(sizes) { 27 | LOGF("uv_shutdown_t: %u bytes\n", (unsigned int) sizeof(uv_shutdown_t)); 28 | LOGF("uv_write_t: %u bytes\n", (unsigned int) sizeof(uv_write_t)); 29 | LOGF("uv_connect_t: %u bytes\n", (unsigned int) sizeof(uv_connect_t)); 30 | LOGF("uv_udp_send_t: %u bytes\n", (unsigned int) sizeof(uv_udp_send_t)); 31 | LOGF("uv_tcp_t: %u bytes\n", (unsigned int) sizeof(uv_tcp_t)); 32 | LOGF("uv_pipe_t: %u bytes\n", (unsigned int) sizeof(uv_pipe_t)); 33 | LOGF("uv_tty_t: %u bytes\n", (unsigned int) sizeof(uv_tty_t)); 34 | LOGF("uv_prepare_t: %u bytes\n", (unsigned int) sizeof(uv_prepare_t)); 35 | LOGF("uv_check_t: %u bytes\n", (unsigned int) sizeof(uv_check_t)); 36 | LOGF("uv_idle_t: %u bytes\n", (unsigned int) sizeof(uv_idle_t)); 37 | LOGF("uv_async_t: %u bytes\n", (unsigned int) sizeof(uv_async_t)); 38 | LOGF("uv_timer_t: %u bytes\n", (unsigned int) sizeof(uv_timer_t)); 39 | LOGF("uv_fs_poll_t: %u bytes\n", (unsigned int) sizeof(uv_fs_poll_t)); 40 | LOGF("uv_fs_event_t: %u bytes\n", (unsigned int) sizeof(uv_fs_event_t)); 41 | LOGF("uv_process_t: %u bytes\n", (unsigned int) sizeof(uv_process_t)); 42 | LOGF("uv_poll_t: %u bytes\n", (unsigned int) sizeof(uv_poll_t)); 43 | LOGF("uv_loop_t: %u bytes\n", (unsigned int) sizeof(uv_loop_t)); 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /test/test-loop-stop.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | static uv_prepare_t prepare_handle; 26 | static uv_timer_t timer_handle; 27 | static int prepare_called = 0; 28 | static int timer_called = 0; 29 | static int num_ticks = 10; 30 | 31 | 32 | static void prepare_cb(uv_prepare_t* handle) { 33 | ASSERT(handle == &prepare_handle); 34 | prepare_called++; 35 | if (prepare_called == num_ticks) 36 | uv_prepare_stop(handle); 37 | } 38 | 39 | 40 | static void timer_cb(uv_timer_t* handle) { 41 | ASSERT(handle == &timer_handle); 42 | timer_called++; 43 | if (timer_called == 1) 44 | uv_stop(uv_default_loop()); 45 | else if (timer_called == num_ticks) 46 | uv_timer_stop(handle); 47 | } 48 | 49 | 50 | TEST_IMPL(loop_stop) { 51 | int r; 52 | uv_prepare_init(uv_default_loop(), &prepare_handle); 53 | uv_prepare_start(&prepare_handle, prepare_cb); 54 | uv_timer_init(uv_default_loop(), &timer_handle); 55 | uv_timer_start(&timer_handle, timer_cb, 100, 100); 56 | 57 | r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); 58 | ASSERT(r != 0); 59 | ASSERT(timer_called == 1); 60 | 61 | r = uv_run(uv_default_loop(), UV_RUN_NOWAIT); 62 | ASSERT(r != 0); 63 | ASSERT(prepare_called > 1); 64 | 65 | r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); 66 | ASSERT(r == 0); 67 | ASSERT(timer_called == 10); 68 | ASSERT(prepare_called == 10); 69 | 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /test/test-callback-order.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | static int idle_cb_called; 26 | static int timer_cb_called; 27 | 28 | static uv_idle_t idle_handle; 29 | static uv_timer_t timer_handle; 30 | 31 | 32 | /* idle_cb should run before timer_cb */ 33 | static void idle_cb(uv_idle_t* handle) { 34 | ASSERT(idle_cb_called == 0); 35 | ASSERT(timer_cb_called == 0); 36 | uv_idle_stop(handle); 37 | idle_cb_called++; 38 | } 39 | 40 | 41 | static void timer_cb(uv_timer_t* handle) { 42 | ASSERT(idle_cb_called == 1); 43 | ASSERT(timer_cb_called == 0); 44 | uv_timer_stop(handle); 45 | timer_cb_called++; 46 | } 47 | 48 | 49 | static void next_tick(uv_idle_t* handle) { 50 | uv_loop_t* loop = handle->loop; 51 | uv_idle_stop(handle); 52 | uv_idle_init(loop, &idle_handle); 53 | uv_idle_start(&idle_handle, idle_cb); 54 | uv_timer_init(loop, &timer_handle); 55 | uv_timer_start(&timer_handle, timer_cb, 0, 0); 56 | } 57 | 58 | 59 | TEST_IMPL(callback_order) { 60 | uv_loop_t* loop; 61 | uv_idle_t idle; 62 | 63 | loop = uv_default_loop(); 64 | uv_idle_init(loop, &idle); 65 | uv_idle_start(&idle, next_tick); 66 | 67 | ASSERT(idle_cb_called == 0); 68 | ASSERT(timer_cb_called == 0); 69 | 70 | uv_run(loop, UV_RUN_DEFAULT); 71 | 72 | ASSERT(idle_cb_called == 1); 73 | ASSERT(timer_cb_called == 1); 74 | 75 | MAKE_VALGRIND_HAPPY(); 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /test/test-osx-select.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | #ifdef __APPLE__ 26 | 27 | #include 28 | #include 29 | 30 | static int read_count; 31 | 32 | 33 | static void alloc_cb(uv_handle_t* handle, size_t size, uv_buf_t* buf) { 34 | static char slab[1024]; 35 | buf->base = slab; 36 | buf->len = sizeof(slab); 37 | } 38 | 39 | 40 | static void read_cb(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) { 41 | fprintf(stdout, "got data %d\n", ++read_count); 42 | 43 | if (read_count == 3) 44 | uv_close((uv_handle_t*) stream, NULL); 45 | } 46 | 47 | 48 | TEST_IMPL(osx_select) { 49 | int r; 50 | int fd; 51 | size_t i; 52 | size_t len; 53 | const char* str; 54 | uv_tty_t tty; 55 | 56 | fd = open("/dev/tty", O_RDONLY); 57 | 58 | ASSERT(fd >= 0); 59 | 60 | r = uv_tty_init(uv_default_loop(), &tty, fd, 1); 61 | ASSERT(r == 0); 62 | 63 | uv_read_start((uv_stream_t*) &tty, alloc_cb, read_cb); 64 | 65 | /* Emulate user-input */ 66 | str = "got some input\n" 67 | "with a couple of lines\n" 68 | "feel pretty happy\n"; 69 | for (i = 0, len = strlen(str); i < len; i++) { 70 | r = ioctl(fd, TIOCSTI, str + i); 71 | ASSERT(r == 0); 72 | } 73 | 74 | uv_run(uv_default_loop(), UV_RUN_DEFAULT); 75 | 76 | ASSERT(read_count == 3); 77 | 78 | MAKE_VALGRIND_HAPPY(); 79 | return 0; 80 | } 81 | 82 | #endif /* __APPLE__ */ 83 | -------------------------------------------------------------------------------- /test/test-walk-handles.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | #include 26 | #include 27 | 28 | static char magic_cookie[] = "magic cookie"; 29 | static int seen_timer_handle; 30 | static uv_timer_t timer; 31 | 32 | 33 | static void walk_cb(uv_handle_t* handle, void* arg) { 34 | ASSERT(arg == (void*)magic_cookie); 35 | 36 | if (handle == (uv_handle_t*)&timer) { 37 | seen_timer_handle++; 38 | } else { 39 | ASSERT(0 && "unexpected handle"); 40 | } 41 | } 42 | 43 | 44 | static void timer_cb(uv_timer_t* handle) { 45 | ASSERT(handle == &timer); 46 | 47 | uv_walk(handle->loop, walk_cb, magic_cookie); 48 | uv_close((uv_handle_t*)handle, NULL); 49 | } 50 | 51 | 52 | TEST_IMPL(walk_handles) { 53 | uv_loop_t* loop; 54 | int r; 55 | 56 | loop = uv_default_loop(); 57 | 58 | r = uv_timer_init(loop, &timer); 59 | ASSERT(r == 0); 60 | 61 | r = uv_timer_start(&timer, timer_cb, 1, 0); 62 | ASSERT(r == 0); 63 | 64 | /* Start event loop, expect to see the timer handle in walk_cb. */ 65 | ASSERT(seen_timer_handle == 0); 66 | r = uv_run(loop, UV_RUN_DEFAULT); 67 | ASSERT(r == 0); 68 | ASSERT(seen_timer_handle == 1); 69 | 70 | /* Loop is finished, walk_cb should not see our timer handle. */ 71 | seen_timer_handle = 0; 72 | uv_walk(loop, walk_cb, magic_cookie); 73 | ASSERT(seen_timer_handle == 0); 74 | 75 | MAKE_VALGRIND_HAPPY(); 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /src/unix/dl.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "internal.h" 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | static int uv__dlerror(uv_lib_t* lib); 31 | 32 | 33 | int uv_dlopen(const char* filename, uv_lib_t* lib) { 34 | dlerror(); /* Reset error status. */ 35 | lib->errmsg = NULL; 36 | lib->handle = dlopen(filename, RTLD_LAZY); 37 | return lib->handle ? 0 : uv__dlerror(lib); 38 | } 39 | 40 | 41 | void uv_dlclose(uv_lib_t* lib) { 42 | if (lib->errmsg) { 43 | free(lib->errmsg); 44 | lib->errmsg = NULL; 45 | } 46 | 47 | if (lib->handle) { 48 | /* Ignore errors. No good way to signal them without leaking memory. */ 49 | dlclose(lib->handle); 50 | lib->handle = NULL; 51 | } 52 | } 53 | 54 | 55 | int uv_dlsym(uv_lib_t* lib, const char* name, void** ptr) { 56 | dlerror(); /* Reset error status. */ 57 | *ptr = dlsym(lib->handle, name); 58 | return uv__dlerror(lib); 59 | } 60 | 61 | 62 | const char* uv_dlerror(const uv_lib_t* lib) { 63 | return lib->errmsg ? lib->errmsg : "no error"; 64 | } 65 | 66 | 67 | static int uv__dlerror(uv_lib_t* lib) { 68 | const char* errmsg; 69 | 70 | if (lib->errmsg) 71 | free(lib->errmsg); 72 | 73 | errmsg = dlerror(); 74 | 75 | if (errmsg) { 76 | lib->errmsg = strdup(errmsg); 77 | return -1; 78 | } 79 | else { 80 | lib->errmsg = NULL; 81 | return 0; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /m4/dtrace.m4: -------------------------------------------------------------------------------- 1 | dnl Copyright (C) 2009 Sun Microsystems 2 | dnl This file is free software; Sun Microsystems 3 | dnl gives unlimited permission to copy and/or distribute it, 4 | dnl with or without modifications, as long as this notice is preserved. 5 | 6 | dnl --------------------------------------------------------------------------- 7 | dnl Macro: PANDORA_ENABLE_DTRACE 8 | dnl --------------------------------------------------------------------------- 9 | AC_DEFUN([PANDORA_ENABLE_DTRACE],[ 10 | AC_ARG_ENABLE([dtrace], 11 | [AS_HELP_STRING([--disable-dtrace], 12 | [enable DTrace USDT probes. @<:@default=yes@:>@])], 13 | [ac_cv_enable_dtrace="$enableval"], 14 | [ac_cv_enable_dtrace="yes"]) 15 | 16 | AS_IF([test "$ac_cv_enable_dtrace" = "yes"],[ 17 | AC_CHECK_PROGS([DTRACE], [dtrace]) 18 | AS_IF([test "x$ac_cv_prog_DTRACE" = "xdtrace"],[ 19 | 20 | AC_CACHE_CHECK([if dtrace works],[ac_cv_dtrace_works],[ 21 | cat >conftest.d <<_ACEOF 22 | provider Example { 23 | probe increment(int); 24 | }; 25 | _ACEOF 26 | $DTRACE -h -o conftest.h -s conftest.d 2>/dev/zero 27 | AS_IF([test $? -eq 0],[ac_cv_dtrace_works=yes], 28 | [ac_cv_dtrace_works=no]) 29 | rm -f conftest.h conftest.d 30 | ]) 31 | AS_IF([test "x$ac_cv_dtrace_works" = "xyes"],[ 32 | AC_DEFINE([HAVE_DTRACE], [1], [Enables DTRACE Support]) 33 | AC_CACHE_CHECK([if dtrace should instrument object files], 34 | [ac_cv_dtrace_needs_objects],[ 35 | dnl DTrace on MacOSX does not use -G option 36 | cat >conftest.d <<_ACEOF 37 | provider Example { 38 | probe increment(int); 39 | }; 40 | _ACEOF 41 | cat > conftest.c <<_ACEOF 42 | #include "conftest.h" 43 | void foo() { 44 | EXAMPLE_INCREMENT(1); 45 | } 46 | _ACEOF 47 | $DTRACE -h -o conftest.h -s conftest.d 2>/dev/zero 48 | $CC -c -o conftest.o conftest.c 49 | $DTRACE -G -o conftest.d.o -s conftest.d conftest.o 2>/dev/zero 50 | AS_IF([test $? -eq 0],[ac_cv_dtrace_needs_objects=yes], 51 | [ac_cv_dtrace_needs_objects=no]) 52 | rm -f conftest.d.o conftest.d conftest.h conftest.o conftest.c 53 | ]) 54 | ]) 55 | AC_SUBST(DTRACEFLAGS) dnl TODO: test for -G on OSX 56 | ac_cv_have_dtrace=yes 57 | ])]) 58 | 59 | AM_CONDITIONAL([HAVE_DTRACE], [test "x$ac_cv_dtrace_works" = "xyes"]) 60 | AM_CONDITIONAL([DTRACE_NEEDS_OBJECTS], 61 | [test "x$ac_cv_dtrace_needs_objects" = "xyes"]) 62 | 63 | ]) 64 | dnl --------------------------------------------------------------------------- 65 | dnl End Macro: PANDORA_ENABLE_DTRACE 66 | dnl --------------------------------------------------------------------------- 67 | -------------------------------------------------------------------------------- /Makefile.mingw: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013, Ben Noordhuis 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | CC ?= gcc 16 | 17 | CFLAGS += -Wall \ 18 | -Wextra \ 19 | -Wno-unused-parameter \ 20 | -Iinclude \ 21 | -Isrc \ 22 | -Isrc/win \ 23 | -DWIN32_LEAN_AND_MEAN \ 24 | -D_WIN32_WINNT=0x0600 25 | 26 | INCLUDES = include/stdint-msvc2008.h \ 27 | include/tree.h \ 28 | include/uv-errno.h \ 29 | include/uv-threadpool.h \ 30 | include/uv-version.h \ 31 | include/uv-win.h \ 32 | include/uv.h \ 33 | src/heap-inl.h \ 34 | src/queue.h \ 35 | src/uv-common.h \ 36 | src/win/atomicops-inl.h \ 37 | src/win/handle-inl.h \ 38 | src/win/internal.h \ 39 | src/win/req-inl.h \ 40 | src/win/stream-inl.h \ 41 | src/win/winapi.h \ 42 | src/win/winsock.h 43 | 44 | OBJS = src/fs-poll.o \ 45 | src/inet.o \ 46 | src/threadpool.o \ 47 | src/uv-common.o \ 48 | src/version.o \ 49 | src/win/async.o \ 50 | src/win/core.o \ 51 | src/win/dl.o \ 52 | src/win/error.o \ 53 | src/win/fs-event.o \ 54 | src/win/fs.o \ 55 | src/win/getaddrinfo.o \ 56 | src/win/getnameinfo.o \ 57 | src/win/handle.o \ 58 | src/win/loop-watcher.o \ 59 | src/win/pipe.o \ 60 | src/win/poll.o \ 61 | src/win/process-stdio.o \ 62 | src/win/process.o \ 63 | src/win/req.o \ 64 | src/win/signal.o \ 65 | src/win/stream.o \ 66 | src/win/tcp.o \ 67 | src/win/thread.o \ 68 | src/win/timer.o \ 69 | src/win/tty.o \ 70 | src/win/udp.o \ 71 | src/win/util.o \ 72 | src/win/winapi.o \ 73 | src/win/winsock.o 74 | 75 | all: libuv.a 76 | 77 | clean: 78 | -$(RM) $(OBJS) libuv.a 79 | 80 | libuv.a: $(OBJS) 81 | $(AR) crs $@ $^ 82 | 83 | $(OBJS): %.o : %.c $(INCLUDES) 84 | $(CC) $(CFLAGS) -c -o $@ $< 85 | -------------------------------------------------------------------------------- /test/test-shutdown-twice.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | /* 23 | * This is a regression test for issue #1113 (calling uv_shutdown twice will 24 | * leave a ghost request in the system) 25 | */ 26 | 27 | #include "uv.h" 28 | #include "task.h" 29 | 30 | static uv_shutdown_t req1; 31 | static uv_shutdown_t req2; 32 | 33 | static int shutdown_cb_called = 0; 34 | 35 | static void close_cb(uv_handle_t* handle) { 36 | 37 | } 38 | 39 | static void shutdown_cb(uv_shutdown_t* req, int status) { 40 | ASSERT(req == &req1); 41 | ASSERT(status == 0); 42 | shutdown_cb_called++; 43 | uv_close((uv_handle_t*) req->handle, close_cb); 44 | } 45 | 46 | static void connect_cb(uv_connect_t* req, int status) { 47 | int r; 48 | 49 | ASSERT(status == 0); 50 | 51 | r = uv_shutdown(&req1, req->handle, shutdown_cb); 52 | ASSERT(r == 0); 53 | r = uv_shutdown(&req2, req->handle, shutdown_cb); 54 | ASSERT(r != 0); 55 | 56 | } 57 | 58 | TEST_IMPL(shutdown_twice) { 59 | struct sockaddr_in addr; 60 | uv_loop_t* loop; 61 | int r; 62 | uv_tcp_t h; 63 | 64 | uv_connect_t connect_req; 65 | 66 | ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr)); 67 | loop = uv_default_loop(); 68 | 69 | r = uv_tcp_init(loop, &h); 70 | 71 | r = uv_tcp_connect(&connect_req, 72 | &h, 73 | (const struct sockaddr*) &addr, 74 | connect_cb); 75 | ASSERT(r == 0); 76 | 77 | r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); 78 | ASSERT(r == 0); 79 | 80 | ASSERT(shutdown_cb_called == 1); 81 | 82 | MAKE_VALGRIND_HAPPY(); 83 | return 0; 84 | } 85 | -------------------------------------------------------------------------------- /test/test-poll-closesocket.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifdef _WIN32 23 | 24 | #include 25 | 26 | #include "uv.h" 27 | #include "task.h" 28 | 29 | uv_os_sock_t sock; 30 | uv_poll_t handle; 31 | 32 | static int close_cb_called = 0; 33 | 34 | 35 | static void close_cb(uv_handle_t* h) { 36 | close_cb_called++; 37 | } 38 | 39 | 40 | static void poll_cb(uv_poll_t* h, int status, int events) { 41 | int r; 42 | 43 | ASSERT(status == 0); 44 | ASSERT(h == &handle); 45 | 46 | r = uv_poll_start(&handle, UV_READABLE, poll_cb); 47 | ASSERT(r == 0); 48 | 49 | closesocket(sock); 50 | uv_close((uv_handle_t*) &handle, close_cb); 51 | 52 | } 53 | 54 | 55 | TEST_IMPL(poll_closesocket) { 56 | struct WSAData wsa_data; 57 | int r; 58 | unsigned long on; 59 | struct sockaddr_in addr; 60 | 61 | r = WSAStartup(MAKEWORD(2, 2), &wsa_data); 62 | ASSERT(r == 0); 63 | 64 | sock = socket(AF_INET, SOCK_STREAM, 0); 65 | ASSERT(sock != INVALID_SOCKET); 66 | on = 1; 67 | r = ioctlsocket(sock, FIONBIO, &on); 68 | ASSERT(r == 0); 69 | 70 | r = uv_ip4_addr("127.0.0.1", TEST_PORT, &addr); 71 | ASSERT(r == 0); 72 | 73 | r = connect(sock, (const struct sockaddr*) &addr, sizeof addr); 74 | ASSERT(r != 0); 75 | ASSERT(WSAGetLastError() == WSAEWOULDBLOCK); 76 | 77 | r = uv_poll_init_socket(uv_default_loop(), &handle, sock); 78 | ASSERT(r == 0); 79 | r = uv_poll_start(&handle, UV_WRITABLE, poll_cb); 80 | ASSERT(r == 0); 81 | 82 | uv_run(uv_default_loop(), UV_RUN_DEFAULT); 83 | 84 | ASSERT(close_cb_called == 1); 85 | 86 | MAKE_VALGRIND_HAPPY(); 87 | return 0; 88 | } 89 | #endif 90 | -------------------------------------------------------------------------------- /test/benchmark-loop-count.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "task.h" 23 | #include "uv.h" 24 | 25 | #include 26 | #include 27 | 28 | #define NUM_TICKS (2 * 1000 * 1000) 29 | 30 | static unsigned long ticks; 31 | static uv_idle_t idle_handle; 32 | static uv_timer_t timer_handle; 33 | 34 | 35 | static void idle_cb(uv_idle_t* handle) { 36 | if (++ticks == NUM_TICKS) 37 | uv_idle_stop(handle); 38 | } 39 | 40 | 41 | static void idle2_cb(uv_idle_t* handle) { 42 | ticks++; 43 | } 44 | 45 | 46 | static void timer_cb(uv_timer_t* handle) { 47 | uv_idle_stop(&idle_handle); 48 | uv_timer_stop(&timer_handle); 49 | } 50 | 51 | 52 | BENCHMARK_IMPL(loop_count) { 53 | uv_loop_t* loop = uv_default_loop(); 54 | uint64_t ns; 55 | 56 | uv_idle_init(loop, &idle_handle); 57 | uv_idle_start(&idle_handle, idle_cb); 58 | 59 | ns = uv_hrtime(); 60 | uv_run(loop, UV_RUN_DEFAULT); 61 | ns = uv_hrtime() - ns; 62 | 63 | ASSERT(ticks == NUM_TICKS); 64 | 65 | LOGF("loop_count: %d ticks in %.2fs (%.0f/s)\n", 66 | NUM_TICKS, 67 | ns / 1e9, 68 | NUM_TICKS / (ns / 1e9)); 69 | 70 | MAKE_VALGRIND_HAPPY(); 71 | return 0; 72 | } 73 | 74 | 75 | BENCHMARK_IMPL(loop_count_timed) { 76 | uv_loop_t* loop = uv_default_loop(); 77 | 78 | uv_idle_init(loop, &idle_handle); 79 | uv_idle_start(&idle_handle, idle2_cb); 80 | 81 | uv_timer_init(loop, &timer_handle); 82 | uv_timer_start(&timer_handle, timer_cb, 5000, 0); 83 | 84 | uv_run(loop, UV_RUN_DEFAULT); 85 | 86 | LOGF("loop_count: %lu ticks (%.0f ticks/s)\n", ticks, ticks / 5.0); 87 | 88 | MAKE_VALGRIND_HAPPY(); 89 | return 0; 90 | } 91 | -------------------------------------------------------------------------------- /test/test-close-order.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | static int check_cb_called; 26 | static int timer_cb_called; 27 | static int close_cb_called; 28 | 29 | static uv_check_t check_handle; 30 | static uv_timer_t timer_handle1; 31 | static uv_timer_t timer_handle2; 32 | 33 | 34 | static void close_cb(uv_handle_t* handle) { 35 | ASSERT(handle != NULL); 36 | close_cb_called++; 37 | } 38 | 39 | 40 | /* check_cb should run before any close_cb */ 41 | static void check_cb(uv_check_t* handle) { 42 | ASSERT(check_cb_called == 0); 43 | ASSERT(timer_cb_called == 1); 44 | ASSERT(close_cb_called == 0); 45 | uv_close((uv_handle_t*) handle, close_cb); 46 | uv_close((uv_handle_t*) &timer_handle2, close_cb); 47 | check_cb_called++; 48 | } 49 | 50 | 51 | static void timer_cb(uv_timer_t* handle) { 52 | uv_close((uv_handle_t*) handle, close_cb); 53 | timer_cb_called++; 54 | } 55 | 56 | 57 | TEST_IMPL(close_order) { 58 | uv_loop_t* loop; 59 | loop = uv_default_loop(); 60 | 61 | uv_check_init(loop, &check_handle); 62 | uv_check_start(&check_handle, check_cb); 63 | uv_timer_init(loop, &timer_handle1); 64 | uv_timer_start(&timer_handle1, timer_cb, 0, 0); 65 | uv_timer_init(loop, &timer_handle2); 66 | uv_timer_start(&timer_handle2, timer_cb, 100000, 0); 67 | 68 | ASSERT(check_cb_called == 0); 69 | ASSERT(close_cb_called == 0); 70 | ASSERT(timer_cb_called == 0); 71 | 72 | uv_run(loop, UV_RUN_DEFAULT); 73 | 74 | ASSERT(check_cb_called == 1); 75 | ASSERT(close_cb_called == 3); 76 | ASSERT(timer_cb_called == 1); 77 | 78 | MAKE_VALGRIND_HAPPY(); 79 | return 0; 80 | } 81 | -------------------------------------------------------------------------------- /samples/socks5-proxy/LICENSE: -------------------------------------------------------------------------------- 1 | Files: * 2 | ======== 3 | 4 | Copyright StrongLoop, Inc. All rights reserved. 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to 8 | deal in the Software without restriction, including without limitation the 9 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 | sell copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22 | IN THE SOFTWARE. 23 | 24 | 25 | Files: getopt.c 26 | =============== 27 | 28 | Copyright (c) 1987, 1993, 1994 29 | The Regents of the University of California. All rights reserved. 30 | 31 | Redistribution and use in source and binary forms, with or without 32 | modification, are permitted provided that the following conditions 33 | are met: 34 | 1. Redistributions of source code must retain the above copyright 35 | notice, this list of conditions and the following disclaimer. 36 | 2. Redistributions in binary form must reproduce the above copyright 37 | notice, this list of conditions and the following disclaimer in the 38 | documentation and/or other materials provided with the distribution. 39 | 3. Neither the name of the University nor the names of its contributors 40 | may be used to endorse or promote products derived from this software 41 | without specific prior written permission. 42 | 43 | THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 44 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 45 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 46 | ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 47 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 48 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 49 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 50 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 51 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 52 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 53 | SUCH DAMAGE. 54 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013, Ben Noordhuis 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | AC_PREREQ(2.57) 16 | AC_INIT([libuv], [0.11.27], [https://github.com/joyent/libuv/issues]) 17 | AC_CONFIG_MACRO_DIR([m4]) 18 | m4_include([m4/libuv-extra-automake-flags.m4]) 19 | m4_include([m4/as_case.m4]) 20 | AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects] UV_EXTRA_AUTOMAKE_FLAGS) 21 | AC_CANONICAL_HOST 22 | AC_ENABLE_SHARED 23 | AC_ENABLE_STATIC 24 | AC_PROG_CC 25 | AM_PROG_CC_C_O 26 | # AM_PROG_AR is not available in automake v0.11 but it's essential in v0.12. 27 | m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) 28 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) 29 | LT_INIT 30 | # TODO(bnoordhuis) Check for -pthread vs. -pthreads 31 | AC_CHECK_LIB([dl], [dlopen]) 32 | AC_CHECK_LIB([kstat], [kstat_lookup]) 33 | AC_CHECK_LIB([kvm], [kvm_open]) 34 | AC_CHECK_LIB([nsl], [gethostbyname]) 35 | AC_CHECK_LIB([perfstat], [perfstat_cpu]) 36 | AC_CHECK_LIB([pthread], [pthread_mutex_init]) 37 | AC_CHECK_LIB([rt], [clock_gettime]) 38 | AC_CHECK_LIB([sendfile], [sendfile]) 39 | AC_CHECK_LIB([socket], [socket]) 40 | AC_SYS_LARGEFILE 41 | AM_CONDITIONAL([AIX], [AS_CASE([$host_os],[aix*], [true], [false])]) 42 | AM_CONDITIONAL([ANDROID],[AS_CASE([$host_os],[linux-android*],[true], [false])]) 43 | AM_CONDITIONAL([DARWIN], [AS_CASE([$host_os],[darwin*], [true], [false])]) 44 | AM_CONDITIONAL([FREEBSD],[AS_CASE([$host_os],[freebsd*], [true], [false])]) 45 | AM_CONDITIONAL([LINUX], [AS_CASE([$host_os],[linux*], [true], [false])]) 46 | AM_CONDITIONAL([NETBSD], [AS_CASE([$host_os],[netbsd*], [true], [false])]) 47 | AM_CONDITIONAL([OPENBSD],[AS_CASE([$host_os],[openbsd*], [true], [false])]) 48 | AM_CONDITIONAL([SUNOS], [AS_CASE([$host_os],[solaris*], [true], [false])]) 49 | AM_CONDITIONAL([WINNT], [AS_CASE([$host_os],[mingw*], [true], [false])]) 50 | PANDORA_ENABLE_DTRACE 51 | AC_CHECK_PROG(PKG_CONFIG, pkg-config, yes) 52 | AM_CONDITIONAL([HAVE_PKG_CONFIG], [test "x$PKG_CONFIG" != "x"]) 53 | AS_IF([test "x$PKG_CONFIG" != "x"], [ 54 | AC_CONFIG_FILES([libuv.pc]) 55 | ]) 56 | AC_CONFIG_FILES([Makefile]) 57 | AC_OUTPUT 58 | -------------------------------------------------------------------------------- /test/test-getnameinfo.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | #include 25 | #include 26 | #include 27 | 28 | 29 | static const char* address_ip4 = "127.0.0.1"; 30 | static const char* address_ip6 = "::1"; 31 | static const int port = 80; 32 | 33 | static struct sockaddr_in addr4; 34 | static struct sockaddr_in6 addr6; 35 | static uv_getnameinfo_t req; 36 | 37 | static void getnameinfo_req(uv_getnameinfo_t* handle, 38 | int status, 39 | const char* hostname, 40 | const char* service) { 41 | ASSERT(handle != NULL); 42 | ASSERT(status == 0); 43 | ASSERT(hostname != NULL); 44 | ASSERT(service != NULL); 45 | } 46 | 47 | TEST_IMPL(getnameinfo_basic_ip4) { 48 | int r; 49 | 50 | r = uv_ip4_addr(address_ip4, port, &addr4); 51 | ASSERT(r == 0); 52 | 53 | r = uv_getnameinfo(uv_default_loop(), 54 | &req, 55 | &getnameinfo_req, 56 | (const struct sockaddr*)&addr4, 57 | 0); 58 | ASSERT(r == 0); 59 | 60 | uv_run(uv_default_loop(), UV_RUN_DEFAULT); 61 | 62 | MAKE_VALGRIND_HAPPY(); 63 | return 0; 64 | } 65 | 66 | TEST_IMPL(getnameinfo_basic_ip6) { 67 | int r; 68 | 69 | r = uv_ip6_addr(address_ip6, port, &addr6); 70 | ASSERT(r == 0); 71 | 72 | r = uv_getnameinfo(uv_default_loop(), 73 | &req, 74 | &getnameinfo_req, 75 | (const struct sockaddr*)&addr6, 76 | 0); 77 | ASSERT(r == 0); 78 | 79 | uv_run(uv_default_loop(), UV_RUN_DEFAULT); 80 | 81 | MAKE_VALGRIND_HAPPY(); 82 | return 0; 83 | } 84 | -------------------------------------------------------------------------------- /test/test-active.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | #include 26 | #include 27 | 28 | 29 | static int close_cb_called = 0; 30 | 31 | 32 | static void close_cb(uv_handle_t* handle) { 33 | ASSERT(handle != NULL); 34 | close_cb_called++; 35 | } 36 | 37 | 38 | static void timer_cb(uv_timer_t* handle) { 39 | ASSERT(0 && "timer_cb should not have been called"); 40 | } 41 | 42 | 43 | TEST_IMPL(active) { 44 | int r; 45 | uv_timer_t timer; 46 | 47 | r = uv_timer_init(uv_default_loop(), &timer); 48 | ASSERT(r == 0); 49 | 50 | /* uv_is_active() and uv_is_closing() should always return either 0 or 1. */ 51 | ASSERT(0 == uv_is_active((uv_handle_t*) &timer)); 52 | ASSERT(0 == uv_is_closing((uv_handle_t*) &timer)); 53 | 54 | r = uv_timer_start(&timer, timer_cb, 1000, 0); 55 | ASSERT(r == 0); 56 | 57 | ASSERT(1 == uv_is_active((uv_handle_t*) &timer)); 58 | ASSERT(0 == uv_is_closing((uv_handle_t*) &timer)); 59 | 60 | r = uv_timer_stop(&timer); 61 | ASSERT(r == 0); 62 | 63 | ASSERT(0 == uv_is_active((uv_handle_t*) &timer)); 64 | ASSERT(0 == uv_is_closing((uv_handle_t*) &timer)); 65 | 66 | r = uv_timer_start(&timer, timer_cb, 1000, 0); 67 | ASSERT(r == 0); 68 | 69 | ASSERT(1 == uv_is_active((uv_handle_t*) &timer)); 70 | ASSERT(0 == uv_is_closing((uv_handle_t*) &timer)); 71 | 72 | uv_close((uv_handle_t*) &timer, close_cb); 73 | 74 | ASSERT(0 == uv_is_active((uv_handle_t*) &timer)); 75 | ASSERT(1 == uv_is_closing((uv_handle_t*) &timer)); 76 | 77 | r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); 78 | ASSERT(r == 0); 79 | 80 | ASSERT(close_cb_called == 1); 81 | 82 | MAKE_VALGRIND_HAPPY(); 83 | return 0; 84 | } 85 | -------------------------------------------------------------------------------- /test/benchmark-getaddrinfo.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | #include 25 | 26 | #define CONCURRENT_CALLS 10 27 | #define TOTAL_CALLS 10000 28 | 29 | static const char* name = "localhost"; 30 | 31 | static uv_loop_t* loop; 32 | 33 | static uv_getaddrinfo_t handles[CONCURRENT_CALLS]; 34 | 35 | static int calls_initiated = 0; 36 | static int calls_completed = 0; 37 | static int64_t start_time; 38 | static int64_t end_time; 39 | 40 | 41 | static void getaddrinfo_initiate(uv_getaddrinfo_t* handle); 42 | 43 | 44 | static void getaddrinfo_cb(uv_getaddrinfo_t* handle, int status, 45 | struct addrinfo* res) { 46 | ASSERT(status == 0); 47 | calls_completed++; 48 | if (calls_initiated < TOTAL_CALLS) { 49 | getaddrinfo_initiate(handle); 50 | } 51 | 52 | uv_freeaddrinfo(res); 53 | } 54 | 55 | 56 | static void getaddrinfo_initiate(uv_getaddrinfo_t* handle) { 57 | int r; 58 | 59 | calls_initiated++; 60 | 61 | r = uv_getaddrinfo(loop, handle, &getaddrinfo_cb, name, NULL, NULL); 62 | ASSERT(r == 0); 63 | } 64 | 65 | 66 | BENCHMARK_IMPL(getaddrinfo) { 67 | int i; 68 | 69 | loop = uv_default_loop(); 70 | 71 | uv_update_time(loop); 72 | start_time = uv_now(loop); 73 | 74 | for (i = 0; i < CONCURRENT_CALLS; i++) { 75 | getaddrinfo_initiate(&handles[i]); 76 | } 77 | 78 | uv_run(loop, UV_RUN_DEFAULT); 79 | 80 | uv_update_time(loop); 81 | end_time = uv_now(loop); 82 | 83 | ASSERT(calls_initiated == TOTAL_CALLS); 84 | ASSERT(calls_completed == TOTAL_CALLS); 85 | 86 | LOGF("getaddrinfo: %.0f req/s\n", 87 | (double) calls_completed / (double) (end_time - start_time) * 1000.0); 88 | 89 | MAKE_VALGRIND_HAPPY(); 90 | return 0; 91 | } 92 | -------------------------------------------------------------------------------- /test/test-udp-bind.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | 30 | TEST_IMPL(udp_bind) { 31 | struct sockaddr_in addr; 32 | uv_loop_t* loop; 33 | uv_udp_t h1, h2; 34 | int r; 35 | 36 | ASSERT(0 == uv_ip4_addr("0.0.0.0", TEST_PORT, &addr)); 37 | 38 | loop = uv_default_loop(); 39 | 40 | r = uv_udp_init(loop, &h1); 41 | ASSERT(r == 0); 42 | 43 | r = uv_udp_init(loop, &h2); 44 | ASSERT(r == 0); 45 | 46 | r = uv_udp_bind(&h1, (const struct sockaddr*) &addr, 0); 47 | ASSERT(r == 0); 48 | 49 | r = uv_udp_bind(&h2, (const struct sockaddr*) &addr, 0); 50 | ASSERT(r == UV_EADDRINUSE); 51 | 52 | uv_close((uv_handle_t*) &h1, NULL); 53 | uv_close((uv_handle_t*) &h2, NULL); 54 | 55 | r = uv_run(loop, UV_RUN_DEFAULT); 56 | ASSERT(r == 0); 57 | 58 | MAKE_VALGRIND_HAPPY(); 59 | return 0; 60 | } 61 | 62 | 63 | TEST_IMPL(udp_bind_reuseaddr) { 64 | struct sockaddr_in addr; 65 | uv_loop_t* loop; 66 | uv_udp_t h1, h2; 67 | int r; 68 | 69 | ASSERT(0 == uv_ip4_addr("0.0.0.0", TEST_PORT, &addr)); 70 | 71 | loop = uv_default_loop(); 72 | 73 | r = uv_udp_init(loop, &h1); 74 | ASSERT(r == 0); 75 | 76 | r = uv_udp_init(loop, &h2); 77 | ASSERT(r == 0); 78 | 79 | r = uv_udp_bind(&h1, (const struct sockaddr*) &addr, UV_UDP_REUSEADDR); 80 | ASSERT(r == 0); 81 | 82 | r = uv_udp_bind(&h2, (const struct sockaddr*) &addr, UV_UDP_REUSEADDR); 83 | ASSERT(r == 0); 84 | 85 | uv_close((uv_handle_t*) &h1, NULL); 86 | uv_close((uv_handle_t*) &h2, NULL); 87 | 88 | r = uv_run(loop, UV_RUN_DEFAULT); 89 | ASSERT(r == 0); 90 | 91 | MAKE_VALGRIND_HAPPY(); 92 | return 0; 93 | } 94 | -------------------------------------------------------------------------------- /test/test-udp-dgram-too-big.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #define CHECK_HANDLE(handle) \ 30 | ASSERT((uv_udp_t*)(handle) == &handle_) 31 | 32 | #define CHECK_REQ(req) \ 33 | ASSERT((req) == &req_); 34 | 35 | static uv_udp_t handle_; 36 | static uv_udp_send_t req_; 37 | 38 | static int send_cb_called; 39 | static int close_cb_called; 40 | 41 | 42 | static void close_cb(uv_handle_t* handle) { 43 | CHECK_HANDLE(handle); 44 | close_cb_called++; 45 | } 46 | 47 | 48 | static void send_cb(uv_udp_send_t* req, int status) { 49 | CHECK_REQ(req); 50 | CHECK_HANDLE(req->handle); 51 | 52 | ASSERT(status == UV_EMSGSIZE); 53 | 54 | uv_close((uv_handle_t*)req->handle, close_cb); 55 | send_cb_called++; 56 | } 57 | 58 | 59 | TEST_IMPL(udp_dgram_too_big) { 60 | char dgram[65536]; /* 64K MTU is unlikely, even on localhost */ 61 | struct sockaddr_in addr; 62 | uv_buf_t buf; 63 | int r; 64 | 65 | memset(dgram, 42, sizeof dgram); /* silence valgrind */ 66 | 67 | r = uv_udp_init(uv_default_loop(), &handle_); 68 | ASSERT(r == 0); 69 | 70 | buf = uv_buf_init(dgram, sizeof dgram); 71 | ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr)); 72 | 73 | r = uv_udp_send(&req_, 74 | &handle_, 75 | &buf, 76 | 1, 77 | (const struct sockaddr*) &addr, 78 | send_cb); 79 | ASSERT(r == 0); 80 | 81 | ASSERT(close_cb_called == 0); 82 | ASSERT(send_cb_called == 0); 83 | 84 | uv_run(uv_default_loop(), UV_RUN_DEFAULT); 85 | 86 | ASSERT(send_cb_called == 1); 87 | ASSERT(close_cb_called == 1); 88 | 89 | MAKE_VALGRIND_HAPPY(); 90 | return 0; 91 | } 92 | -------------------------------------------------------------------------------- /test/benchmark-million-timers.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "task.h" 23 | #include "uv.h" 24 | 25 | #define NUM_TIMERS (10 * 1000 * 1000) 26 | 27 | static int timer_cb_called; 28 | static int close_cb_called; 29 | 30 | 31 | static void timer_cb(uv_timer_t* handle) { 32 | timer_cb_called++; 33 | } 34 | 35 | 36 | static void close_cb(uv_handle_t* handle) { 37 | close_cb_called++; 38 | } 39 | 40 | 41 | BENCHMARK_IMPL(million_timers) { 42 | uv_timer_t* timers; 43 | uv_loop_t* loop; 44 | uint64_t before_all; 45 | uint64_t before_run; 46 | uint64_t after_run; 47 | uint64_t after_all; 48 | int timeout; 49 | int i; 50 | 51 | timers = malloc(NUM_TIMERS * sizeof(timers[0])); 52 | ASSERT(timers != NULL); 53 | 54 | loop = uv_default_loop(); 55 | timeout = 0; 56 | 57 | before_all = uv_hrtime(); 58 | for (i = 0; i < NUM_TIMERS; i++) { 59 | if (i % 1000 == 0) timeout++; 60 | ASSERT(0 == uv_timer_init(loop, timers + i)); 61 | ASSERT(0 == uv_timer_start(timers + i, timer_cb, timeout, 0)); 62 | } 63 | 64 | before_run = uv_hrtime(); 65 | ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT)); 66 | after_run = uv_hrtime(); 67 | 68 | for (i = 0; i < NUM_TIMERS; i++) 69 | uv_close((uv_handle_t*) (timers + i), close_cb); 70 | 71 | ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT)); 72 | after_all = uv_hrtime(); 73 | 74 | ASSERT(timer_cb_called == NUM_TIMERS); 75 | ASSERT(close_cb_called == NUM_TIMERS); 76 | free(timers); 77 | 78 | LOGF("%.2f seconds total\n", (after_all - before_all) / 1e9); 79 | LOGF("%.2f seconds init\n", (before_run - before_all) / 1e9); 80 | LOGF("%.2f seconds dispatch\n", (after_run - before_run) / 1e9); 81 | LOGF("%.2f seconds cleanup\n", (after_all - after_run) / 1e9); 82 | 83 | MAKE_VALGRIND_HAPPY(); 84 | return 0; 85 | } 86 | -------------------------------------------------------------------------------- /test/test-tcp-read-stop.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | static uv_timer_t timer_handle; 26 | static uv_tcp_t tcp_handle; 27 | static uv_write_t write_req; 28 | 29 | 30 | static void fail_cb(void) { 31 | ASSERT(0 && "fail_cb called"); 32 | } 33 | 34 | 35 | static void write_cb(uv_write_t* req, int status) { 36 | uv_close((uv_handle_t*) &timer_handle, NULL); 37 | uv_close((uv_handle_t*) &tcp_handle, NULL); 38 | } 39 | 40 | 41 | static void timer_cb(uv_timer_t* handle) { 42 | uv_buf_t buf = uv_buf_init("PING", 4); 43 | ASSERT(0 == uv_write(&write_req, 44 | (uv_stream_t*) &tcp_handle, 45 | &buf, 46 | 1, 47 | write_cb)); 48 | ASSERT(0 == uv_read_stop((uv_stream_t*) &tcp_handle)); 49 | } 50 | 51 | 52 | static void connect_cb(uv_connect_t* req, int status) { 53 | ASSERT(0 == status); 54 | ASSERT(0 == uv_timer_start(&timer_handle, timer_cb, 50, 0)); 55 | ASSERT(0 == uv_read_start((uv_stream_t*) &tcp_handle, 56 | (uv_alloc_cb) fail_cb, 57 | (uv_read_cb) fail_cb)); 58 | } 59 | 60 | 61 | TEST_IMPL(tcp_read_stop) { 62 | uv_connect_t connect_req; 63 | struct sockaddr_in addr; 64 | 65 | ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr)); 66 | ASSERT(0 == uv_timer_init(uv_default_loop(), &timer_handle)); 67 | ASSERT(0 == uv_tcp_init(uv_default_loop(), &tcp_handle)); 68 | ASSERT(0 == uv_tcp_connect(&connect_req, 69 | &tcp_handle, 70 | (const struct sockaddr*) &addr, 71 | connect_cb)); 72 | ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT)); 73 | MAKE_VALGRIND_HAPPY(); 74 | 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /src/win/dl.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "internal.h" 24 | 25 | static int uv__dlerror(uv_lib_t* lib, int errorno); 26 | 27 | 28 | int uv_dlopen(const char* filename, uv_lib_t* lib) { 29 | WCHAR filename_w[32768]; 30 | 31 | lib->handle = NULL; 32 | lib->errmsg = NULL; 33 | 34 | if (!uv_utf8_to_utf16(filename, filename_w, ARRAY_SIZE(filename_w))) { 35 | return uv__dlerror(lib, GetLastError()); 36 | } 37 | 38 | lib->handle = LoadLibraryExW(filename_w, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); 39 | if (lib->handle == NULL) { 40 | return uv__dlerror(lib, GetLastError()); 41 | } 42 | 43 | return 0; 44 | } 45 | 46 | 47 | void uv_dlclose(uv_lib_t* lib) { 48 | if (lib->errmsg) { 49 | LocalFree((void*)lib->errmsg); 50 | lib->errmsg = NULL; 51 | } 52 | 53 | if (lib->handle) { 54 | /* Ignore errors. No good way to signal them without leaking memory. */ 55 | FreeLibrary(lib->handle); 56 | lib->handle = NULL; 57 | } 58 | } 59 | 60 | 61 | int uv_dlsym(uv_lib_t* lib, const char* name, void** ptr) { 62 | *ptr = (void*) GetProcAddress(lib->handle, name); 63 | return uv__dlerror(lib, *ptr ? 0 : GetLastError()); 64 | } 65 | 66 | 67 | const char* uv_dlerror(const uv_lib_t* lib) { 68 | return lib->errmsg ? lib->errmsg : "no error"; 69 | } 70 | 71 | 72 | static int uv__dlerror(uv_lib_t* lib, int errorno) { 73 | if (lib->errmsg) { 74 | LocalFree((void*)lib->errmsg); 75 | lib->errmsg = NULL; 76 | } 77 | 78 | if (errorno) { 79 | FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | 80 | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorno, 81 | MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 82 | (LPSTR)&lib->errmsg, 0, NULL); 83 | } 84 | 85 | return errorno ? -1 : 0; 86 | } 87 | -------------------------------------------------------------------------------- /test/test-close-fd.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #if !defined(_WIN32) 23 | 24 | #include "uv.h" 25 | #include "task.h" 26 | #include 27 | #include 28 | 29 | static unsigned int read_cb_called; 30 | 31 | static void alloc_cb(uv_handle_t *handle, size_t size, uv_buf_t *buf) { 32 | static char slab[1]; 33 | buf->base = slab; 34 | buf->len = sizeof(slab); 35 | } 36 | 37 | static void read_cb(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf) { 38 | switch (++read_cb_called) { 39 | case 1: 40 | ASSERT(nread == 1); 41 | uv_read_stop(handle); 42 | break; 43 | case 2: 44 | ASSERT(nread == UV_EOF); 45 | uv_close((uv_handle_t *) handle, NULL); 46 | break; 47 | default: 48 | ASSERT(!"read_cb_called > 2"); 49 | } 50 | } 51 | 52 | TEST_IMPL(close_fd) { 53 | uv_pipe_t pipe_handle; 54 | int fd[2]; 55 | 56 | ASSERT(0 == pipe(fd)); 57 | ASSERT(0 == fcntl(fd[0], F_SETFL, O_NONBLOCK)); 58 | ASSERT(0 == uv_pipe_init(uv_default_loop(), &pipe_handle, 0)); 59 | ASSERT(0 == uv_pipe_open(&pipe_handle, fd[0])); 60 | fd[0] = -1; /* uv_pipe_open() takes ownership of the file descriptor. */ 61 | ASSERT(1 == write(fd[1], "", 1)); 62 | ASSERT(0 == close(fd[1])); 63 | fd[1] = -1; 64 | ASSERT(0 == uv_read_start((uv_stream_t *) &pipe_handle, alloc_cb, read_cb)); 65 | ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT)); 66 | ASSERT(1 == read_cb_called); 67 | ASSERT(0 == uv_is_active((const uv_handle_t *) &pipe_handle)); 68 | ASSERT(0 == uv_read_start((uv_stream_t *) &pipe_handle, alloc_cb, read_cb)); 69 | ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT)); 70 | ASSERT(2 == read_cb_called); 71 | ASSERT(0 != uv_is_closing((const uv_handle_t *) &pipe_handle)); 72 | 73 | MAKE_VALGRIND_HAPPY(); 74 | return 0; 75 | } 76 | 77 | #endif /* !defined(_WIN32) */ 78 | -------------------------------------------------------------------------------- /test/test-tcp-connect-timeout.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | #include 25 | #include 26 | 27 | 28 | static int connect_cb_called; 29 | static int close_cb_called; 30 | 31 | static uv_connect_t connect_req; 32 | static uv_timer_t timer; 33 | static uv_tcp_t conn; 34 | 35 | static void connect_cb(uv_connect_t* req, int status); 36 | static void timer_cb(uv_timer_t* handle); 37 | static void close_cb(uv_handle_t* handle); 38 | 39 | 40 | static void connect_cb(uv_connect_t* req, int status) { 41 | ASSERT(req == &connect_req); 42 | ASSERT(status == UV_ECANCELED); 43 | connect_cb_called++; 44 | } 45 | 46 | 47 | static void timer_cb(uv_timer_t* handle) { 48 | ASSERT(handle == &timer); 49 | uv_close((uv_handle_t*)&conn, close_cb); 50 | uv_close((uv_handle_t*)&timer, close_cb); 51 | } 52 | 53 | 54 | static void close_cb(uv_handle_t* handle) { 55 | ASSERT(handle == (uv_handle_t*)&conn || handle == (uv_handle_t*)&timer); 56 | close_cb_called++; 57 | } 58 | 59 | 60 | /* Verify that connecting to an unreachable address or port doesn't hang 61 | * the event loop. 62 | */ 63 | TEST_IMPL(tcp_connect_timeout) { 64 | struct sockaddr_in addr; 65 | int r; 66 | 67 | ASSERT(0 == uv_ip4_addr("8.8.8.8", 9999, &addr)); 68 | 69 | r = uv_timer_init(uv_default_loop(), &timer); 70 | ASSERT(r == 0); 71 | 72 | r = uv_timer_start(&timer, timer_cb, 50, 0); 73 | ASSERT(r == 0); 74 | 75 | r = uv_tcp_init(uv_default_loop(), &conn); 76 | ASSERT(r == 0); 77 | 78 | r = uv_tcp_connect(&connect_req, 79 | &conn, 80 | (const struct sockaddr*) &addr, 81 | connect_cb); 82 | ASSERT(r == 0); 83 | 84 | r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); 85 | ASSERT(r == 0); 86 | 87 | MAKE_VALGRIND_HAPPY(); 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /test/test-tcp-close-while-connecting.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | static uv_timer_t timer1_handle; 26 | static uv_timer_t timer2_handle; 27 | static uv_tcp_t tcp_handle; 28 | 29 | static int connect_cb_called; 30 | static int timer1_cb_called; 31 | static int close_cb_called; 32 | 33 | 34 | static void close_cb(uv_handle_t* handle) { 35 | close_cb_called++; 36 | } 37 | 38 | 39 | static void connect_cb(uv_connect_t* req, int status) { 40 | ASSERT(status == UV_ECANCELED); 41 | uv_timer_stop(&timer2_handle); 42 | connect_cb_called++; 43 | } 44 | 45 | 46 | static void timer1_cb(uv_timer_t* handle) { 47 | uv_close((uv_handle_t*)handle, close_cb); 48 | uv_close((uv_handle_t*)&tcp_handle, close_cb); 49 | timer1_cb_called++; 50 | } 51 | 52 | 53 | static void timer2_cb(uv_timer_t* handle) { 54 | ASSERT(0 && "should not be called"); 55 | } 56 | 57 | 58 | TEST_IMPL(tcp_close_while_connecting) { 59 | uv_connect_t connect_req; 60 | struct sockaddr_in addr; 61 | uv_loop_t* loop; 62 | 63 | loop = uv_default_loop(); 64 | ASSERT(0 == uv_ip4_addr("1.2.3.4", TEST_PORT, &addr)); 65 | ASSERT(0 == uv_tcp_init(loop, &tcp_handle)); 66 | ASSERT(0 == uv_tcp_connect(&connect_req, 67 | &tcp_handle, 68 | (const struct sockaddr*) &addr, 69 | connect_cb)); 70 | ASSERT(0 == uv_timer_init(loop, &timer1_handle)); 71 | ASSERT(0 == uv_timer_start(&timer1_handle, timer1_cb, 50, 0)); 72 | ASSERT(0 == uv_timer_init(loop, &timer2_handle)); 73 | ASSERT(0 == uv_timer_start(&timer2_handle, timer2_cb, 86400 * 1000, 0)); 74 | ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT)); 75 | 76 | ASSERT(connect_cb_called == 1); 77 | ASSERT(timer1_cb_called == 1); 78 | ASSERT(close_cb_called == 2); 79 | 80 | MAKE_VALGRIND_HAPPY(); 81 | return 0; 82 | } 83 | -------------------------------------------------------------------------------- /test/test-pipe-connect-error.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | #include 25 | #include 26 | 27 | 28 | #ifdef _WIN32 29 | # define BAD_PIPENAME "bad-pipe" 30 | #else 31 | # define BAD_PIPENAME "/path/to/unix/socket/that/really/should/not/be/there" 32 | #endif 33 | 34 | 35 | static int close_cb_called = 0; 36 | static int connect_cb_called = 0; 37 | 38 | 39 | static void close_cb(uv_handle_t* handle) { 40 | ASSERT(handle != NULL); 41 | close_cb_called++; 42 | } 43 | 44 | 45 | static void connect_cb(uv_connect_t* connect_req, int status) { 46 | ASSERT(status == UV_ENOENT); 47 | uv_close((uv_handle_t*)connect_req->handle, close_cb); 48 | connect_cb_called++; 49 | } 50 | 51 | 52 | static void connect_cb_file(uv_connect_t* connect_req, int status) { 53 | ASSERT(status == UV_ENOTSOCK || status == UV_ECONNREFUSED); 54 | uv_close((uv_handle_t*)connect_req->handle, close_cb); 55 | connect_cb_called++; 56 | } 57 | 58 | 59 | TEST_IMPL(pipe_connect_bad_name) { 60 | uv_pipe_t client; 61 | uv_connect_t req; 62 | int r; 63 | 64 | r = uv_pipe_init(uv_default_loop(), &client, 0); 65 | ASSERT(r == 0); 66 | uv_pipe_connect(&req, &client, BAD_PIPENAME, connect_cb); 67 | 68 | uv_run(uv_default_loop(), UV_RUN_DEFAULT); 69 | 70 | ASSERT(close_cb_called == 1); 71 | ASSERT(connect_cb_called == 1); 72 | 73 | MAKE_VALGRIND_HAPPY(); 74 | return 0; 75 | } 76 | 77 | 78 | TEST_IMPL(pipe_connect_to_file) { 79 | const char* path = "test/fixtures/empty_file"; 80 | uv_pipe_t client; 81 | uv_connect_t req; 82 | int r; 83 | 84 | r = uv_pipe_init(uv_default_loop(), &client, 0); 85 | ASSERT(r == 0); 86 | uv_pipe_connect(&req, &client, path, connect_cb_file); 87 | 88 | uv_run(uv_default_loop(), UV_RUN_DEFAULT); 89 | 90 | ASSERT(close_cb_called == 1); 91 | ASSERT(connect_cb_called == 1); 92 | 93 | MAKE_VALGRIND_HAPPY(); 94 | return 0; 95 | } 96 | -------------------------------------------------------------------------------- /test/test-udp-multicast-ttl.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #define CHECK_HANDLE(handle) \ 30 | ASSERT((uv_udp_t*)(handle) == &server || (uv_udp_t*)(handle) == &client) 31 | 32 | static uv_udp_t server; 33 | static uv_udp_t client; 34 | 35 | static int sv_send_cb_called; 36 | static int close_cb_called; 37 | 38 | 39 | static void close_cb(uv_handle_t* handle) { 40 | CHECK_HANDLE(handle); 41 | close_cb_called++; 42 | } 43 | 44 | 45 | static void sv_send_cb(uv_udp_send_t* req, int status) { 46 | ASSERT(req != NULL); 47 | ASSERT(status == 0); 48 | CHECK_HANDLE(req->handle); 49 | 50 | sv_send_cb_called++; 51 | 52 | uv_close((uv_handle_t*) req->handle, close_cb); 53 | } 54 | 55 | 56 | TEST_IMPL(udp_multicast_ttl) { 57 | int r; 58 | uv_udp_send_t req; 59 | uv_buf_t buf; 60 | struct sockaddr_in addr; 61 | 62 | r = uv_udp_init(uv_default_loop(), &server); 63 | ASSERT(r == 0); 64 | 65 | ASSERT(0 == uv_ip4_addr("0.0.0.0", 0, &addr)); 66 | r = uv_udp_bind(&server, (const struct sockaddr*) &addr, 0); 67 | ASSERT(r == 0); 68 | 69 | r = uv_udp_set_multicast_ttl(&server, 32); 70 | ASSERT(r == 0); 71 | 72 | /* server sends "PING" */ 73 | buf = uv_buf_init("PING", 4); 74 | ASSERT(0 == uv_ip4_addr("239.255.0.1", TEST_PORT, &addr)); 75 | r = uv_udp_send(&req, 76 | &server, 77 | &buf, 78 | 1, 79 | (const struct sockaddr*) &addr, 80 | sv_send_cb); 81 | ASSERT(r == 0); 82 | 83 | ASSERT(close_cb_called == 0); 84 | ASSERT(sv_send_cb_called == 0); 85 | 86 | /* run the loop till all events are processed */ 87 | uv_run(uv_default_loop(), UV_RUN_DEFAULT); 88 | 89 | ASSERT(sv_send_cb_called == 1); 90 | ASSERT(close_cb_called == 1); 91 | 92 | MAKE_VALGRIND_HAPPY(); 93 | return 0; 94 | } 95 | -------------------------------------------------------------------------------- /test/test-idle.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | 26 | static uv_idle_t idle_handle; 27 | static uv_check_t check_handle; 28 | static uv_timer_t timer_handle; 29 | 30 | static int idle_cb_called = 0; 31 | static int check_cb_called = 0; 32 | static int timer_cb_called = 0; 33 | static int close_cb_called = 0; 34 | 35 | 36 | static void close_cb(uv_handle_t* handle) { 37 | close_cb_called++; 38 | } 39 | 40 | 41 | static void timer_cb(uv_timer_t* handle) { 42 | ASSERT(handle == &timer_handle); 43 | 44 | uv_close((uv_handle_t*) &idle_handle, close_cb); 45 | uv_close((uv_handle_t*) &check_handle, close_cb); 46 | uv_close((uv_handle_t*) &timer_handle, close_cb); 47 | 48 | timer_cb_called++; 49 | LOGF("timer_cb %d\n", timer_cb_called); 50 | } 51 | 52 | 53 | static void idle_cb(uv_idle_t* handle) { 54 | ASSERT(handle == &idle_handle); 55 | 56 | idle_cb_called++; 57 | LOGF("idle_cb %d\n", idle_cb_called); 58 | } 59 | 60 | 61 | static void check_cb(uv_check_t* handle) { 62 | ASSERT(handle == &check_handle); 63 | 64 | check_cb_called++; 65 | LOGF("check_cb %d\n", check_cb_called); 66 | } 67 | 68 | 69 | TEST_IMPL(idle_starvation) { 70 | int r; 71 | 72 | r = uv_idle_init(uv_default_loop(), &idle_handle); 73 | ASSERT(r == 0); 74 | r = uv_idle_start(&idle_handle, idle_cb); 75 | ASSERT(r == 0); 76 | 77 | r = uv_check_init(uv_default_loop(), &check_handle); 78 | ASSERT(r == 0); 79 | r = uv_check_start(&check_handle, check_cb); 80 | ASSERT(r == 0); 81 | 82 | r = uv_timer_init(uv_default_loop(), &timer_handle); 83 | ASSERT(r == 0); 84 | r = uv_timer_start(&timer_handle, timer_cb, 50, 0); 85 | ASSERT(r == 0); 86 | 87 | r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); 88 | ASSERT(r == 0); 89 | 90 | ASSERT(idle_cb_called > 0); 91 | ASSERT(timer_cb_called == 1); 92 | ASSERT(close_cb_called == 3); 93 | 94 | MAKE_VALGRIND_HAPPY(); 95 | return 0; 96 | } 97 | -------------------------------------------------------------------------------- /test/test-pipe-server-close.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | #include 26 | #include 27 | 28 | 29 | static uv_pipe_t pipe_client; 30 | static uv_pipe_t pipe_server; 31 | static uv_connect_t connect_req; 32 | 33 | static int pipe_close_cb_called = 0; 34 | static int pipe_client_connect_cb_called = 0; 35 | 36 | 37 | static void pipe_close_cb(uv_handle_t* handle) { 38 | ASSERT(handle == (uv_handle_t*) &pipe_client || 39 | handle == (uv_handle_t*) &pipe_server); 40 | pipe_close_cb_called++; 41 | } 42 | 43 | 44 | static void pipe_client_connect_cb(uv_connect_t* req, int status) { 45 | ASSERT(req == &connect_req); 46 | ASSERT(status == 0); 47 | 48 | pipe_client_connect_cb_called++; 49 | 50 | uv_close((uv_handle_t*) &pipe_client, pipe_close_cb); 51 | uv_close((uv_handle_t*) &pipe_server, pipe_close_cb); 52 | } 53 | 54 | 55 | static void pipe_server_connection_cb(uv_stream_t* handle, int status) { 56 | /* This function *may* be called, depending on whether accept or the 57 | * connection callback is called first. 58 | */ 59 | ASSERT(status == 0); 60 | } 61 | 62 | 63 | TEST_IMPL(pipe_server_close) { 64 | uv_loop_t* loop; 65 | int r; 66 | 67 | loop = uv_default_loop(); 68 | ASSERT(loop != NULL); 69 | 70 | r = uv_pipe_init(loop, &pipe_server, 0); 71 | ASSERT(r == 0); 72 | 73 | r = uv_pipe_bind(&pipe_server, TEST_PIPENAME); 74 | ASSERT(r == 0); 75 | 76 | r = uv_listen((uv_stream_t*) &pipe_server, 0, pipe_server_connection_cb); 77 | ASSERT(r == 0); 78 | 79 | r = uv_pipe_init(loop, &pipe_client, 0); 80 | ASSERT(r == 0); 81 | 82 | uv_pipe_connect(&connect_req, &pipe_client, TEST_PIPENAME, pipe_client_connect_cb); 83 | 84 | r = uv_run(loop, UV_RUN_DEFAULT); 85 | ASSERT(r == 0); 86 | ASSERT(pipe_client_connect_cb_called == 1); 87 | ASSERT(pipe_close_cb_called == 2); 88 | 89 | MAKE_VALGRIND_HAPPY(); 90 | return 0; 91 | } 92 | -------------------------------------------------------------------------------- /include/pthread-fixes.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013, Sony Mobile Communications AB 2 | * Copyright (c) 2012, Google Inc. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | * Redistributions in binary form must reproduce the above 12 | copyright notice, this list of conditions and the following disclaimer 13 | in the documentation and/or other materials provided with the 14 | distribution. 15 | * Neither the name of Google Inc. nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef GOOGLE_BREAKPAD_COMMON_ANDROID_TESTING_PTHREAD_FIXES_H 33 | #define GOOGLE_BREAKPAD_COMMON_ANDROID_TESTING_PTHREAD_FIXES_H 34 | 35 | #include 36 | 37 | 38 | /*Android doesn't provide pthread_barrier_t for now.*/ 39 | #ifndef PTHREAD_BARRIER_SERIAL_THREAD 40 | 41 | /* Anything except 0 will do here.*/ 42 | #define PTHREAD_BARRIER_SERIAL_THREAD 0x12345 43 | 44 | typedef struct { 45 | pthread_mutex_t mutex; 46 | pthread_cond_t cond; 47 | unsigned count; 48 | } pthread_barrier_t; 49 | 50 | int pthread_barrier_init(pthread_barrier_t* barrier, 51 | const void* barrier_attr, 52 | unsigned count); 53 | 54 | int pthread_barrier_wait(pthread_barrier_t* barrier); 55 | int pthread_barrier_destroy(pthread_barrier_t *barrier); 56 | #endif /* defined(PTHREAD_BARRIER_SERIAL_THREAD) */ 57 | 58 | int pthread_yield(void); 59 | 60 | /* Workaround pthread_sigmask() returning EINVAL on versions < 4.1 by 61 | * replacing all calls to pthread_sigmask with sigprocmask. See: 62 | * https://android.googlesource.com/platform/bionic/+/9bf330b5 63 | * https://code.google.com/p/android/issues/detail?id=15337 64 | */ 65 | int uv__pthread_sigmask(int how, const sigset_t* set, sigset_t* oset); 66 | 67 | #ifdef pthread_sigmask 68 | #undef pthread_sigmask 69 | #endif 70 | #define pthread_sigmask(how, set, oldset) uv__pthread_sigmask(how, set, oldset) 71 | 72 | #endif /* GOOGLE_BREAKPAD_COMMON_ANDROID_TESTING_PTHREAD_FIXES_H */ 73 | -------------------------------------------------------------------------------- /test/test-timer-from-check.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | static uv_prepare_t prepare_handle; 26 | static uv_check_t check_handle; 27 | static uv_timer_t timer_handle; 28 | 29 | static int prepare_cb_called; 30 | static int check_cb_called; 31 | static int timer_cb_called; 32 | 33 | 34 | static void prepare_cb(uv_prepare_t* handle) { 35 | ASSERT(0 == uv_prepare_stop(&prepare_handle)); 36 | ASSERT(0 == prepare_cb_called); 37 | ASSERT(1 == check_cb_called); 38 | ASSERT(0 == timer_cb_called); 39 | prepare_cb_called++; 40 | } 41 | 42 | 43 | static void timer_cb(uv_timer_t* handle) { 44 | ASSERT(0 == uv_timer_stop(&timer_handle)); 45 | ASSERT(1 == prepare_cb_called); 46 | ASSERT(1 == check_cb_called); 47 | ASSERT(0 == timer_cb_called); 48 | timer_cb_called++; 49 | } 50 | 51 | 52 | static void check_cb(uv_check_t* handle) { 53 | ASSERT(0 == uv_check_stop(&check_handle)); 54 | ASSERT(0 == uv_timer_stop(&timer_handle)); /* Runs before timer_cb. */ 55 | ASSERT(0 == uv_timer_start(&timer_handle, timer_cb, 50, 0)); 56 | ASSERT(0 == uv_prepare_start(&prepare_handle, prepare_cb)); 57 | ASSERT(0 == prepare_cb_called); 58 | ASSERT(0 == check_cb_called); 59 | ASSERT(0 == timer_cb_called); 60 | check_cb_called++; 61 | } 62 | 63 | 64 | TEST_IMPL(timer_from_check) { 65 | ASSERT(0 == uv_prepare_init(uv_default_loop(), &prepare_handle)); 66 | ASSERT(0 == uv_check_init(uv_default_loop(), &check_handle)); 67 | ASSERT(0 == uv_check_start(&check_handle, check_cb)); 68 | ASSERT(0 == uv_timer_init(uv_default_loop(), &timer_handle)); 69 | ASSERT(0 == uv_timer_start(&timer_handle, timer_cb, 50, 0)); 70 | ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT)); 71 | ASSERT(1 == prepare_cb_called); 72 | ASSERT(1 == check_cb_called); 73 | ASSERT(1 == timer_cb_called); 74 | uv_close((uv_handle_t*) &prepare_handle, NULL); 75 | uv_close((uv_handle_t*) &check_handle, NULL); 76 | uv_close((uv_handle_t*) &timer_handle, NULL); 77 | ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_ONCE)); 78 | MAKE_VALGRIND_HAPPY(); 79 | return 0; 80 | } 81 | -------------------------------------------------------------------------------- /src/unix/proctitle.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * Permission is hereby granted, free of charge, to any person obtaining a copy 3 | * of this software and associated documentation files (the "Software"), to 4 | * deal in the Software without restriction, including without limitation the 5 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 6 | * sell copies of the Software, and to permit persons to whom the Software is 7 | * furnished to do so, subject to the following conditions: 8 | * 9 | * The above copyright notice and this permission notice shall be included in 10 | * all copies or substantial portions of the Software. 11 | * 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 18 | * IN THE SOFTWARE. 19 | */ 20 | 21 | #include "uv.h" 22 | #include "internal.h" 23 | 24 | #include 25 | #include 26 | 27 | extern void uv__set_process_title(const char* title); 28 | 29 | static void* args_mem; 30 | 31 | static struct { 32 | char* str; 33 | size_t len; 34 | } process_title; 35 | 36 | 37 | char** uv_setup_args(int argc, char** argv) { 38 | char** new_argv; 39 | size_t size; 40 | char* s; 41 | int i; 42 | 43 | if (argc <= 0) 44 | return argv; 45 | 46 | /* Calculate how much memory we need for the argv strings. */ 47 | size = 0; 48 | for (i = 0; i < argc; i++) 49 | size += strlen(argv[i]) + 1; 50 | 51 | process_title.str = argv[0]; 52 | process_title.len = argv[argc - 1] + strlen(argv[argc - 1]) - argv[0]; 53 | assert(process_title.len + 1 == size); /* argv memory should be adjacent. */ 54 | 55 | /* Add space for the argv pointers. */ 56 | size += (argc + 1) * sizeof(char*); 57 | 58 | new_argv = malloc(size); 59 | if (new_argv == NULL) 60 | return argv; 61 | args_mem = new_argv; 62 | 63 | /* Copy over the strings and set up the pointer table. */ 64 | s = (char*) &new_argv[argc + 1]; 65 | for (i = 0; i < argc; i++) { 66 | size = strlen(argv[i]) + 1; 67 | memcpy(s, argv[i], size); 68 | new_argv[i] = s; 69 | s += size; 70 | } 71 | new_argv[i] = NULL; 72 | 73 | return new_argv; 74 | } 75 | 76 | 77 | int uv_set_process_title(const char* title) { 78 | if (process_title.len == 0) 79 | return 0; 80 | 81 | /* No need to terminate, byte after is always '\0'. */ 82 | strncpy(process_title.str, title, process_title.len); 83 | uv__set_process_title(title); 84 | 85 | return 0; 86 | } 87 | 88 | 89 | int uv_get_process_title(char* buffer, size_t size) { 90 | if (process_title.len > 0) 91 | strncpy(buffer, process_title.str, size); 92 | else if (size > 0) 93 | buffer[0] = '\0'; 94 | 95 | return 0; 96 | } 97 | 98 | 99 | UV_DESTRUCTOR(static void free_args_mem(void)) { 100 | free(args_mem); /* Keep valgrind happy. */ 101 | args_mem = NULL; 102 | } 103 | -------------------------------------------------------------------------------- /test/test-tcp-connect-error-after-write.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | static int connect_cb_called; 30 | static int write_cb_called; 31 | static int close_cb_called; 32 | 33 | 34 | static void close_cb(uv_handle_t* handle) { 35 | close_cb_called++; 36 | } 37 | 38 | 39 | static void connect_cb(uv_connect_t* req, int status) { 40 | ASSERT(status < 0); 41 | connect_cb_called++; 42 | uv_close((uv_handle_t*)req->handle, close_cb); 43 | } 44 | 45 | 46 | static void write_cb(uv_write_t* req, int status) { 47 | ASSERT(status < 0); 48 | write_cb_called++; 49 | } 50 | 51 | 52 | /* 53 | * Try to connect to an address on which nothing listens, get ECONNREFUSED 54 | * (uv errno 12) and get connect_cb() called once with status != 0. 55 | * Related issue: https://github.com/joyent/libuv/issues/443 56 | */ 57 | TEST_IMPL(tcp_connect_error_after_write) { 58 | uv_connect_t connect_req; 59 | struct sockaddr_in addr; 60 | uv_write_t write_req; 61 | uv_tcp_t conn; 62 | uv_buf_t buf; 63 | int r; 64 | 65 | #ifdef _WIN32 66 | fprintf(stderr, "This test is disabled on Windows for now.\n"); 67 | fprintf(stderr, "See https://github.com/joyent/libuv/issues/444\n"); 68 | return 0; /* windows slackers... */ 69 | #endif 70 | 71 | ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr)); 72 | buf = uv_buf_init("TEST", 4); 73 | 74 | r = uv_tcp_init(uv_default_loop(), &conn); 75 | ASSERT(r == 0); 76 | 77 | r = uv_write(&write_req, (uv_stream_t*)&conn, &buf, 1, write_cb); 78 | ASSERT(r == UV_EBADF); 79 | 80 | r = uv_tcp_connect(&connect_req, 81 | &conn, 82 | (const struct sockaddr*) &addr, 83 | connect_cb); 84 | ASSERT(r == 0); 85 | 86 | r = uv_write(&write_req, (uv_stream_t*)&conn, &buf, 1, write_cb); 87 | ASSERT(r == 0); 88 | 89 | r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); 90 | ASSERT(r == 0); 91 | 92 | ASSERT(connect_cb_called == 1); 93 | ASSERT(write_cb_called == 1); 94 | ASSERT(close_cb_called == 1); 95 | 96 | MAKE_VALGRIND_HAPPY(); 97 | return 0; 98 | } 99 | -------------------------------------------------------------------------------- /test/test-udp-multicast-interface.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #define CHECK_HANDLE(handle) \ 30 | ASSERT((uv_udp_t*)(handle) == &server || (uv_udp_t*)(handle) == &client) 31 | 32 | static uv_udp_t server; 33 | static uv_udp_t client; 34 | 35 | static int sv_send_cb_called; 36 | static int close_cb_called; 37 | 38 | 39 | static void close_cb(uv_handle_t* handle) { 40 | CHECK_HANDLE(handle); 41 | close_cb_called++; 42 | } 43 | 44 | 45 | static void sv_send_cb(uv_udp_send_t* req, int status) { 46 | ASSERT(req != NULL); 47 | ASSERT(status == 0); 48 | CHECK_HANDLE(req->handle); 49 | 50 | sv_send_cb_called++; 51 | 52 | uv_close((uv_handle_t*) req->handle, close_cb); 53 | } 54 | 55 | 56 | TEST_IMPL(udp_multicast_interface) { 57 | int r; 58 | uv_udp_send_t req; 59 | uv_buf_t buf; 60 | struct sockaddr_in addr; 61 | struct sockaddr_in baddr; 62 | 63 | ASSERT(0 == uv_ip4_addr("239.255.0.1", TEST_PORT, &addr)); 64 | 65 | r = uv_udp_init(uv_default_loop(), &server); 66 | ASSERT(r == 0); 67 | 68 | ASSERT(0 == uv_ip4_addr("0.0.0.0", 0, &baddr)); 69 | r = uv_udp_bind(&server, (const struct sockaddr*)&baddr, 0); 70 | ASSERT(r == 0); 71 | 72 | r = uv_udp_set_multicast_interface(&server, "0.0.0.0"); 73 | ASSERT(r == 0); 74 | 75 | /* server sends "PING" */ 76 | buf = uv_buf_init("PING", 4); 77 | r = uv_udp_send(&req, 78 | &server, 79 | &buf, 80 | 1, 81 | (const struct sockaddr*)&addr, 82 | sv_send_cb); 83 | ASSERT(r == 0); 84 | 85 | ASSERT(close_cb_called == 0); 86 | ASSERT(sv_send_cb_called == 0); 87 | 88 | /* run the loop till all events are processed */ 89 | uv_run(uv_default_loop(), UV_RUN_DEFAULT); 90 | 91 | ASSERT(sv_send_cb_called == 1); 92 | ASSERT(close_cb_called == 1); 93 | 94 | ASSERT(client.send_queue_size == 0); 95 | ASSERT(server.send_queue_size == 0); 96 | 97 | MAKE_VALGRIND_HAPPY(); 98 | return 0; 99 | } 100 | -------------------------------------------------------------------------------- /test/test-udp-multicast-interface6.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #define CHECK_HANDLE(handle) \ 30 | ASSERT((uv_udp_t*)(handle) == &server || (uv_udp_t*)(handle) == &client) 31 | 32 | static uv_udp_t server; 33 | static uv_udp_t client; 34 | 35 | static int sv_send_cb_called; 36 | static int close_cb_called; 37 | 38 | 39 | static void close_cb(uv_handle_t* handle) { 40 | CHECK_HANDLE(handle); 41 | close_cb_called++; 42 | } 43 | 44 | 45 | static void sv_send_cb(uv_udp_send_t* req, int status) { 46 | ASSERT(req != NULL); 47 | ASSERT(status == 0); 48 | CHECK_HANDLE(req->handle); 49 | 50 | sv_send_cb_called++; 51 | 52 | uv_close((uv_handle_t*) req->handle, close_cb); 53 | } 54 | 55 | 56 | TEST_IMPL(udp_multicast_interface6) { 57 | int r; 58 | uv_udp_send_t req; 59 | uv_buf_t buf; 60 | struct sockaddr_in6 addr; 61 | struct sockaddr_in6 baddr; 62 | 63 | ASSERT(0 == uv_ip6_addr("::1", TEST_PORT, &addr)); 64 | 65 | r = uv_udp_init(uv_default_loop(), &server); 66 | ASSERT(r == 0); 67 | 68 | ASSERT(0 == uv_ip6_addr("::", 0, &baddr)); 69 | r = uv_udp_bind(&server, (const struct sockaddr*)&baddr, 0); 70 | ASSERT(r == 0); 71 | 72 | #if defined(__APPLE__) 73 | r = uv_udp_set_multicast_interface(&server, "::1%lo0"); 74 | #else 75 | r = uv_udp_set_multicast_interface(&server, NULL); 76 | #endif 77 | ASSERT(r == 0); 78 | 79 | /* server sends "PING" */ 80 | buf = uv_buf_init("PING", 4); 81 | r = uv_udp_send(&req, 82 | &server, 83 | &buf, 84 | 1, 85 | (const struct sockaddr*)&addr, 86 | sv_send_cb); 87 | ASSERT(r == 0); 88 | 89 | ASSERT(close_cb_called == 0); 90 | ASSERT(sv_send_cb_called == 0); 91 | 92 | /* run the loop till all events are processed */ 93 | uv_run(uv_default_loop(), UV_RUN_DEFAULT); 94 | 95 | ASSERT(sv_send_cb_called == 1); 96 | ASSERT(close_cb_called == 1); 97 | 98 | MAKE_VALGRIND_HAPPY(); 99 | return 0; 100 | } 101 | -------------------------------------------------------------------------------- /src/win/async.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include 23 | 24 | #include "uv.h" 25 | #include "internal.h" 26 | #include "atomicops-inl.h" 27 | #include "handle-inl.h" 28 | #include "req-inl.h" 29 | 30 | 31 | void uv_async_endgame(uv_loop_t* loop, uv_async_t* handle) { 32 | if (handle->flags & UV__HANDLE_CLOSING && 33 | !handle->async_sent) { 34 | assert(!(handle->flags & UV_HANDLE_CLOSED)); 35 | uv__handle_close(handle); 36 | } 37 | } 38 | 39 | 40 | int uv_async_init(uv_loop_t* loop, uv_async_t* handle, uv_async_cb async_cb) { 41 | uv_req_t* req; 42 | 43 | uv__handle_init(loop, (uv_handle_t*) handle, UV_ASYNC); 44 | handle->async_sent = 0; 45 | handle->async_cb = async_cb; 46 | 47 | req = &handle->async_req; 48 | uv_req_init(loop, req); 49 | req->type = UV_WAKEUP; 50 | req->data = handle; 51 | 52 | uv__handle_start(handle); 53 | 54 | return 0; 55 | } 56 | 57 | 58 | void uv_async_close(uv_loop_t* loop, uv_async_t* handle) { 59 | if (!((uv_async_t*)handle)->async_sent) { 60 | uv_want_endgame(loop, (uv_handle_t*) handle); 61 | } 62 | 63 | uv__handle_closing(handle); 64 | } 65 | 66 | 67 | int uv_async_send(uv_async_t* handle) { 68 | uv_loop_t* loop = handle->loop; 69 | 70 | if (handle->type != UV_ASYNC) { 71 | /* Can't set errno because that's not thread-safe. */ 72 | return -1; 73 | } 74 | 75 | /* The user should make sure never to call uv_async_send to a closing */ 76 | /* or closed handle. */ 77 | assert(!(handle->flags & UV__HANDLE_CLOSING)); 78 | 79 | if (!uv__atomic_exchange_set(&handle->async_sent)) { 80 | POST_COMPLETION_FOR_REQ(loop, &handle->async_req); 81 | } 82 | 83 | return 0; 84 | } 85 | 86 | 87 | void uv_process_async_wakeup_req(uv_loop_t* loop, uv_async_t* handle, 88 | uv_req_t* req) { 89 | assert(handle->type == UV_ASYNC); 90 | assert(req->type == UV_WAKEUP); 91 | 92 | handle->async_sent = 0; 93 | 94 | if (handle->flags & UV__HANDLE_CLOSING) { 95 | uv_want_endgame(loop, (uv_handle_t*)handle); 96 | } else if (handle->async_cb != NULL) { 97 | handle->async_cb(handle); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /samples/socks5-proxy/main.c: -------------------------------------------------------------------------------- 1 | /* Copyright StrongLoop, Inc. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "defs.h" 23 | #include 24 | #include 25 | #include 26 | 27 | #if HAVE_UNISTD_H 28 | #include /* getopt */ 29 | #endif 30 | 31 | #define DEFAULT_BIND_HOST "127.0.0.1" 32 | #define DEFAULT_BIND_PORT 1080 33 | #define DEFAULT_IDLE_TIMEOUT (60 * 1000) 34 | 35 | static void parse_opts(server_config *cf, int argc, char **argv); 36 | static void usage(void); 37 | 38 | static const char *progname = __FILE__; /* Reset in main(). */ 39 | 40 | int main(int argc, char **argv) { 41 | server_config config; 42 | int err; 43 | 44 | progname = argv[0]; 45 | memset(&config, 0, sizeof(config)); 46 | config.bind_host = DEFAULT_BIND_HOST; 47 | config.bind_port = DEFAULT_BIND_PORT; 48 | config.idle_timeout = DEFAULT_IDLE_TIMEOUT; 49 | parse_opts(&config, argc, argv); 50 | 51 | err = server_run(&config, uv_default_loop()); 52 | if (err) { 53 | exit(1); 54 | } 55 | 56 | return 0; 57 | } 58 | 59 | const char *_getprogname(void) { 60 | return progname; 61 | } 62 | 63 | static void parse_opts(server_config *cf, int argc, char **argv) { 64 | int opt; 65 | 66 | while (-1 != (opt = getopt(argc, argv, "H:hp:"))) { 67 | switch (opt) { 68 | case 'H': 69 | cf->bind_host = optarg; 70 | break; 71 | 72 | case 'p': 73 | if (1 != sscanf(optarg, "%hu", &cf->bind_port)) { 74 | pr_err("bad port number: %s", optarg); 75 | usage(); 76 | } 77 | break; 78 | 79 | default: 80 | usage(); 81 | } 82 | } 83 | } 84 | 85 | static void usage(void) { 86 | printf("Usage:\n" 87 | "\n" 88 | " %s [-b
[-h] [-p ]\n" 89 | "\n" 90 | "Options:\n" 91 | "\n" 92 | " -b Bind to this address or hostname.\n" 93 | " Default: \"127.0.0.1\"\n" 94 | " -h Show this help message.\n" 95 | " -p Bind to this port number. Default: 1080\n" 96 | "", 97 | progname); 98 | exit(1); 99 | } 100 | -------------------------------------------------------------------------------- /test/test-barrier.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | #include 26 | #include 27 | 28 | typedef struct { 29 | uv_barrier_t barrier; 30 | int delay; 31 | volatile int posted; 32 | int main_barrier_wait_rval; 33 | int worker_barrier_wait_rval; 34 | } worker_config; 35 | 36 | 37 | static void worker(void* arg) { 38 | worker_config* c = arg; 39 | 40 | if (c->delay) 41 | uv_sleep(c->delay); 42 | 43 | c->worker_barrier_wait_rval = uv_barrier_wait(&c->barrier); 44 | } 45 | 46 | 47 | TEST_IMPL(barrier_1) { 48 | uv_thread_t thread; 49 | worker_config wc; 50 | 51 | memset(&wc, 0, sizeof(wc)); 52 | 53 | ASSERT(0 == uv_barrier_init(&wc.barrier, 2)); 54 | ASSERT(0 == uv_thread_create(&thread, worker, &wc)); 55 | 56 | uv_sleep(100); 57 | wc.main_barrier_wait_rval = uv_barrier_wait(&wc.barrier); 58 | 59 | ASSERT(0 == uv_thread_join(&thread)); 60 | uv_barrier_destroy(&wc.barrier); 61 | 62 | ASSERT(1 == (wc.main_barrier_wait_rval ^ wc.worker_barrier_wait_rval)); 63 | 64 | return 0; 65 | } 66 | 67 | 68 | TEST_IMPL(barrier_2) { 69 | uv_thread_t thread; 70 | worker_config wc; 71 | 72 | memset(&wc, 0, sizeof(wc)); 73 | wc.delay = 100; 74 | 75 | ASSERT(0 == uv_barrier_init(&wc.barrier, 2)); 76 | ASSERT(0 == uv_thread_create(&thread, worker, &wc)); 77 | 78 | wc.main_barrier_wait_rval = uv_barrier_wait(&wc.barrier); 79 | 80 | ASSERT(0 == uv_thread_join(&thread)); 81 | uv_barrier_destroy(&wc.barrier); 82 | 83 | ASSERT(1 == (wc.main_barrier_wait_rval ^ wc.worker_barrier_wait_rval)); 84 | 85 | return 0; 86 | } 87 | 88 | 89 | TEST_IMPL(barrier_3) { 90 | uv_thread_t thread; 91 | worker_config wc; 92 | 93 | memset(&wc, 0, sizeof(wc)); 94 | 95 | ASSERT(0 == uv_barrier_init(&wc.barrier, 2)); 96 | ASSERT(0 == uv_thread_create(&thread, worker, &wc)); 97 | 98 | wc.main_barrier_wait_rval = uv_barrier_wait(&wc.barrier); 99 | 100 | ASSERT(0 == uv_thread_join(&thread)); 101 | uv_barrier_destroy(&wc.barrier); 102 | 103 | ASSERT(1 == (wc.main_barrier_wait_rval ^ wc.worker_barrier_wait_rval)); 104 | 105 | return 0; 106 | } 107 | -------------------------------------------------------------------------------- /include/uv-darwin.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UV_DARWIN_H 23 | #define UV_DARWIN_H 24 | 25 | #if defined(__APPLE__) && defined(__MACH__) 26 | # include 27 | # include 28 | # include 29 | # include 30 | # define UV_PLATFORM_SEM_T semaphore_t 31 | #endif 32 | 33 | #define UV_IO_PRIVATE_PLATFORM_FIELDS \ 34 | int rcount; \ 35 | int wcount; \ 36 | 37 | #define UV_PLATFORM_LOOP_FIELDS \ 38 | uv_thread_t cf_thread; \ 39 | void* _cf_reserved; \ 40 | void* cf_state; \ 41 | uv_mutex_t cf_mutex; \ 42 | uv_sem_t cf_sem; \ 43 | void* cf_signals[2]; \ 44 | 45 | #define UV_PLATFORM_FS_EVENT_FIELDS \ 46 | uv__io_t event_watcher; \ 47 | char* realpath; \ 48 | int realpath_len; \ 49 | int cf_flags; \ 50 | uv_async_t* cf_cb; \ 51 | void* cf_events[2]; \ 52 | void* cf_member[2]; \ 53 | int cf_error; \ 54 | uv_mutex_t cf_mutex; \ 55 | 56 | #define UV_STREAM_PRIVATE_PLATFORM_FIELDS \ 57 | void* select; \ 58 | 59 | #define UV_HAVE_KQUEUE 1 60 | 61 | #endif /* UV_DARWIN_H */ 62 | -------------------------------------------------------------------------------- /samples/socks5-proxy/s5.h: -------------------------------------------------------------------------------- 1 | /* Copyright StrongLoop, Inc. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef S5_H_ 23 | #define S5_H_ 24 | 25 | #include 26 | #include 27 | 28 | #define S5_ERR_MAP(V) \ 29 | V(-1, bad_version, "Bad protocol version.") \ 30 | V(-2, bad_cmd, "Bad protocol command.") \ 31 | V(-3, bad_atyp, "Bad address type.") \ 32 | V(0, ok, "No error.") \ 33 | V(1, auth_select, "Select authentication method.") \ 34 | V(2, auth_verify, "Verify authentication.") \ 35 | V(3, exec_cmd, "Execute command.") \ 36 | 37 | typedef enum { 38 | #define S5_ERR_GEN(code, name, _) s5_ ## name = code, 39 | S5_ERR_MAP(S5_ERR_GEN) 40 | #undef S5_ERR_GEN 41 | s5_max_errors 42 | } s5_err; 43 | 44 | typedef enum { 45 | S5_AUTH_NONE = 1 << 0, 46 | S5_AUTH_GSSAPI = 1 << 1, 47 | S5_AUTH_PASSWD = 1 << 2 48 | } s5_auth_method; 49 | 50 | typedef enum { 51 | s5_auth_allow, 52 | s5_auth_deny 53 | } s5_auth_result; 54 | 55 | typedef enum { 56 | s5_atyp_ipv4, 57 | s5_atyp_ipv6, 58 | s5_atyp_host 59 | } s5_atyp; 60 | 61 | typedef enum { 62 | s5_cmd_tcp_connect, 63 | s5_cmd_tcp_bind, 64 | s5_cmd_udp_assoc 65 | } s5_cmd; 66 | 67 | typedef struct { 68 | uint32_t arg0; /* Scratch space for the state machine. */ 69 | uint32_t arg1; /* Scratch space for the state machine. */ 70 | uint8_t state; 71 | uint8_t methods; 72 | uint8_t cmd; 73 | uint8_t atyp; 74 | uint8_t userlen; 75 | uint8_t passlen; 76 | uint16_t dport; 77 | uint8_t username[257]; 78 | uint8_t password[257]; 79 | uint8_t daddr[257]; /* TODO(bnoordhuis) Merge with username/password. */ 80 | } s5_ctx; 81 | 82 | void s5_init(s5_ctx *ctx); 83 | 84 | s5_err s5_parse(s5_ctx *cx, uint8_t **data, size_t *size); 85 | 86 | /* Only call after s5_parse() has returned s5_want_auth_method. */ 87 | unsigned int s5_auth_methods(const s5_ctx *cx); 88 | 89 | /* Call after s5_parse() has returned s5_want_auth_method. */ 90 | int s5_select_auth(s5_ctx *cx, s5_auth_method method); 91 | 92 | const char *s5_strerror(s5_err err); 93 | 94 | #endif /* S5_H_ */ 95 | -------------------------------------------------------------------------------- /test/test-semaphore.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "task.h" 24 | 25 | #include 26 | #include 27 | 28 | typedef struct { 29 | uv_mutex_t mutex; 30 | uv_sem_t sem; 31 | int delay; 32 | volatile int posted; 33 | } worker_config; 34 | 35 | 36 | static void worker(void* arg) { 37 | worker_config* c = arg; 38 | 39 | if (c->delay) 40 | uv_sleep(c->delay); 41 | 42 | uv_mutex_lock(&c->mutex); 43 | ASSERT(c->posted == 0); 44 | uv_sem_post(&c->sem); 45 | c->posted = 1; 46 | uv_mutex_unlock(&c->mutex); 47 | } 48 | 49 | 50 | TEST_IMPL(semaphore_1) { 51 | uv_thread_t thread; 52 | worker_config wc; 53 | 54 | memset(&wc, 0, sizeof(wc)); 55 | 56 | ASSERT(0 == uv_sem_init(&wc.sem, 0)); 57 | ASSERT(0 == uv_mutex_init(&wc.mutex)); 58 | ASSERT(0 == uv_thread_create(&thread, worker, &wc)); 59 | 60 | uv_sleep(100); 61 | uv_mutex_lock(&wc.mutex); 62 | ASSERT(wc.posted == 1); 63 | uv_sem_wait(&wc.sem); /* should not block */ 64 | uv_mutex_unlock(&wc.mutex); /* ergo, it should be ok to unlock after wait */ 65 | 66 | ASSERT(0 == uv_thread_join(&thread)); 67 | uv_mutex_destroy(&wc.mutex); 68 | uv_sem_destroy(&wc.sem); 69 | 70 | return 0; 71 | } 72 | 73 | 74 | TEST_IMPL(semaphore_2) { 75 | uv_thread_t thread; 76 | worker_config wc; 77 | 78 | memset(&wc, 0, sizeof(wc)); 79 | wc.delay = 100; 80 | 81 | ASSERT(0 == uv_sem_init(&wc.sem, 0)); 82 | ASSERT(0 == uv_mutex_init(&wc.mutex)); 83 | ASSERT(0 == uv_thread_create(&thread, worker, &wc)); 84 | 85 | uv_sem_wait(&wc.sem); 86 | 87 | ASSERT(0 == uv_thread_join(&thread)); 88 | uv_mutex_destroy(&wc.mutex); 89 | uv_sem_destroy(&wc.sem); 90 | 91 | return 0; 92 | } 93 | 94 | 95 | TEST_IMPL(semaphore_3) { 96 | uv_sem_t sem; 97 | 98 | ASSERT(0 == uv_sem_init(&sem, 3)); 99 | uv_sem_wait(&sem); /* should not block */ 100 | uv_sem_wait(&sem); /* should not block */ 101 | ASSERT(0 == uv_sem_trywait(&sem)); 102 | ASSERT(UV_EAGAIN == uv_sem_trywait(&sem)); 103 | 104 | uv_sem_post(&sem); 105 | ASSERT(0 == uv_sem_trywait(&sem)); 106 | ASSERT(UV_EAGAIN == uv_sem_trywait(&sem)); 107 | 108 | uv_sem_destroy(&sem); 109 | 110 | return 0; 111 | } 112 | --------------------------------------------------------------------------------