├── Makefile ├── README.md ├── libuv ├── .gitignore ├── .mailmap ├── AUTHORS ├── CONTRIBUTING.md ├── ChangeLog ├── LICENSE ├── Makefile.am ├── Makefile.mingw ├── README.md ├── android-configure ├── autogen.sh ├── checksparse.sh ├── common.gypi ├── configure.ac ├── docs │ ├── make.bat │ └── src │ │ ├── async.rst │ │ ├── check.rst │ │ ├── conf.py │ │ ├── design.rst │ │ ├── dll.rst │ │ ├── dns.rst │ │ ├── errors.rst │ │ ├── fs.rst │ │ ├── fs_event.rst │ │ ├── fs_poll.rst │ │ ├── handle.rst │ │ ├── idle.rst │ │ ├── index.rst │ │ ├── loop.rst │ │ ├── migration_010_100.rst │ │ ├── misc.rst │ │ ├── pipe.rst │ │ ├── poll.rst │ │ ├── prepare.rst │ │ ├── process.rst │ │ ├── request.rst │ │ ├── signal.rst │ │ ├── static │ │ ├── architecture.png │ │ ├── diagrams.key │ │ │ ├── Data │ │ │ │ ├── st0-311.jpg │ │ │ │ └── st1-475.jpg │ │ │ ├── Index.zip │ │ │ ├── Metadata │ │ │ │ ├── BuildVersionHistory.plist │ │ │ │ ├── DocumentIdentifier │ │ │ │ └── Properties.plist │ │ │ ├── preview-micro.jpg │ │ │ ├── preview-web.jpg │ │ │ └── preview.jpg │ │ ├── favicon.ico │ │ ├── logo.png │ │ └── loop_iteration.png │ │ ├── stream.rst │ │ ├── tcp.rst │ │ ├── threading.rst │ │ ├── threadpool.rst │ │ ├── timer.rst │ │ ├── tty.rst │ │ └── udp.rst ├── gyp_uv.py ├── img │ ├── banner.png │ └── logos.svg ├── include │ ├── android-ifaddrs.h │ ├── pthread-fixes.h │ ├── stdint-msvc2008.h │ ├── tree.h │ ├── uv-aix.h │ ├── uv-bsd.h │ ├── uv-darwin.h │ ├── uv-errno.h │ ├── uv-linux.h │ ├── uv-sunos.h │ ├── uv-threadpool.h │ ├── uv-unix.h │ ├── uv-version.h │ ├── uv-win.h │ └── uv.h ├── libuv.pc.in ├── m4 │ ├── .gitignore │ ├── as_case.m4 │ └── libuv-check-flags.m4 ├── samples │ ├── .gitignore │ └── socks5-proxy │ │ ├── .gitignore │ │ ├── LICENSE │ │ ├── build.gyp │ │ ├── client.c │ │ ├── defs.h │ │ ├── getopt.c │ │ ├── main.c │ │ ├── s5.c │ │ ├── s5.h │ │ ├── server.c │ │ └── util.c ├── src │ ├── fs-poll.c │ ├── heap-inl.h │ ├── inet.c │ ├── queue.h │ ├── threadpool.c │ ├── unix │ │ ├── aix.c │ │ ├── android-ifaddrs.c │ │ ├── async.c │ │ ├── atomic-ops.h │ │ ├── core.c │ │ ├── darwin-proctitle.c │ │ ├── darwin.c │ │ ├── dl.c │ │ ├── freebsd.c │ │ ├── fs.c │ │ ├── fsevents.c │ │ ├── getaddrinfo.c │ │ ├── getnameinfo.c │ │ ├── internal.h │ │ ├── kqueue.c │ │ ├── linux-core.c │ │ ├── linux-inotify.c │ │ ├── linux-syscalls.c │ │ ├── linux-syscalls.h │ │ ├── loop-watcher.c │ │ ├── loop.c │ │ ├── netbsd.c │ │ ├── openbsd.c │ │ ├── pipe.c │ │ ├── poll.c │ │ ├── process.c │ │ ├── proctitle.c │ │ ├── pthread-fixes.c │ │ ├── signal.c │ │ ├── spinlock.h │ │ ├── stream.c │ │ ├── sunos.c │ │ ├── tcp.c │ │ ├── thread.c │ │ ├── timer.c │ │ ├── tty.c │ │ └── udp.c │ ├── uv-common.c │ ├── uv-common.h │ ├── version.c │ └── win │ │ ├── async.c │ │ ├── atomicops-inl.h │ │ ├── core.c │ │ ├── dl.c │ │ ├── error.c │ │ ├── fs-event.c │ │ ├── fs.c │ │ ├── getaddrinfo.c │ │ ├── getnameinfo.c │ │ ├── handle-inl.h │ │ ├── handle.c │ │ ├── internal.h │ │ ├── loop-watcher.c │ │ ├── pipe.c │ │ ├── poll.c │ │ ├── process-stdio.c │ │ ├── process.c │ │ ├── req-inl.h │ │ ├── req.c │ │ ├── signal.c │ │ ├── stream-inl.h │ │ ├── stream.c │ │ ├── tcp.c │ │ ├── thread.c │ │ ├── timer.c │ │ ├── tty.c │ │ ├── udp.c │ │ ├── util.c │ │ ├── winapi.c │ │ ├── winapi.h │ │ ├── winsock.c │ │ └── winsock.h ├── test │ ├── benchmark-async-pummel.c │ ├── benchmark-async.c │ ├── benchmark-fs-stat.c │ ├── benchmark-getaddrinfo.c │ ├── benchmark-list.h │ ├── benchmark-loop-count.c │ ├── benchmark-million-async.c │ ├── benchmark-million-timers.c │ ├── benchmark-multi-accept.c │ ├── benchmark-ping-pongs.c │ ├── benchmark-pound.c │ ├── benchmark-pump.c │ ├── benchmark-sizes.c │ ├── benchmark-spawn.c │ ├── benchmark-tcp-write-batch.c │ ├── benchmark-thread.c │ ├── benchmark-udp-pummel.c │ ├── blackhole-server.c │ ├── dns-server.c │ ├── echo-server.c │ ├── fixtures │ │ ├── empty_file │ │ └── load_error.node │ ├── run-benchmarks.c │ ├── run-tests.c │ ├── runner-unix.c │ ├── runner-unix.h │ ├── runner-win.c │ ├── runner-win.h │ ├── runner.c │ ├── runner.h │ ├── task.h │ ├── test-active.c │ ├── test-async-null-cb.c │ ├── test-async.c │ ├── test-barrier.c │ ├── test-callback-order.c │ ├── test-callback-stack.c │ ├── test-close-fd.c │ ├── test-close-order.c │ ├── test-condvar.c │ ├── test-connection-fail.c │ ├── test-cwd-and-chdir.c │ ├── test-default-loop-close.c │ ├── test-delayed-accept.c │ ├── test-dlerror.c │ ├── test-embed.c │ ├── test-emfile.c │ ├── test-error.c │ ├── test-fail-always.c │ ├── test-fs-event.c │ ├── test-fs-poll.c │ ├── test-fs.c │ ├── test-get-currentexe.c │ ├── test-get-loadavg.c │ ├── test-get-memory.c │ ├── test-getaddrinfo.c │ ├── test-getnameinfo.c │ ├── test-getsockname.c │ ├── test-handle-fileno.c │ ├── test-hrtime.c │ ├── test-idle.c │ ├── test-ip4-addr.c │ ├── test-ip6-addr.c │ ├── test-ipc-send-recv.c │ ├── test-ipc.c │ ├── test-list.h │ ├── test-loop-alive.c │ ├── test-loop-close.c │ ├── test-loop-configure.c │ ├── test-loop-handles.c │ ├── test-loop-stop.c │ ├── test-loop-time.c │ ├── test-multiple-listen.c │ ├── test-mutexes.c │ ├── test-osx-select.c │ ├── test-pass-always.c │ ├── test-ping-pong.c │ ├── test-pipe-bind-error.c │ ├── test-pipe-close-stdout-read-stdin.c │ ├── test-pipe-connect-error.c │ ├── test-pipe-getsockname.c │ ├── test-pipe-sendmsg.c │ ├── test-pipe-server-close.c │ ├── test-platform-output.c │ ├── test-poll-close-doesnt-corrupt-stack.c │ ├── test-poll-close.c │ ├── test-poll-closesocket.c │ ├── test-poll.c │ ├── test-process-title.c │ ├── test-ref.c │ ├── test-run-nowait.c │ ├── test-run-once.c │ ├── test-semaphore.c │ ├── test-shutdown-close.c │ ├── test-shutdown-eof.c │ ├── test-shutdown-twice.c │ ├── test-signal-multiple-loops.c │ ├── test-signal.c │ ├── test-socket-buffer-size.c │ ├── test-spawn.c │ ├── test-stdio-over-pipes.c │ ├── test-tcp-bind-error.c │ ├── test-tcp-bind6-error.c │ ├── test-tcp-close-accept.c │ ├── test-tcp-close-while-connecting.c │ ├── test-tcp-close.c │ ├── test-tcp-connect-error-after-write.c │ ├── test-tcp-connect-error.c │ ├── test-tcp-connect-timeout.c │ ├── test-tcp-connect6-error.c │ ├── test-tcp-flags.c │ ├── test-tcp-open.c │ ├── test-tcp-read-stop.c │ ├── test-tcp-shutdown-after-write.c │ ├── test-tcp-try-write.c │ ├── test-tcp-unexpected-read.c │ ├── test-tcp-write-after-connect.c │ ├── test-tcp-write-queue-order.c │ ├── test-tcp-write-to-half-open-connection.c │ ├── test-tcp-writealot.c │ ├── test-thread-equal.c │ ├── test-thread.c │ ├── test-threadpool-cancel.c │ ├── test-threadpool.c │ ├── test-timer-again.c │ ├── test-timer-from-check.c │ ├── test-timer.c │ ├── test-tty.c │ ├── test-udp-bind.c │ ├── test-udp-dgram-too-big.c │ ├── test-udp-ipv6.c │ ├── test-udp-multicast-interface.c │ ├── test-udp-multicast-interface6.c │ ├── test-udp-multicast-join.c │ ├── test-udp-multicast-join6.c │ ├── test-udp-multicast-ttl.c │ ├── test-udp-open.c │ ├── test-udp-options.c │ ├── test-udp-send-and-recv.c │ ├── test-udp-send-immediate.c │ ├── test-udp-send-unreachable.c │ ├── test-udp-try-send.c │ ├── test-walk-handles.c │ └── test-watcher-cross-stop.c ├── uv.gyp └── vcbuild.bat ├── prepend_licence.py ├── ssl_test.cnf ├── test_tls.c ├── test_tls_client.c ├── tls_engine.c ├── tls_engine.h ├── uv_tls.c └── uv_tls.h /Makefile: -------------------------------------------------------------------------------- 1 | all: echo tls_client gen_cert 2 | echo: test_tls.c 3 | cd libuv && python gyp_uv.py 4 | make -C ./libuv/out 5 | #clang -fsanitize=address -g -Wall -o echo test_tls.c tls_engine.c uv_tls.c libuv/out/Debug/libuv.a -lpthread -lssl -lcrypto 6 | clang -g -Wall -Wunused -o $@ tls_engine.c uv_tls.c test_tls.c \ 7 | libuv/out/Debug/libuv.a -ldl -lrt -lpthread -lssl -lcrypto 8 | 9 | tls_client: test_tls_client.c 10 | cd libuv && python gyp_uv.py 11 | make -C ./libuv/out 12 | clang -g -Wall -o $@ tls_engine.c uv_tls.c test_tls_client.c \ 13 | libuv/out/Debug/libuv.a -ldl -lrt -lpthread -lssl -lcrypto 14 | 15 | new: 16 | cd libuv && python gyp_uv.py 17 | make -C ./libuv/out 18 | clang -g -Wall -o $@ new.c evt_tls.c libuv/out/Debug/libuv.a -ldl -lrt -lpthread -lssl -lcrypto 19 | 20 | 21 | 22 | gen_cert: 23 | openssl req -x509 -newkey rsa:2048 -nodes -keyout server-key.pem -out server-cert.pem -config ssl_test.cnf 24 | 25 | clean: 26 | -rm echo 27 | -rm tls_client 28 | -rm new 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # THIS REPOSITORY HAS BEEN MARKED AS DEPRECATED, FOR UPDATED WORK, PLEASE REFER sample/libuv-tls IN 2 | https://github.com/deleisha/evt-tls 3 | # libuv-tls 4 | Add SSL/TLS functionality on top of libuv using OpenSSL. 5 | 6 | This small library adds SSL/TLS functionality using BIO pair on libuv. It tries to provide 7 | API similar to libuv with bare minimum change. Also it tries to use facilities provided by 8 | OpenSSL. Currently it scratches BIO pair only as a result. This might go away as we learn 9 | more and more both on OpenSSL and libuv. Writing our own custom BIO will lend lot more 10 | flexibility. 11 | 12 | We intend to provide the library as subpart of libuv, if we can finish soon. 13 | 14 | ### TODO: 15 | - Add session resumption feature - may be later version 16 | - Renegotiation not yet handled - may be later version 17 | - Work on supporting DTLS support - later versions 18 | - Work on building and packaging 19 | 20 | ### Usage and API 21 | libuv-tls have similar looking API as that of libuv. Any libuv users can easily used the API 22 | looking at the `uv_tls.h`. 23 | 24 | uv_tls.h have all the APIs and users including this header will still have access to all APIs 25 | being exported by uv.h 26 | 27 | As of now, libuv-tls does not hide any symbols. 28 | 29 | Sample usage can be seen at ```test_tls.c``` and ```test_tls_client.c``` 30 | 31 | 32 | ### TEST: 33 | To test the echo server, generate the test cert and key using 34 | 35 | ```make && ./echo``` 36 | 37 | Now the echo server is compiled and started and we can start sending some data using 38 | 39 | ```openssl s_client -connect address:8000 -nbio -state -msg -debug``` 40 | 41 | 42 | where address is your ip address. 43 | 44 | ### CONTRIBUTING 45 | Clone/fork the library and play around and provide feedback/patches or anything for improvement. 46 | -------------------------------------------------------------------------------- /libuv/.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 gyp for android 38 | *.target.mk 39 | 40 | /out/ 41 | /build/gyp 42 | 43 | /test/.libs/ 44 | /test/run-tests 45 | /test/run-tests.exe 46 | /test/run-tests.dSYM 47 | /test/run-benchmarks 48 | /test/run-benchmarks.exe 49 | /test/run-benchmarks.dSYM 50 | 51 | *.sln 52 | *.sln.cache 53 | *.ncb 54 | *.vcproj 55 | *.vcproj*.user 56 | *.vcxproj 57 | *.vcxproj.filters 58 | *.vcxproj.user 59 | _UpgradeReport_Files/ 60 | UpgradeLog*.XML 61 | Debug 62 | Release 63 | ipch 64 | 65 | # sphinx generated files 66 | /docs/build/ 67 | 68 | *.xcodeproj 69 | *.xcworkspace 70 | 71 | # make dist output 72 | libuv-*.tar.* 73 | -------------------------------------------------------------------------------- /libuv/.mailmap: -------------------------------------------------------------------------------- 1 | Aaron Bieber 2 | Alan Gutierrez 3 | Andrius Bentkus 4 | Bert Belder 5 | Bert Belder 6 | Brandon Philips 7 | Brian White 8 | Brian White 9 | Caleb James DeLisle 10 | Christoph Iserlohn 11 | Fedor Indutny 12 | Frank Denis 13 | Isaac Z. Schlueter 14 | Justin Venus 15 | Keno Fischer 16 | Keno Fischer 17 | Leonard Hecker 18 | Maciej Małecki 19 | Marc Schlaich 20 | Rasmus Christian Pedersen 21 | Rasmus Christian Pedersen 22 | Robert Mustacchi 23 | Ryan Dahl 24 | Ryan Emery 25 | Sam Roberts 26 | San-Tai Hsu 27 | Saúl Ibarra Corretgé 28 | Shigeki Ohtsu 29 | Timothy J. Fontaine 30 | Yasuhiro Matsumoto 31 | Yazhong Liu 32 | Yuki Okumura 33 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 v1.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 | -------------------------------------------------------------------------------- /libuv/docs/src/async.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _async: 3 | 4 | :c:type:`uv_async_t` --- Async handle 5 | ===================================== 6 | 7 | Async handles allow the user to "wakeup" the event loop and get a callback 8 | called from another thread. 9 | 10 | 11 | Data types 12 | ---------- 13 | 14 | .. c:type:: uv_async_t 15 | 16 | Async handle type. 17 | 18 | .. c:type:: void (*uv_async_cb)(uv_async_t* handle) 19 | 20 | Type definition for callback passed to :c:func:`uv_async_init`. 21 | 22 | 23 | Public members 24 | ^^^^^^^^^^^^^^ 25 | 26 | N/A 27 | 28 | .. seealso:: The :c:type:`uv_handle_t` members also apply. 29 | 30 | 31 | API 32 | --- 33 | 34 | .. c:function:: int uv_async_init(uv_loop_t* loop, uv_async_t* async, uv_async_cb async_cb) 35 | 36 | Initialize the handle. A NULL callback is allowed. 37 | 38 | .. note:: 39 | Unlike other handle initialization functions, it immediately starts the handle. 40 | 41 | .. c:function:: int uv_async_send(uv_async_t* async) 42 | 43 | Wakeup the event loop and call the async handle's callback. 44 | 45 | .. note:: 46 | It's safe to call this function from any thread. The callback will be called on the 47 | loop thread. 48 | 49 | .. warning:: 50 | libuv will coalesce calls to :c:func:`uv_async_send`, that is, not every call to it will 51 | yield an execution of the callback. For example: if :c:func:`uv_async_send` is called 5 52 | times in a row before the callback is called, the callback will only be called once. If 53 | :c:func:`uv_async_send` is called again after the callback was called, it will be called 54 | again. 55 | 56 | .. seealso:: 57 | The :c:type:`uv_handle_t` API functions also apply. 58 | -------------------------------------------------------------------------------- /libuv/docs/src/check.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _check: 3 | 4 | :c:type:`uv_check_t` --- Check handle 5 | ===================================== 6 | 7 | Check handles will run the given callback once per loop iteration, right 8 | after polling for i/o. 9 | 10 | 11 | Data types 12 | ---------- 13 | 14 | .. c:type:: uv_check_t 15 | 16 | Check handle type. 17 | 18 | .. c:type:: void (*uv_check_cb)(uv_check_t* handle) 19 | 20 | Type definition for callback passed to :c:func:`uv_check_start`. 21 | 22 | 23 | Public members 24 | ^^^^^^^^^^^^^^ 25 | 26 | N/A 27 | 28 | .. seealso:: The :c:type:`uv_handle_t` members also apply. 29 | 30 | 31 | API 32 | --- 33 | 34 | .. c:function:: int uv_check_init(uv_loop_t*, uv_check_t* check) 35 | 36 | Initialize the handle. 37 | 38 | .. c:function:: int uv_check_start(uv_check_t* check, uv_check_cb cb) 39 | 40 | Start the handle with the given callback. 41 | 42 | .. c:function:: int uv_check_stop(uv_check_t* check) 43 | 44 | Stop the handle, the callback will no longer be called. 45 | 46 | .. seealso:: The :c:type:`uv_handle_t` API functions also apply. 47 | -------------------------------------------------------------------------------- /libuv/docs/src/dll.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _dll: 3 | 4 | Shared library handling 5 | ======================= 6 | 7 | libuv provides cross platform utilities for loading shared libraries and 8 | retrieving symbols from them, using the following API. 9 | 10 | 11 | Data types 12 | ---------- 13 | 14 | .. c:type:: uv_lib_t 15 | 16 | Shared library data type. 17 | 18 | 19 | Public members 20 | ^^^^^^^^^^^^^^ 21 | 22 | N/A 23 | 24 | 25 | API 26 | --- 27 | 28 | .. c:function:: int uv_dlopen(const char* filename, uv_lib_t* lib) 29 | 30 | Opens a shared library. The filename is in utf-8. Returns 0 on success and 31 | -1 on error. Call :c:func:`uv_dlerror` to get the error message. 32 | 33 | .. c:function:: void uv_dlclose(uv_lib_t* lib) 34 | 35 | Close the shared library. 36 | 37 | .. c:function:: uv_dlsym(uv_lib_t* lib, const char* name, void** ptr) 38 | 39 | Retrieves a data pointer from a dynamic library. It is legal for a symbol 40 | to map to NULL. Returns 0 on success and -1 if the symbol was not found. 41 | 42 | .. c:function:: const char* uv_dlerror(const uv_lib_t* lib) 43 | 44 | Returns the last uv_dlopen() or uv_dlsym() error message. 45 | -------------------------------------------------------------------------------- /libuv/docs/src/dns.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _dns: 3 | 4 | DNS utility functions 5 | ===================== 6 | 7 | libuv provides asynchronous variants of `getaddrinfo` and `getnameinfo`. 8 | 9 | 10 | Data types 11 | ---------- 12 | 13 | .. c:type:: uv_getaddrinfo_t 14 | 15 | `getaddrinfo` request type. 16 | 17 | .. c:type:: void (*uv_getaddrinfo_cb)(uv_getaddrinfo_t* req, int status, struct addrinfo* res) 18 | 19 | Callback which will be called with the getaddrinfo request result once 20 | complete. In case it was cancelled, `status` will have a value of 21 | ``UV_ECANCELED``. 22 | 23 | .. c:type:: uv_getnameinfo_t 24 | 25 | `getnameinfo` request type. 26 | 27 | .. c:type:: void (*uv_getnameinfo_cb)(uv_getnameinfo_t* req, int status, const char* hostname, const char* service) 28 | 29 | Callback which will be called with the getnameinfo request result once 30 | complete. In case it was cancelled, `status` will have a value of 31 | ``UV_ECANCELED``. 32 | 33 | 34 | Public members 35 | ^^^^^^^^^^^^^^ 36 | 37 | .. c:member:: uv_loop_t* uv_getaddrinfo_t.loop 38 | 39 | Loop that started this getaddrinfo request and where completion will be 40 | reported. Readonly. 41 | 42 | .. c:member:: uv_loop_t* uv_getnameinfo_t.loop 43 | 44 | Loop that started this getnameinfo request and where completion will be 45 | reported. Readonly. 46 | 47 | .. seealso:: The :c:type:`uv_req_t` members also apply. 48 | 49 | 50 | API 51 | --- 52 | 53 | .. c:function:: int uv_getaddrinfo(uv_loop_t* loop, uv_getaddrinfo_t* req, uv_getaddrinfo_cb getaddrinfo_cb, const char* node, const char* service, const struct addrinfo* hints) 54 | 55 | Asynchronous ``getaddrinfo(3)``. 56 | 57 | Either node or service may be NULL but not both. 58 | 59 | `hints` is a pointer to a struct addrinfo with additional address type 60 | constraints, or NULL. Consult `man -s 3 getaddrinfo` for more details. 61 | 62 | Returns 0 on success or an error code < 0 on failure. If successful, the 63 | callback will get called sometime in the future with the lookup result, 64 | which is either: 65 | 66 | * status == 0, the res argument points to a valid `struct addrinfo`, or 67 | * status < 0, the res argument is NULL. See the UV_EAI_* constants. 68 | 69 | Call :c:func:`uv_freeaddrinfo` to free the addrinfo structure. 70 | 71 | .. c:function:: void uv_freeaddrinfo(struct addrinfo* ai) 72 | 73 | Free the struct addrinfo. Passing NULL is allowed and is a no-op. 74 | 75 | .. c:function:: int uv_getnameinfo(uv_loop_t* loop, uv_getnameinfo_t* req, uv_getnameinfo_cb getnameinfo_cb, const struct sockaddr* addr, int flags) 76 | 77 | Asynchronous ``getnameinfo(3)``. 78 | 79 | Returns 0 on success or an error code < 0 on failure. If successful, the 80 | callback will get called sometime in the future with the lookup result. 81 | Consult `man -s 3 getnameinfo` for more details. 82 | 83 | .. seealso:: The :c:type:`uv_req_t` API functions also apply. 84 | -------------------------------------------------------------------------------- /libuv/docs/src/fs_poll.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _fs_poll: 3 | 4 | :c:type:`uv_fs_poll_t` --- FS Poll handle 5 | ========================================= 6 | 7 | FS Poll handles allow the user to monitor a given path for changes. Unlike 8 | :c:type:`uv_fs_event_t`, fs poll handles use `stat` to detect when a file has 9 | changed so they can work on file systems where fs event handles can't. 10 | 11 | 12 | Data types 13 | ---------- 14 | 15 | .. c:type:: uv_fs_poll_t 16 | 17 | FS Poll handle type. 18 | 19 | .. c:type:: void (*uv_fs_poll_cb)(uv_fs_poll_t* handle, int status, const uv_stat_t* prev, const uv_stat_t* curr) 20 | 21 | Callback passed to :c:func:`uv_fs_poll_start` which will be called repeatedly 22 | after the handle is started, when any change happens to the monitored path. 23 | 24 | The callback is invoked with `status < 0` if `path` does not exist 25 | or is inaccessible. The watcher is *not* stopped but your callback is 26 | not called again until something changes (e.g. when the file is created 27 | or the error reason changes). 28 | 29 | When `status == 0`, the callback receives pointers to the old and new 30 | :c:type:`uv_stat_t` structs. They are valid for the duration of the 31 | callback only. 32 | 33 | 34 | Public members 35 | ^^^^^^^^^^^^^^ 36 | 37 | N/A 38 | 39 | .. seealso:: The :c:type:`uv_handle_t` members also apply. 40 | 41 | 42 | API 43 | --- 44 | 45 | .. c:function:: int uv_fs_poll_init(uv_loop_t* loop, uv_fs_poll_t* handle) 46 | 47 | Initialize the handle. 48 | 49 | .. c:function:: int uv_fs_poll_start(uv_fs_poll_t* handle, uv_fs_poll_cb poll_cb, const char* path, unsigned int interval) 50 | 51 | Check the file at `path` for changes every `interval` milliseconds. 52 | 53 | .. note:: 54 | For maximum portability, use multi-second intervals. Sub-second intervals will not detect 55 | all changes on many file systems. 56 | 57 | .. c:function:: int uv_fs_poll_stop(uv_fs_poll_t* handle) 58 | 59 | Stop the handle, the callback will no longer be called. 60 | 61 | .. c:function:: int uv_fs_poll_getpath(uv_fs_poll_t* handle, char* buf, size_t* len) 62 | 63 | Get the path being monitored by the handle. The buffer must be preallocated 64 | by the user. Returns 0 on success or an error code < 0 in case of failure. 65 | On success, `buf` will contain the path and `len` its length. If the buffer 66 | is not big enough UV_ENOBUFS will be returned and len will be set to the 67 | required size. 68 | 69 | .. seealso:: The :c:type:`uv_handle_t` API functions also apply. 70 | -------------------------------------------------------------------------------- /libuv/docs/src/idle.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _idle: 3 | 4 | :c:type:`uv_idle_t` --- Idle handle 5 | =================================== 6 | 7 | Idle handles will run the given callback once per loop iteration, right 8 | before the :c:type:`uv_prepare_t` handles. 9 | 10 | .. note:: 11 | The notable difference with prepare handles is that when there are active idle handles, 12 | the loop will perform a zero timeout poll instead of blocking for i/o. 13 | 14 | .. warning:: 15 | Despite the name, idle handles will get their callbacks called on every loop iteration, 16 | not when the loop is actually "idle". 17 | 18 | 19 | Data types 20 | ---------- 21 | 22 | .. c:type:: uv_idle_t 23 | 24 | Idle handle type. 25 | 26 | .. c:type:: void (*uv_idle_cb)(uv_idle_t* handle) 27 | 28 | Type definition for callback passed to :c:func:`uv_idle_start`. 29 | 30 | 31 | Public members 32 | ^^^^^^^^^^^^^^ 33 | 34 | N/A 35 | 36 | .. seealso:: The :c:type:`uv_handle_t` members also apply. 37 | 38 | 39 | API 40 | --- 41 | 42 | .. c:function:: int uv_idle_init(uv_loop_t*, uv_idle_t* idle) 43 | 44 | Initialize the handle. 45 | 46 | .. c:function:: int uv_idle_start(uv_idle_t* idle, uv_idle_cb cb) 47 | 48 | Start the handle with the given callback. 49 | 50 | .. c:function:: int uv_idle_stop(uv_idle_t* idle) 51 | 52 | Stop the handle, the callback will no longer be called. 53 | 54 | .. seealso:: The :c:type:`uv_handle_t` API functions also apply. 55 | -------------------------------------------------------------------------------- /libuv/docs/src/index.rst: -------------------------------------------------------------------------------- 1 | 2 | Welcome to the libuv API documentation 3 | ====================================== 4 | 5 | Overview 6 | -------- 7 | 8 | libuv is a multi-platform support library with a focus on asynchronous I/O. It 9 | was primarily developed for use by `Node.js`_, but it's also used by `Luvit`_, 10 | `Julia`_, `pyuv`_, and `others`_. 11 | 12 | .. note:: 13 | In case you find errors in this documentation you can help by sending 14 | `pull requests `_! 15 | 16 | .. _Node.js: http://nodejs.org 17 | .. _Luvit: http://luvit.io 18 | .. _Julia: http://julialang.org 19 | .. _pyuv: https://github.com/saghul/pyuv 20 | .. _others: https://github.com/libuv/libuv/wiki/Projects-that-use-libuv 21 | 22 | 23 | Features 24 | -------- 25 | 26 | * Full-featured event loop backed by epoll, kqueue, IOCP, event ports. 27 | * Asynchronous TCP and UDP sockets 28 | * Asynchronous DNS resolution 29 | * Asynchronous file and file system operations 30 | * File system events 31 | * ANSI escape code controlled TTY 32 | * IPC with socket sharing, using Unix domain sockets or named pipes (Windows) 33 | * Child processes 34 | * Thread pool 35 | * Signal handling 36 | * High resolution clock 37 | * Threading and synchronization primitives 38 | 39 | 40 | Downloads 41 | --------- 42 | 43 | libuv can be downloaded from `here `_. 44 | 45 | 46 | Installation 47 | ------------ 48 | 49 | Installation instructions can be found on `the README `_. 50 | 51 | 52 | Upgrading 53 | --------- 54 | 55 | Migration guides for different libuv versions, starting with 1.0. 56 | 57 | .. toctree:: 58 | :maxdepth: 1 59 | 60 | migration_010_100 61 | 62 | 63 | Documentation 64 | ------------- 65 | 66 | .. toctree:: 67 | :maxdepth: 1 68 | 69 | design 70 | errors 71 | loop 72 | handle 73 | request 74 | timer 75 | prepare 76 | check 77 | idle 78 | async 79 | poll 80 | signal 81 | process 82 | stream 83 | tcp 84 | pipe 85 | tty 86 | udp 87 | fs_event 88 | fs_poll 89 | fs 90 | threadpool 91 | dns 92 | dll 93 | threading 94 | misc 95 | -------------------------------------------------------------------------------- /libuv/docs/src/pipe.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _pipe: 3 | 4 | :c:type:`uv_pipe_t` --- Pipe handle 5 | =================================== 6 | 7 | Pipe handles provide an abstraction over local domain sockets on Unix and named 8 | pipes on Windows. 9 | 10 | :c:type:`uv_pipe_t` is a 'subclass' of :c:type:`uv_stream_t`. 11 | 12 | 13 | Data types 14 | ---------- 15 | 16 | .. c:type:: uv_pipe_t 17 | 18 | Pipe handle type. 19 | 20 | 21 | Public members 22 | ^^^^^^^^^^^^^^ 23 | 24 | N/A 25 | 26 | .. seealso:: The :c:type:`uv_stream_t` members also apply. 27 | 28 | 29 | API 30 | --- 31 | 32 | .. c:function:: int uv_pipe_init(uv_loop_t*, uv_pipe_t* handle, int ipc) 33 | 34 | Initialize a pipe handle. The `ipc` argument is a boolean to indicate if 35 | this pipe will be used for handle passing between processes. 36 | 37 | .. c:function:: int uv_pipe_open(uv_pipe_t*, uv_file file) 38 | 39 | Open an existing file descriptor or HANDLE as a pipe. 40 | 41 | .. versionchanged:: 1.2.1 the file descriptor is set to non-blocking mode. 42 | 43 | .. c:function:: int uv_pipe_bind(uv_pipe_t* handle, const char* name) 44 | 45 | Bind the pipe to a file path (Unix) or a name (Windows). 46 | 47 | .. note:: 48 | Paths on Unix get truncated to ``sizeof(sockaddr_un.sun_path)`` bytes, typically between 49 | 92 and 108 bytes. 50 | 51 | .. c:function:: void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle, const char* name, uv_connect_cb cb) 52 | 53 | Connect to the Unix domain socket or the named pipe. 54 | 55 | .. note:: 56 | Paths on Unix get truncated to ``sizeof(sockaddr_un.sun_path)`` bytes, typically between 57 | 92 and 108 bytes. 58 | 59 | .. c:function:: int uv_pipe_getsockname(const uv_pipe_t* handle, char* buf, size_t* len) 60 | 61 | Get the name of the Unix domain socket or the named pipe. 62 | 63 | A preallocated buffer must be provided. The len parameter holds the length 64 | of the buffer and it's set to the number of bytes written to the buffer on 65 | output. If the buffer is not big enough ``UV_ENOBUFS`` will be returned and 66 | len will contain the required size. 67 | 68 | .. c:function:: void uv_pipe_pending_instances(uv_pipe_t* handle, int count) 69 | 70 | Set the number of pending pipe instance handles when the pipe server is 71 | waiting for connections. 72 | 73 | .. note:: 74 | This setting applies to Windows only. 75 | 76 | .. c:function:: int uv_pipe_pending_count(uv_pipe_t* handle) 77 | .. c:function:: uv_handle_type uv_pipe_pending_type(uv_pipe_t* handle) 78 | 79 | Used to receive handles over IPC pipes. 80 | 81 | First - call :c:func:`uv_pipe_pending_count`, if it's > 0 then initialize 82 | a handle of the given `type`, returned by :c:func:`uv_pipe_pending_type` 83 | and call ``uv_accept(pipe, handle)``. 84 | 85 | .. seealso:: The :c:type:`uv_stream_t` API functions also apply. 86 | -------------------------------------------------------------------------------- /libuv/docs/src/prepare.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _prepare: 3 | 4 | :c:type:`uv_prepare_t` --- Prepare handle 5 | ========================================= 6 | 7 | Prepare handles will run the given callback once per loop iteration, right 8 | before polling for i/o. 9 | 10 | 11 | Data types 12 | ---------- 13 | 14 | .. c:type:: uv_prepare_t 15 | 16 | Prepare handle type. 17 | 18 | .. c:type:: void (*uv_prepare_cb)(uv_prepare_t* handle) 19 | 20 | Type definition for callback passed to :c:func:`uv_prepare_start`. 21 | 22 | 23 | Public members 24 | ^^^^^^^^^^^^^^ 25 | 26 | N/A 27 | 28 | .. seealso:: The :c:type:`uv_handle_t` members also apply. 29 | 30 | 31 | API 32 | --- 33 | 34 | .. c:function:: int uv_prepare_init(uv_loop_t* loop, uv_prepare_t* prepare) 35 | 36 | Initialize the handle. 37 | 38 | .. c:function:: int uv_prepare_start(uv_prepare_t* prepare, uv_prepare_cb cb) 39 | 40 | Start the handle with the given callback. 41 | 42 | .. c:function:: int uv_prepare_stop(uv_prepare_t* prepare) 43 | 44 | Stop the handle, the callback will no longer be called. 45 | 46 | .. seealso:: The :c:type:`uv_handle_t` API functions also apply. 47 | -------------------------------------------------------------------------------- /libuv/docs/src/request.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _request: 3 | 4 | :c:type:`uv_req_t` --- Base request 5 | =================================== 6 | 7 | `uv_req_t` is the base type for all libuv request types. 8 | 9 | Structures are aligned so that any libuv request can be cast to `uv_req_t`. 10 | All API functions defined here work with any request type. 11 | 12 | 13 | Data types 14 | ---------- 15 | 16 | .. c:type:: uv_req_t 17 | 18 | The base libuv request structure. 19 | 20 | .. c:type:: uv_any_req 21 | 22 | Union of all request types. 23 | 24 | 25 | Public members 26 | ^^^^^^^^^^^^^^ 27 | 28 | .. c:member:: void* uv_request_t.data 29 | 30 | Space for user-defined arbitrary data. libuv does not use this field. 31 | 32 | .. c:member:: uv_req_type uv_req_t.type 33 | 34 | Indicated the type of request. Readonly. 35 | 36 | :: 37 | 38 | typedef enum { 39 | UV_UNKNOWN_REQ = 0, 40 | UV_REQ, 41 | UV_CONNECT, 42 | UV_WRITE, 43 | UV_SHUTDOWN, 44 | UV_UDP_SEND, 45 | UV_FS, 46 | UV_WORK, 47 | UV_GETADDRINFO, 48 | UV_GETNAMEINFO, 49 | UV_REQ_TYPE_PRIVATE, 50 | UV_REQ_TYPE_MAX, 51 | } uv_req_type; 52 | 53 | 54 | API 55 | --- 56 | 57 | .. c:function:: int uv_cancel(uv_req_t* req) 58 | 59 | Cancel a pending request. Fails if the request is executing or has finished 60 | executing. 61 | 62 | Returns 0 on success, or an error code < 0 on failure. 63 | 64 | Only cancellation of :c:type:`uv_fs_t`, :c:type:`uv_getaddrinfo_t`, 65 | :c:type:`uv_getnameinfo_t` and :c:type:`uv_work_t` requests is 66 | currently supported. 67 | 68 | Cancelled requests have their callbacks invoked some time in the future. 69 | It's **not** safe to free the memory associated with the request until the 70 | callback is called. 71 | 72 | Here is how cancellation is reported to the callback: 73 | 74 | * A :c:type:`uv_fs_t` request has its req->result field set to `UV_ECANCELED`. 75 | 76 | * A :c:type:`uv_work_t`, :c:type:`uv_getaddrinfo_t` or c:type:`uv_getnameinfo_t` 77 | request has its callback invoked with status == `UV_ECANCELED`. 78 | 79 | .. c:function:: size_t uv_req_size(uv_req_type type) 80 | 81 | Returns the size of the given request type. Useful for FFI binding writers 82 | who don't want to know the structure layout. 83 | -------------------------------------------------------------------------------- /libuv/docs/src/signal.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _signal: 3 | 4 | :c:type:`uv_signal_t` --- Signal handle 5 | ======================================= 6 | 7 | Signal handles implement Unix style signal handling on a per-event loop bases. 8 | 9 | Reception of some signals is emulated on Windows: 10 | 11 | * SIGINT is normally delivered when the user presses CTRL+C. However, like 12 | on Unix, it is not generated when terminal raw mode is enabled. 13 | 14 | * SIGBREAK is delivered when the user pressed CTRL + BREAK. 15 | 16 | * SIGHUP is generated when the user closes the console window. On SIGHUP the 17 | program is given approximately 10 seconds to perform cleanup. After that 18 | Windows will unconditionally terminate it. 19 | 20 | * SIGWINCH is raised whenever libuv detects that the console has been 21 | resized. SIGWINCH is emulated by libuv when the program uses a :c:type:`uv_tty_t` 22 | handle to write to the console. SIGWINCH may not always be delivered in a 23 | timely manner; libuv will only detect size changes when the cursor is 24 | being moved. When a readable :c:type:`uv_tty_t` handle is used in raw mode, 25 | resizing the console buffer will also trigger a SIGWINCH signal. 26 | 27 | Watchers for other signals can be successfully created, but these signals 28 | are never received. These signals are: `SIGILL`, `SIGABRT`, `SIGFPE`, `SIGSEGV`, 29 | `SIGTERM` and `SIGKILL.` 30 | 31 | Calls to raise() or abort() to programmatically raise a signal are 32 | not detected by libuv; these will not trigger a signal watcher. 33 | 34 | .. note:: 35 | On Linux SIGRT0 and SIGRT1 (signals 32 and 33) are used by the NPTL pthreads library to 36 | manage threads. Installing watchers for those signals will lead to unpredictable behavior 37 | and is strongly discouraged. Future versions of libuv may simply reject them. 38 | 39 | 40 | Data types 41 | ---------- 42 | 43 | .. c:type:: uv_signal_t 44 | 45 | Signal handle type. 46 | 47 | .. c:type:: void (*uv_signal_cb)(uv_signal_t* handle, int signum) 48 | 49 | Type definition for callback passed to :c:func:`uv_signal_start`. 50 | 51 | 52 | Public members 53 | ^^^^^^^^^^^^^^ 54 | 55 | .. c:member:: int uv_signal_t.signum 56 | 57 | Signal being monitored by this handle. Readonly. 58 | 59 | .. seealso:: The :c:type:`uv_handle_t` members also apply. 60 | 61 | 62 | API 63 | --- 64 | 65 | .. c:function:: int uv_signal_init(uv_loop_t*, uv_signal_t* signal) 66 | 67 | Initialize the handle. 68 | 69 | .. c:function:: int uv_signal_start(uv_signal_t* signal, uv_signal_cb cb, int signum) 70 | 71 | Start the handle with the given callback, watching for the given signal. 72 | 73 | .. c:function:: int uv_signal_stop(uv_signal_t* signal) 74 | 75 | Stop the handle, the callback will no longer be called. 76 | 77 | .. seealso:: The :c:type:`uv_handle_t` API functions also apply. 78 | -------------------------------------------------------------------------------- /libuv/docs/src/static/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deleisha/libuv-tls/94ca8f4347294419cad4be6f4c31cb3f9cc5443f/libuv/docs/src/static/architecture.png -------------------------------------------------------------------------------- /libuv/docs/src/static/diagrams.key/Data/st0-311.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deleisha/libuv-tls/94ca8f4347294419cad4be6f4c31cb3f9cc5443f/libuv/docs/src/static/diagrams.key/Data/st0-311.jpg -------------------------------------------------------------------------------- /libuv/docs/src/static/diagrams.key/Data/st1-475.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deleisha/libuv-tls/94ca8f4347294419cad4be6f4c31cb3f9cc5443f/libuv/docs/src/static/diagrams.key/Data/st1-475.jpg -------------------------------------------------------------------------------- /libuv/docs/src/static/diagrams.key/Index.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deleisha/libuv-tls/94ca8f4347294419cad4be6f4c31cb3f9cc5443f/libuv/docs/src/static/diagrams.key/Index.zip -------------------------------------------------------------------------------- /libuv/docs/src/static/diagrams.key/Metadata/BuildVersionHistory.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Template: White (2014-02-28 09:41) 6 | M6.2.2-1878-1 7 | 8 | 9 | -------------------------------------------------------------------------------- /libuv/docs/src/static/diagrams.key/Metadata/DocumentIdentifier: -------------------------------------------------------------------------------- 1 | F69E9CD9-EEF1-4223-9DA4-A1EA7FE112BA -------------------------------------------------------------------------------- /libuv/docs/src/static/diagrams.key/Metadata/Properties.plist: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deleisha/libuv-tls/94ca8f4347294419cad4be6f4c31cb3f9cc5443f/libuv/docs/src/static/diagrams.key/Metadata/Properties.plist -------------------------------------------------------------------------------- /libuv/docs/src/static/diagrams.key/preview-micro.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deleisha/libuv-tls/94ca8f4347294419cad4be6f4c31cb3f9cc5443f/libuv/docs/src/static/diagrams.key/preview-micro.jpg -------------------------------------------------------------------------------- /libuv/docs/src/static/diagrams.key/preview-web.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deleisha/libuv-tls/94ca8f4347294419cad4be6f4c31cb3f9cc5443f/libuv/docs/src/static/diagrams.key/preview-web.jpg -------------------------------------------------------------------------------- /libuv/docs/src/static/diagrams.key/preview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deleisha/libuv-tls/94ca8f4347294419cad4be6f4c31cb3f9cc5443f/libuv/docs/src/static/diagrams.key/preview.jpg -------------------------------------------------------------------------------- /libuv/docs/src/static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deleisha/libuv-tls/94ca8f4347294419cad4be6f4c31cb3f9cc5443f/libuv/docs/src/static/favicon.ico -------------------------------------------------------------------------------- /libuv/docs/src/static/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deleisha/libuv-tls/94ca8f4347294419cad4be6f4c31cb3f9cc5443f/libuv/docs/src/static/logo.png -------------------------------------------------------------------------------- /libuv/docs/src/static/loop_iteration.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deleisha/libuv-tls/94ca8f4347294419cad4be6f4c31cb3f9cc5443f/libuv/docs/src/static/loop_iteration.png -------------------------------------------------------------------------------- /libuv/docs/src/threadpool.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _threadpool: 3 | 4 | Thread pool work scheduling 5 | =========================== 6 | 7 | libuv provides a threadpool which can be used to run user code and get notified 8 | in the loop thread. This thread pool is internally used to run all filesystem 9 | operations, as well as getaddrinfo and getnameinfo requests. 10 | 11 | Its default size is 4, but it can be changed at startup time by setting the 12 | ``UV_THREADPOOL_SIZE`` environment variable to any value (the absolute maximum 13 | is 128). 14 | 15 | The threadpool is global and shared across all event loops. 16 | 17 | 18 | Data types 19 | ---------- 20 | 21 | .. c:type:: uv_work_t 22 | 23 | Work request type. 24 | 25 | .. c:type:: void (*uv_work_cb)(uv_work_t* req) 26 | 27 | Callback passed to :c:func:`uv_queue_work` which will be run on the thread 28 | pool. 29 | 30 | .. c:type:: void (*uv_after_work_cb)(uv_work_t* req, int status) 31 | 32 | Callback passed to :c:func:`uv_queue_work` which will be called on the loop 33 | thread after the work on the threadpool has been completed. If the work 34 | was cancelled using :c:func:`uv_cancel` `status` will be ``UV_ECANCELED``. 35 | 36 | 37 | Public members 38 | ^^^^^^^^^^^^^^ 39 | 40 | .. c:member:: uv_loop_t* uv_work_t.loop 41 | 42 | Loop that started this request and where completion will be reported. 43 | Readonly. 44 | 45 | .. seealso:: The :c:type:`uv_req_t` members also apply. 46 | 47 | 48 | API 49 | --- 50 | 51 | .. c:function:: int uv_queue_work(uv_loop_t* loop, uv_work_t* req, uv_work_cb work_cb, uv_after_work_cb after_work_cb) 52 | 53 | Initializes a work request which will run the given `work_cb` in a thread 54 | from the threadpool. Once `work_cb` is completed, `after_work_cb` will be 55 | called on the loop thread. 56 | 57 | This request can be cancelled with :c:func:`uv_cancel`. 58 | 59 | .. seealso:: The :c:type:`uv_req_t` API functions also apply. 60 | -------------------------------------------------------------------------------- /libuv/docs/src/timer.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _timer: 3 | 4 | :c:type:`uv_timer_t` --- Timer handle 5 | ===================================== 6 | 7 | Timer handles are used to schedule callbacks to be called in the future. 8 | 9 | 10 | Data types 11 | ---------- 12 | 13 | .. c:type:: uv_timer_t 14 | 15 | Timer handle type. 16 | 17 | .. c:type:: void (*uv_timer_cb)(uv_timer_t* handle) 18 | 19 | Type definition for callback passed to :c:func:`uv_timer_start`. 20 | 21 | 22 | Public members 23 | ^^^^^^^^^^^^^^ 24 | 25 | N/A 26 | 27 | .. seealso:: The :c:type:`uv_handle_t` members also apply. 28 | 29 | 30 | API 31 | --- 32 | 33 | .. c:function:: int uv_timer_init(uv_loop_t* loop, uv_timer_t* handle) 34 | 35 | Initialize the handle. 36 | 37 | .. c:function:: int uv_timer_start(uv_timer_t* handle, uv_timer_cb cb, uint64_t timeout, uint64_t repeat) 38 | 39 | Start the timer. `timeout` and `repeat` are in milliseconds. 40 | 41 | If `timeout` is zero, the callback fires on the next event loop iteration. 42 | If `repeat` is non-zero, the callback fires first after `timeout` 43 | milliseconds and then repeatedly after `repeat` milliseconds. 44 | 45 | .. c:function:: int uv_timer_stop(uv_timer_t* handle) 46 | 47 | Stop the timer, the callback will not be called anymore. 48 | 49 | .. c:function:: int uv_timer_again(uv_timer_t* handle) 50 | 51 | Stop the timer, and if it is repeating restart it using the repeat value 52 | as the timeout. If the timer has never been started before it returns 53 | UV_EINVAL. 54 | 55 | .. c:function:: void uv_timer_set_repeat(uv_timer_t* handle, uint64_t repeat) 56 | 57 | Set the repeat value in milliseconds. 58 | 59 | .. note:: 60 | If the repeat value is set from a timer callback it does not immediately take effect. 61 | If the timer was non-repeating before, it will have been stopped. If it was repeating, 62 | then the old repeat value will have been used to schedule the next timeout. 63 | 64 | .. c:function:: uint64_t uv_timer_get_repeat(const uv_timer_t* handle) 65 | 66 | Get the timer repeat value. 67 | 68 | .. seealso:: The :c:type:`uv_handle_t` API functions also apply. 69 | -------------------------------------------------------------------------------- /libuv/docs/src/tty.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _tty: 3 | 4 | :c:type:`uv_tty_t` --- TTY handle 5 | ================================= 6 | 7 | TTY handles represent a stream for the console. 8 | 9 | :c:type:`uv_tty_t` is a 'subclass' of :c:type:`uv_stream_t`. 10 | 11 | 12 | Data types 13 | ---------- 14 | 15 | .. c:type:: uv_tty_t 16 | 17 | TTY handle type. 18 | 19 | .. c:type:: uv_tty_mode_t 20 | 21 | .. versionadded:: 1.2.0 22 | 23 | TTY mode type: 24 | 25 | :: 26 | 27 | typedef enum { 28 | /* Initial/normal terminal mode */ 29 | UV_TTY_MODE_NORMAL, 30 | /* Raw input mode (On Windows, ENABLE_WINDOW_INPUT is also enabled) */ 31 | UV_TTY_MODE_RAW, 32 | /* Binary-safe I/O mode for IPC (Unix-only) */ 33 | UV_TTY_MODE_IO 34 | } uv_tty_mode_t; 35 | 36 | 37 | 38 | Public members 39 | ^^^^^^^^^^^^^^ 40 | 41 | N/A 42 | 43 | .. seealso:: The :c:type:`uv_stream_t` members also apply. 44 | 45 | 46 | API 47 | --- 48 | 49 | .. c:function:: int uv_tty_init(uv_loop_t*, uv_tty_t*, uv_file fd, int readable) 50 | 51 | Initialize a new TTY stream with the given file descriptor. Usually the 52 | file descriptor will be: 53 | 54 | * 0 = stdin 55 | * 1 = stdout 56 | * 2 = stderr 57 | 58 | `readable`, specifies if you plan on calling :c:func:`uv_read_start` with 59 | this stream. stdin is readable, stdout is not. 60 | 61 | On Unix this function will try to open ``/dev/tty`` and use it if the passed file 62 | descriptor refers to a TTY. This lets libuv put the tty in non-blocking mode 63 | without affecting other processes that share the tty. 64 | 65 | .. note:: 66 | If opening ``/dev/tty`` fails, libuv falls back to blocking writes for non-readable 67 | TTY streams. 68 | 69 | .. c:function:: int uv_tty_set_mode(uv_tty_t*, uv_tty_mode_t mode) 70 | 71 | .. versionchanged:: 1.2.0: the mode is specified as a :c:type:`uv_tty_mode_t` 72 | value. 73 | 74 | Set the TTY using the specified terminal mode. 75 | 76 | .. c:function:: int uv_tty_reset_mode(void) 77 | 78 | To be called when the program exits. Resets TTY settings to default 79 | values for the next process to take over. 80 | 81 | This function is async signal-safe on Unix platforms but can fail with error 82 | code ``UV_EBUSY`` if you call it when execution is inside 83 | :c:func:`uv_tty_set_mode`. 84 | 85 | .. c:function:: int uv_tty_get_winsize(uv_tty_t*, int* width, int* height) 86 | 87 | Gets the current Window size. On success it returns 0. 88 | 89 | .. seealso:: The :c:type:`uv_stream_t` API functions also apply. 90 | -------------------------------------------------------------------------------- /libuv/img/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deleisha/libuv-tls/94ca8f4347294419cad4be6f4c31cb3f9cc5443f/libuv/img/banner.png -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/include/uv-aix.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_AIX_H 23 | #define UV_AIX_H 24 | 25 | #define UV_PLATFORM_LOOP_FIELDS \ 26 | int fs_fd; \ 27 | 28 | #define UV_PLATFORM_FS_EVENT_FIELDS \ 29 | uv__io_t event_watcher; \ 30 | char *dir_filename; \ 31 | 32 | #endif /* UV_AIX_H */ 33 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 the same major number are ABI stable. API is allowed to 27 | * evolve between minor releases, but only in a backwards compatible way. 28 | * 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 1 34 | #define UV_VERSION_MINOR 2 35 | #define UV_VERSION_PATCH 1 36 | #define UV_VERSION_IS_RELEASE 1 37 | #define UV_VERSION_SUFFIX "" 38 | 39 | #endif /* UV_VERSION_H */ 40 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/m4/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore libtoolize-generated files. 2 | *.m4 3 | !as_case.m4 4 | !libuv-check-flags.m4 5 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 "-" UV_VERSION_SUFFIX 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 | -------------------------------------------------------------------------------- /libuv/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 | } 40 | 41 | #else /* GCC */ 42 | 43 | /* Mingw-32 version, hopefully this works for 64-bit gcc as well. */ 44 | static inline char uv__atomic_exchange_set(char volatile* target) { 45 | const char one = 1; 46 | char old_value; 47 | __asm__ __volatile__ ("lock xchgb %0, %1\n\t" 48 | : "=r"(old_value), "=m"(*target) 49 | : "0"(one), "m"(*target) 50 | : "memory"); 51 | return old_value; 52 | } 53 | 54 | #endif 55 | 56 | #endif /* UV_WIN_ATOMICOPS_INL_H_ */ 57 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/test/fixtures/empty_file: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deleisha/libuv-tls/94ca8f4347294419cad4be6f4c31cb3f9cc5443f/libuv/test/fixtures/empty_file -------------------------------------------------------------------------------- /libuv/test/fixtures/load_error.node: -------------------------------------------------------------------------------- 1 | foobar 2 | -------------------------------------------------------------------------------- /libuv/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 | if (platform_init(argc, argv)) 37 | return EXIT_FAILURE; 38 | 39 | switch (argc) { 40 | case 1: return run_tests(1); 41 | case 2: return maybe_run_test(argc, argv); 42 | case 3: return run_test_part(argv[1], argv[2]); 43 | default: 44 | LOGF("Too many arguments.\n"); 45 | return EXIT_FAILURE; 46 | } 47 | 48 | return EXIT_SUCCESS; 49 | } 50 | 51 | 52 | static int maybe_run_test(int argc, char **argv) { 53 | if (strcmp(argv[1], "--list") == 0) { 54 | print_tests(stdout); 55 | return 0; 56 | } 57 | 58 | if (strcmp(argv[1], "spawn_helper") == 0) { 59 | printf("hello world\n"); 60 | return 42; 61 | } 62 | 63 | return run_test(argv[1], 1, 1); 64 | } 65 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 == uv_pipe_init(uv_default_loop(), &pipe_handle, 0)); 58 | ASSERT(0 == uv_pipe_open(&pipe_handle, fd[0])); 59 | fd[0] = -1; /* uv_pipe_open() takes ownership of the file descriptor. */ 60 | ASSERT(1 == write(fd[1], "", 1)); 61 | ASSERT(0 == close(fd[1])); 62 | fd[1] = -1; 63 | ASSERT(0 == uv_read_start((uv_stream_t *) &pipe_handle, alloc_cb, read_cb)); 64 | ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT)); 65 | ASSERT(1 == read_cb_called); 66 | ASSERT(0 == uv_is_active((const uv_handle_t *) &pipe_handle)); 67 | ASSERT(0 == uv_read_start((uv_stream_t *) &pipe_handle, alloc_cb, read_cb)); 68 | ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT)); 69 | ASSERT(2 == read_cb_called); 70 | ASSERT(0 != uv_is_closing((const uv_handle_t *) &pipe_handle)); 71 | 72 | MAKE_VALGRIND_HAPPY(); 73 | return 0; 74 | } 75 | 76 | #endif /* !defined(_WIN32) */ 77 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 size1; 33 | size_t size2; 34 | int err; 35 | 36 | size1 = sizeof buffer_orig; 37 | err = uv_cwd(buffer_orig, &size1); 38 | ASSERT(err == 0); 39 | 40 | err = uv_chdir(buffer_orig); 41 | ASSERT(err == 0); 42 | 43 | size2 = sizeof buffer_new; 44 | err = uv_cwd(buffer_new, &size2); 45 | ASSERT(err == 0); 46 | 47 | ASSERT(size1 == size2); 48 | ASSERT(strcmp(buffer_orig, buffer_new) == 0); 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /libuv/test/test-default-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 | 26 | static int timer_cb_called; 27 | 28 | 29 | static void timer_cb(uv_timer_t* timer) { 30 | timer_cb_called++; 31 | uv_close((uv_handle_t*) timer, NULL); 32 | } 33 | 34 | 35 | TEST_IMPL(default_loop_close) { 36 | uv_loop_t* loop; 37 | uv_timer_t timer_handle; 38 | 39 | loop = uv_default_loop(); 40 | ASSERT(loop != NULL); 41 | 42 | ASSERT(0 == uv_timer_init(loop, &timer_handle)); 43 | ASSERT(0 == uv_timer_start(&timer_handle, timer_cb, 1, 0)); 44 | ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT)); 45 | ASSERT(1 == timer_cb_called); 46 | ASSERT(0 == uv_loop_close(loop)); 47 | 48 | loop = uv_default_loop(); 49 | ASSERT(loop != NULL); 50 | 51 | ASSERT(0 == uv_timer_init(loop, &timer_handle)); 52 | ASSERT(0 == uv_timer_start(&timer_handle, timer_cb, 1, 0)); 53 | ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT)); 54 | ASSERT(2 == timer_cb_called); 55 | ASSERT(0 == uv_loop_close(loop)); 56 | 57 | MAKE_VALGRIND_HAPPY(); 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /libuv/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* dlerror_no_error = "no error"; 30 | const char* msg; 31 | uv_lib_t lib; 32 | int r; 33 | 34 | lib.errmsg = NULL; 35 | lib.handle = NULL; 36 | msg = uv_dlerror(&lib); 37 | ASSERT(msg != NULL); 38 | ASSERT(strstr(msg, dlerror_no_error) != NULL); 39 | 40 | r = uv_dlopen(path, &lib); 41 | ASSERT(r == -1); 42 | 43 | msg = uv_dlerror(&lib); 44 | ASSERT(msg != NULL); 45 | ASSERT(strstr(msg, dlerror_no_error) == NULL); 46 | 47 | /* Should return the same error twice in a row. */ 48 | msg = uv_dlerror(&lib); 49 | ASSERT(msg != NULL); 50 | ASSERT(strstr(msg, dlerror_no_error) == NULL); 51 | 52 | uv_dlclose(&lib); 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | size = 0; 65 | r = uv_exepath(buffer, &size); 66 | ASSERT(r == UV_EINVAL); 67 | 68 | memset(buffer, -1, sizeof(buffer)); 69 | 70 | size = 1; 71 | r = uv_exepath(buffer, &size); 72 | ASSERT(r == 0); 73 | ASSERT(size == 0); 74 | ASSERT(buffer[0] == '\0'); 75 | 76 | memset(buffer, -1, sizeof(buffer)); 77 | 78 | size = 2; 79 | r = uv_exepath(buffer, &size); 80 | ASSERT(r == 0); 81 | ASSERT(size == 1); 82 | ASSERT(buffer[0] != '\0'); 83 | ASSERT(buffer[1] == '\0'); 84 | 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/test/test-loop-configure.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, 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 | #include "uv.h" 17 | #include "task.h" 18 | 19 | static void timer_cb(uv_timer_t* handle) { 20 | uv_close((uv_handle_t*) handle, NULL); 21 | } 22 | 23 | 24 | TEST_IMPL(loop_configure) { 25 | uv_timer_t timer_handle; 26 | uv_loop_t loop; 27 | ASSERT(0 == uv_loop_init(&loop)); 28 | #ifdef _WIN32 29 | ASSERT(UV_ENOSYS == uv_loop_configure(&loop, UV_LOOP_BLOCK_SIGNAL, 0)); 30 | #else 31 | ASSERT(0 == uv_loop_configure(&loop, UV_LOOP_BLOCK_SIGNAL, SIGPROF)); 32 | #endif 33 | ASSERT(0 == uv_timer_init(&loop, &timer_handle)); 34 | ASSERT(0 == uv_timer_start(&timer_handle, timer_cb, 10, 0)); 35 | ASSERT(0 == uv_run(&loop, UV_RUN_DEFAULT)); 36 | ASSERT(0 == uv_loop_close(&loop)); 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | MAKE_VALGRIND_HAPPY(); 34 | return 0; 35 | } 36 | 37 | static void cb(uv_timer_t* timer) { 38 | uv_close((uv_handle_t*)timer, NULL); 39 | } 40 | 41 | TEST_IMPL(loop_backend_timeout) { 42 | uv_loop_t *loop = uv_default_loop(); 43 | uv_timer_t timer; 44 | int r; 45 | 46 | r = uv_timer_init(loop, &timer); 47 | ASSERT(r == 0); 48 | 49 | ASSERT(!uv_loop_alive(loop)); 50 | ASSERT(uv_backend_timeout(loop) == 0); 51 | 52 | r = uv_timer_start(&timer, cb, 1000, 0); /* 1 sec */ 53 | ASSERT(r == 0); 54 | ASSERT(uv_backend_timeout(loop) > 100); /* 0.1 sec */ 55 | ASSERT(uv_backend_timeout(loop) <= 1000); /* 1 sec */ 56 | 57 | r = uv_run(loop, UV_RUN_DEFAULT); 58 | ASSERT(r == 0); 59 | ASSERT(uv_backend_timeout(loop) == 0); 60 | 61 | MAKE_VALGRIND_HAPPY(); 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/test/test-socket-buffer-size.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 uv_udp_t udp; 30 | static uv_tcp_t tcp; 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 check_buffer_size(uv_handle_t* handle) { 40 | int value; 41 | 42 | value = 0; 43 | ASSERT(0 == uv_recv_buffer_size(handle, &value)); 44 | ASSERT(value > 0); 45 | 46 | value = 10000; 47 | ASSERT(0 == uv_recv_buffer_size(handle, &value)); 48 | 49 | value = 0; 50 | ASSERT(0 == uv_recv_buffer_size(handle, &value)); 51 | /* linux sets double the value */ 52 | ASSERT(value == 10000 || value == 20000); 53 | } 54 | 55 | 56 | TEST_IMPL(socket_buffer_size) { 57 | struct sockaddr_in addr; 58 | 59 | ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr)); 60 | 61 | ASSERT(0 == uv_tcp_init(uv_default_loop(), &tcp)); 62 | ASSERT(0 == uv_tcp_bind(&tcp, (struct sockaddr*) &addr, 0)); 63 | check_buffer_size((uv_handle_t*) &tcp); 64 | uv_close((uv_handle_t*) &tcp, close_cb); 65 | 66 | ASSERT(0 == uv_udp_init(uv_default_loop(), &udp)); 67 | ASSERT(0 == uv_udp_bind(&udp, (struct sockaddr*) &addr, 0)); 68 | check_buffer_size((uv_handle_t*) &udp); 69 | uv_close((uv_handle_t*) &udp, close_cb); 70 | 71 | ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT)); 72 | 73 | ASSERT(close_cb_called == 2); 74 | 75 | MAKE_VALGRIND_HAPPY(); 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/test/test-tcp-write-after-connect.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 | #ifndef _WIN32 23 | 24 | #include "uv.h" 25 | #include "task.h" 26 | 27 | uv_loop_t loop; 28 | uv_tcp_t tcp_client; 29 | uv_connect_t connection_request; 30 | uv_write_t write_request; 31 | uv_buf_t buf = { "HELLO", 4 }; 32 | 33 | 34 | static void write_cb(uv_write_t *req, int status) { 35 | ASSERT(status == UV_ECANCELED); 36 | uv_close((uv_handle_t*) req->handle, NULL); 37 | } 38 | 39 | 40 | static void connect_cb(uv_connect_t *req, int status) { 41 | ASSERT(status == UV_ECONNREFUSED); 42 | } 43 | 44 | 45 | TEST_IMPL(tcp_write_after_connect) { 46 | struct sockaddr_in sa; 47 | ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &sa)); 48 | ASSERT(0 == uv_loop_init(&loop)); 49 | ASSERT(0 == uv_tcp_init(&loop, &tcp_client)); 50 | 51 | ASSERT(0 == uv_tcp_connect(&connection_request, 52 | &tcp_client, 53 | (const struct sockaddr *) 54 | &sa, 55 | connect_cb)); 56 | 57 | ASSERT(0 == uv_write(&write_request, 58 | (uv_stream_t *)&tcp_client, 59 | &buf, 1, 60 | write_cb)); 61 | 62 | uv_run(&loop, UV_RUN_DEFAULT); 63 | 64 | MAKE_VALGRIND_HAPPY(); 65 | return 0; 66 | } 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /libuv/test/test-thread-equal.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 | uv_thread_t main_thread_id; 26 | uv_thread_t subthreads[2]; 27 | 28 | static void check_thread(void* arg) { 29 | uv_thread_t *thread_id = arg; 30 | uv_thread_t self_id = uv_thread_self(); 31 | ASSERT(uv_thread_equal(&main_thread_id, &self_id) == 0); 32 | *thread_id = uv_thread_self(); 33 | } 34 | 35 | TEST_IMPL(thread_equal) { 36 | uv_thread_t threads[2]; 37 | main_thread_id = uv_thread_self(); 38 | ASSERT(0 != uv_thread_equal(&main_thread_id, &main_thread_id)); 39 | ASSERT(0 == uv_thread_create(threads + 0, check_thread, subthreads + 0)); 40 | ASSERT(0 == uv_thread_create(threads + 1, check_thread, subthreads + 1)); 41 | ASSERT(0 == uv_thread_join(threads + 0)); 42 | ASSERT(0 == uv_thread_join(threads + 1)); 43 | ASSERT(0 == uv_thread_equal(subthreads + 0, subthreads + 1)); 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /libuv/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 | -------------------------------------------------------------------------------- /prepend_licence.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import sys 3 | 4 | 5 | LICENSE = ''' 6 | /*////////////////////////////////////////////////////////////////////////////// 7 | 8 | * Copyright (c) 2015 libuv-tls contributors 9 | 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy 11 | * of this software and associated documentation files (the "Software"), to deal 12 | * in the Software without restriction, including without limitation the rights 13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | * copies of the Software, and to permit persons to whom the Software is 15 | * furnished to do so, subject to the following conditions: 16 | 17 | * The above copyright notice and this permission notice shall be included in 18 | * all copies or substantial portions of the Software. 19 | 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 26 | * THE SOFTWARE. 27 | **////////////////////////////////////////////////////////////////////////////*/ 28 | ''' 29 | 30 | if len(sys.argv) < 2: 31 | sys.stderr.write('usage: ' + sys.argv[0] + ' file\n' ) 32 | sys.exit(1) 33 | #if len 34 | 35 | with file(sys.argv[1], 'r') as original: data = original.read() 36 | with file(sys.argv[1], 'w') as modified: modified.write(LICENSE + '\n\n' + data) 37 | -------------------------------------------------------------------------------- /ssl_test.cnf: -------------------------------------------------------------------------------- 1 | [ req ] 2 | distinguished_name = req_distinguished_name 3 | prompt = no 4 | [ req_distinguished_name ] 5 | C = IN 6 | ST = KT 7 | L = BL 8 | O = libuv-tls 9 | OU = libuv-tls 10 | CN = DONT USE - test cert for libuv-tls 11 | -------------------------------------------------------------------------------- /tls_engine.h: -------------------------------------------------------------------------------- 1 | 2 | /*////////////////////////////////////////////////////////////////////////////// 3 | 4 | * Copyright (c) 2015 libuv-tls contributors 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 deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * 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 FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | **////////////////////////////////////////////////////////////////////////////*/ 24 | 25 | 26 | #ifndef __UV_TLS_ENGINE_H__ 27 | #define __UV_TLS_ENGINE_H__ 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #include 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | 41 | 42 | 43 | enum uv_tls_state { 44 | STATE_INIT = 0x0 45 | ,STATE_HANDSHAKING = 0x1 46 | ,STATE_IO = 0x2 //read or write mode 47 | ,STATE_CLOSING = 0x4 // This means closed state also 48 | }; 49 | 50 | //TODO: improve the error handling 51 | enum uv_tls_error { 52 | ERR_TLS_ERROR = -1 //use OpenSSL error handling technique for this 53 | ,ERR_TLS_OK 54 | }; 55 | 56 | 57 | typedef struct tls_engine_s tls_engine; 58 | 59 | struct tls_engine_s { 60 | BIO *app_bio_; //Our BIO, All IO should be through this 61 | SSL *ssl; 62 | SSL_CTX *ctx; 63 | BIO *ssl_bio_; //the ssl BIO used only by openSSL 64 | }; 65 | 66 | static tls_engine the_engine; 67 | static tls_engine *ptr_engine; 68 | 69 | 70 | int tls_engine_inhale(char *, char*, int); 71 | 72 | 73 | #ifdef __cplusplus 74 | } 75 | #endif 76 | 77 | #endif 78 | --------------------------------------------------------------------------------