├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── api └── evt_tls.h ├── evt_test.c ├── exp ├── TBD.txt ├── evt.c ├── evt_mbed.c ├── evt_mbed.h ├── evt_openssl.c ├── makefile ├── mbedtls.c ├── test_evt_cfg.c └── test_evt_tls.c ├── mbedtls.c ├── prepend_licence.py ├── queue.h ├── sample └── libuv-tls │ ├── Makefile │ ├── README.md │ ├── libuv │ ├── .gitignore │ ├── .mailmap │ ├── AUTHORS │ ├── CONTRIBUTING.md │ ├── ChangeLog │ ├── LICENSE │ ├── MAINTAINERS.md │ ├── Makefile.am │ ├── Makefile.mingw │ ├── README.md │ ├── android-configure │ ├── appveyor.yml │ ├── 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 │ │ │ ├── sphinx-plugins │ │ │ └── manpage.py │ │ │ ├── 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 │ │ │ └── version.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.nsi │ ├── 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-homedir.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-connect-multiple.c │ │ ├── test-pipe-connect-prepare.c │ │ ├── test-pipe-getsockname.c │ │ ├── test-pipe-pending-instances.c │ │ ├── test-pipe-sendmsg.c │ │ ├── test-pipe-server-close.c │ │ ├── test-pipe-set-non-blocking.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-create-socket-early.c │ │ ├── test-tcp-flags.c │ │ ├── test-tcp-oob.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-fail.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-create-socket-early.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 │ ├── test_tls.c │ ├── tls_client_test.c │ ├── uv_tls.c │ └── uv_tls.h ├── src └── evt_tls.c └── ssl_test.cnf /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Libraries 12 | *.lib 13 | *.a 14 | *.la 15 | *.lo 16 | 17 | # Shared objects (inc. Windows DLLs) 18 | *.dll 19 | *.so 20 | *.so.* 21 | *.dylib 22 | 23 | # Executables 24 | *.exe 25 | *.out 26 | *.app 27 | *.i*86 28 | *.x86_64 29 | *.hex 30 | 31 | # Debug files 32 | *.dSYM/ 33 | 34 | #crtf and key 35 | *.pem 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Devchandra M. Leishangthem 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: clean test_evt gen_cert test 2 | 3 | #This target needs libuv to be built, check www.libuv.org for building it 4 | evt: 5 | make -C sample/libuv-tls evt 6 | 7 | gen_cert: 8 | openssl req -x509 -newkey rsa:2048 -nodes -keyout server-key.pem \ 9 | -out server-cert.pem -config ssl_test.cnf 10 | -cp -rf server-cert.pem server-key.pem sample/libuv-tls/ 11 | 12 | test_evt: 13 | $(CC) -g -Wall -o $@ -Iapi -I./ evt_test.c src/evt_tls.c -lssl -lcrypto -lrt 14 | test_mevt: 15 | $(CC) -g -Wall -o $@ -Iapi -I./atls/include -L./atls/library mbedtls.c -lmbedtls -lmbedx509 -lmbedcrypto \ 16 | -L/usr/lib/x86_64-linux-gnu 17 | 18 | test: 19 | ./test_evt 20 | 21 | clean: 22 | make -C sample/libuv-tls clean 23 | -rm test_evt 24 | -------------------------------------------------------------------------------- /exp/TBD.txt: -------------------------------------------------------------------------------- 1 | 1) revisit the default config implementation 2 | 2) revisit the configuration part 3 | -------------------------------------------------------------------------------- /exp/evt.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | 5 | int main() 6 | { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /exp/makefile: -------------------------------------------------------------------------------- 1 | 2 | all: evt 3 | 4 | evt: mbed mtls 5 | #$(CC) -g -Wall -I./ -Imbedtls/include evt.c 6 | $(CC) -o $@ -g -Wall evt_openssl.c -lcrypto -lpthread -lssl -lrt 7 | 8 | mbed: 9 | $(CC) -o $@ -g evt_mbed.c test_evt_cfg.c -I../mbedtls/include \ 10 | -L ../mbedtls/library -lmbedtls -lmbedx509 -lmbedcrypto 11 | 12 | mtls: 13 | $(CC) -o $@ -g evt_mbed.c test_evt_tls.c -I../mbedtls/include \ 14 | -L ../mbedtls/library -lmbedtls -lmbedx509 -lmbedcrypto 15 | 16 | 17 | 18 | clean: 19 | -rm evt 20 | -rm mbed 21 | -rm mtls 22 | -------------------------------------------------------------------------------- /exp/test_evt_cfg.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "evt_mbed.h" 9 | 10 | int main() 11 | { 12 | evt_config_t *cfg = NULL; 13 | 14 | cfg = evt_default_cfg(); 15 | assert(cfg != NULL && "test failed"); 16 | // assert( cfg == evt_default && "test failed"); 17 | assert( 1 == cfg->use_count && "test failed"); 18 | assert( (cfg->verify_peer == EVT_VERIFY_REQUIRED) && "test failed"); 19 | assert( (cfg->transport == EVT_IS_TLS) && "test failed"); 20 | assert( (cfg->protocols == EVT_TLS_DEFAULT_PROTOCOL) && "test failed"); 21 | assert( (strcasecmp(cfg->ciphers, "TLS1.2") == 0) && "test failed"); 22 | 23 | cfg = evt_cfg_new(); 24 | assert(cfg != NULL && "test failed"); 25 | // assert( cfg != evt_default && "test failed"); 26 | assert( 1 == cfg->use_count && "test failed"); 27 | assert( (cfg->verify_peer == EVT_VERIFY_REQUIRED) && "test failed"); 28 | assert( (cfg->transport == EVT_IS_TLS) && "test failed"); 29 | assert( (cfg->protocols == EVT_TLS_DEFAULT_PROTOCOL) && "test failed"); 30 | assert( (strcasecmp(cfg->ciphers, "TLS1.2") == 0) && "test failed"); 31 | 32 | evt_cfg_del(cfg); 33 | 34 | //test the same thing after calling evt_init() 35 | assert( evt_init() == 0 && "test failed"); 36 | 37 | cfg = evt_default_cfg(); 38 | assert(cfg != NULL && "test failed"); 39 | // assert( cfg == evt_default && "test failed"); 40 | assert( 1 == cfg->use_count && "test failed"); 41 | assert( (cfg->verify_peer == EVT_VERIFY_REQUIRED) && "test failed"); 42 | assert( (cfg->transport == EVT_IS_TLS) && "test failed"); 43 | assert( (cfg->protocols == EVT_TLS_DEFAULT_PROTOCOL) && "test failed"); 44 | assert( (strcasecmp(cfg->ciphers, "TLS1.2") == 0) && "test failed"); 45 | 46 | cfg = evt_cfg_new(); 47 | assert(cfg != NULL && "test failed"); 48 | // assert( cfg != evt_default && "test failed"); 49 | assert( 1 == cfg->use_count && "test failed"); 50 | assert( (cfg->verify_peer == EVT_VERIFY_REQUIRED) && "test failed"); 51 | assert( (cfg->transport == EVT_IS_TLS) && "test failed"); 52 | assert( (cfg->protocols == EVT_TLS_DEFAULT_PROTOCOL) && "test failed"); 53 | assert( (strcasecmp(cfg->ciphers, "TLS1.2") == 0) && "test failed"); 54 | 55 | evt_cfg_del(cfg); 56 | 57 | printf("Test passed\n"); 58 | } 59 | -------------------------------------------------------------------------------- /exp/test_evt_tls.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "evt_mbed.h" 5 | 6 | void on_handshake(evt_tls_t *tls, int status) 7 | { 8 | fprintf(stderr, "on handshake called\n"); 9 | } 10 | 11 | 12 | int main() 13 | { 14 | evt_config_t *cfg = evt_cfg_new(); 15 | evt_tls_t *client = evt_tls_client(); 16 | assert( client != NULL && "Test failed"); 17 | assert( client->role == ENDPT_IS_CLIENT && "Test failed"); 18 | if ( evt_configure( client, cfg) != 0 ) { 19 | goto err; 20 | } 21 | 22 | evt_tls_t *server = evt_tls_server(); 23 | assert( server != NULL && "Test failed"); 24 | assert( server->role == ENDPT_IS_SERVER && "Test failed"); 25 | 26 | if ( evt_configure( server, cfg) != 0 ) { 27 | goto err; 28 | } 29 | 30 | if ( evt_tls_handshake(client, on_handshake) != 0 ) 31 | { 32 | goto err; 33 | } 34 | 35 | if (evt_tls_handshake(server, on_handshake) != 0 ) { 36 | goto err; 37 | } 38 | 39 | fprintf(stdout, "Test passed\n"); 40 | return 0; 41 | 42 | err: 43 | fprintf(stderr, "Test failed\n"); 44 | } 45 | -------------------------------------------------------------------------------- /prepend_licence.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import sys 3 | 4 | LICENSE = ''' 5 | //%LICENSE//////////////////////////////////////////////////////////////////// 6 | // 7 | // Copyright (c) 2015 Devchandra M. Leishangthem (dlmeetei at gmail dot com) 8 | // 9 | // Distributed under the MIT License (See accompanying file LICENSE) 10 | // 11 | ////////////////////////////////////////////////////////////////////////// 12 | // 13 | //%/////////////////////////////////////////////////////////////////////////// 14 | ''' 15 | 16 | if len(sys.argv) < 2: 17 | sys.stderr.write('usage: ' + sys.argv[0] + ' file\n' ) 18 | sys.exit(1) 19 | #if len 20 | 21 | with file(sys.argv[1], 'r') as original: data = original.read() 22 | with file(sys.argv[1], 'w') as modified: modified.write(LICENSE + '\n' + data) 23 | -------------------------------------------------------------------------------- /sample/libuv-tls/Makefile: -------------------------------------------------------------------------------- 1 | ROOT = ../../ 2 | LIB_2_LINK = \ 3 | -lssl \ 4 | -lcrypto \ 5 | -lrt \ 6 | libuv/out/Debug/libuv.a \ 7 | -ldl \ 8 | -lpthread \ 9 | 10 | all:evt client 11 | 12 | evt: 13 | cd libuv && python gyp_uv.py 14 | make -C ./libuv/out 15 | $(CC) -g -Wall -o $@ -I$(ROOT) -I$(ROOT)/api test_tls.c $(ROOT)/src/evt_tls.c uv_tls.c $(LIB_2_LINK) 16 | 17 | client: 18 | cd libuv && python gyp_uv.py 19 | make -C ./libuv/out 20 | $(CC) -g -Wall -o $@ -I$(ROOT) -I $(ROOT)/api tls_client_test.c $(ROOT)/src/evt_tls.c uv_tls.c $(LIB_2_LINK) 21 | 22 | 23 | clean: 24 | -rm -fv evt 25 | -rm -fv client 26 | -------------------------------------------------------------------------------- /sample/libuv-tls/README.md: -------------------------------------------------------------------------------- 1 | The code in this folder are meant for evt-tls integration demo with libuv and not to be used for production. 2 | It exhibit similar looking APIs as that of libuv but does not mean it is the best approach to evt-tls. You 3 | can use the evt-tls with libuv or plain non blocking socket or any other library like libev 4 | 5 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | # Clion / IntelliJ project files 69 | /.idea/ 70 | 71 | *.xcodeproj 72 | *.xcworkspace 73 | 74 | # make dist output 75 | libuv-*.tar.* 76 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | Devchandra Meetei Leishangthem 12 | Fedor Indutny 13 | Frank Denis 14 | Isaac Z. Schlueter 15 | Jason Williams 16 | Justin Venus 17 | Keno Fischer 18 | Keno Fischer 19 | Leith Bade 20 | Leonard Hecker 21 | Maciej Małecki 22 | Marc Schlaich 23 | Michael 24 | Michael Neumann 25 | Rasmus Christian Pedersen 26 | Rasmus Christian Pedersen 27 | Robert Mustacchi 28 | Ryan Dahl 29 | Ryan Emery 30 | Sam Roberts 31 | San-Tai Hsu 32 | Santiago Gimeno 33 | Saúl Ibarra Corretgé 34 | Shigeki Ohtsu 35 | Timothy J. Fontaine 36 | Yasuhiro Matsumoto 37 | Yazhong Liu 38 | Yuki Okumura 39 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/libuv/MAINTAINERS.md: -------------------------------------------------------------------------------- 1 | 2 | # Project Maintainers 3 | 4 | libuv is currently managed by the following individuals: 5 | 6 | * **Ben Noordhuis** ([@bnoordhuis](https://github.com/bnoordhuis)) 7 | - GPG key: D77B 1E34 243F BAF0 5F8E 9CC3 4F55 C8C8 46AB 89B9 (pubkey-bnoordhuis) 8 | * **Bert Belder** ([@piscisaureus](https://github.com/piscisaureus)) 9 | * **Fedor Indutny** ([@indutny](https://github.com/indutny)) 10 | - GPG key: AF2E EA41 EC34 47BF DD86 FED9 D706 3CCE 19B7 E890 (pubkey-indutny) 11 | * **Saúl Ibarra Corretgé** ([@saghul](https://github.com/saghul)) 12 | - GPG key: FDF5 1936 4458 319F A823 3DC9 410E 5553 AE9B C059 (pubkey-saghul) 13 | 14 | ## Storing a maintainer key in Git 15 | 16 | It's quite handy to store a maintainer's signature as a git blob, and have 17 | that object tagged and signed with such key. 18 | 19 | Export your public key: 20 | 21 | $ gpg --armor --export saghul@gmail.com > saghul.asc 22 | 23 | Store it as a blob on the repo: 24 | 25 | $ git hash-object -w saghul.asc 26 | 27 | The previous command returns a hash, copy it. For the sake of this explanation, 28 | we'll assume it's 'abcd1234'. Storing the blob in git is not enough, it could 29 | be garbage collected since nothing references it, so we'll create a tag for it: 30 | 31 | $ git tag -s pubkey-saghul abcd1234 32 | 33 | Commit the changes and push: 34 | 35 | $ git push origin pubkey-saghul 36 | 37 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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-21 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 -f make-android 20 | fi 21 | -------------------------------------------------------------------------------- /sample/libuv-tls/libuv/appveyor.yml: -------------------------------------------------------------------------------- 1 | version: v1.7.5.build{build} 2 | 3 | install: 4 | - cinst -y nsis 5 | 6 | matrix: 7 | fast_finish: true 8 | allow_failures: 9 | - platform: x86 10 | configuration: Release 11 | - platform: x64 12 | configuration: Release 13 | 14 | platform: 15 | - x86 16 | - x64 17 | 18 | configuration: 19 | - Release 20 | 21 | build_script: 22 | # Fixed tag version number if using a tag. 23 | - cmd: if "%APPVEYOR_REPO_TAG%" == "true" set APPVEYOR_BUILD_VERSION=%APPVEYOR_REPO_TAG_NAME% 24 | # vcbuild overwrites the platform variable. 25 | - cmd: set ARCH=%platform% 26 | - cmd: vcbuild.bat release %ARCH% shared 27 | 28 | after_build: 29 | - '"%PROGRAMFILES(x86)%\NSIS\makensis" /DVERSION=%APPVEYOR_BUILD_VERSION% /DARCH=%ARCH% libuv.nsi' 30 | 31 | artifacts: 32 | - name: Installer 33 | path: 'libuv-*.exe' 34 | 35 | cache: 36 | - C:\projects\libuv\build\gyp 37 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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* loop, 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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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:: int 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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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* buffer, size_t* size) 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, `buffer` will contain the path and `size` 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 | .. versionchanged:: 1.3.0 the returned length no longer includes the terminating null byte, 70 | and the buffer is not null terminated. 71 | 72 | .. seealso:: The :c:type:`uv_handle_t` API functions also apply. 73 | -------------------------------------------------------------------------------- /sample/libuv-tls/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* loop, 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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | version 72 | loop 73 | handle 74 | request 75 | timer 76 | prepare 77 | check 78 | idle 79 | async 80 | poll 81 | signal 82 | process 83 | stream 84 | tcp 85 | pipe 86 | tty 87 | udp 88 | fs_event 89 | fs_poll 90 | fs 91 | threadpool 92 | dns 93 | dll 94 | threading 95 | misc 96 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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_req_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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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* loop, 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 | -------------------------------------------------------------------------------- /sample/libuv-tls/libuv/docs/src/sphinx-plugins/manpage.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | # 4 | # Copyright (c) 2013 Dariusz Dwornikowski. All rights reserved. 5 | # 6 | # Adapted from https://github.com/tdi/sphinxcontrib-manpage 7 | # License: Apache 2 8 | # 9 | 10 | 11 | import re 12 | 13 | from docutils import nodes, utils 14 | from docutils.parsers.rst.roles import set_classes 15 | from string import Template 16 | 17 | 18 | def make_link_node(rawtext, app, name, manpage_num, options): 19 | ref = app.config.man_url_regex 20 | if not ref: 21 | ref = "http://linux.die.net/man/%s/%s" % (manpage_num, name) 22 | else: 23 | s = Template(ref) 24 | ref = s.substitute(num=manpage_num, topic=name) 25 | set_classes(options) 26 | node = nodes.reference(rawtext, "%s(%s)" % (name, manpage_num), refuri=ref, **options) 27 | return node 28 | 29 | 30 | def man_role(name, rawtext, text, lineno, inliner, options={}, content=[]): 31 | app = inliner.document.settings.env.app 32 | p = re.compile("([a-zA-Z0-9_\.-_]+)\((\d)\)") 33 | m = p.match(text) 34 | 35 | manpage_num = m.group(2) 36 | name = m.group(1) 37 | node = make_link_node(rawtext, app, name, manpage_num, options) 38 | return [node], [] 39 | 40 | 41 | def setup(app): 42 | app.info('Initializing manpage plugin') 43 | app.add_role('man', man_role) 44 | app.add_config_value('man_url_regex', None, 'env') 45 | return 46 | 47 | -------------------------------------------------------------------------------- /sample/libuv-tls/libuv/docs/src/static/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deleisha/evt-tls/ba53a3bebc1cf8d3e93d828bc6c7da0f0ce61fdd/sample/libuv-tls/libuv/docs/src/static/architecture.png -------------------------------------------------------------------------------- /sample/libuv-tls/libuv/docs/src/static/diagrams.key/Data/st0-311.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deleisha/evt-tls/ba53a3bebc1cf8d3e93d828bc6c7da0f0ce61fdd/sample/libuv-tls/libuv/docs/src/static/diagrams.key/Data/st0-311.jpg -------------------------------------------------------------------------------- /sample/libuv-tls/libuv/docs/src/static/diagrams.key/Data/st1-475.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deleisha/evt-tls/ba53a3bebc1cf8d3e93d828bc6c7da0f0ce61fdd/sample/libuv-tls/libuv/docs/src/static/diagrams.key/Data/st1-475.jpg -------------------------------------------------------------------------------- /sample/libuv-tls/libuv/docs/src/static/diagrams.key/Index.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deleisha/evt-tls/ba53a3bebc1cf8d3e93d828bc6c7da0f0ce61fdd/sample/libuv-tls/libuv/docs/src/static/diagrams.key/Index.zip -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/libuv/docs/src/static/diagrams.key/Metadata/DocumentIdentifier: -------------------------------------------------------------------------------- 1 | F69E9CD9-EEF1-4223-9DA4-A1EA7FE112BA -------------------------------------------------------------------------------- /sample/libuv-tls/libuv/docs/src/static/diagrams.key/Metadata/Properties.plist: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deleisha/evt-tls/ba53a3bebc1cf8d3e93d828bc6c7da0f0ce61fdd/sample/libuv-tls/libuv/docs/src/static/diagrams.key/Metadata/Properties.plist -------------------------------------------------------------------------------- /sample/libuv-tls/libuv/docs/src/static/diagrams.key/preview-micro.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deleisha/evt-tls/ba53a3bebc1cf8d3e93d828bc6c7da0f0ce61fdd/sample/libuv-tls/libuv/docs/src/static/diagrams.key/preview-micro.jpg -------------------------------------------------------------------------------- /sample/libuv-tls/libuv/docs/src/static/diagrams.key/preview-web.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deleisha/evt-tls/ba53a3bebc1cf8d3e93d828bc6c7da0f0ce61fdd/sample/libuv-tls/libuv/docs/src/static/diagrams.key/preview-web.jpg -------------------------------------------------------------------------------- /sample/libuv-tls/libuv/docs/src/static/diagrams.key/preview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deleisha/evt-tls/ba53a3bebc1cf8d3e93d828bc6c7da0f0ce61fdd/sample/libuv-tls/libuv/docs/src/static/diagrams.key/preview.jpg -------------------------------------------------------------------------------- /sample/libuv-tls/libuv/docs/src/static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deleisha/evt-tls/ba53a3bebc1cf8d3e93d828bc6c7da0f0ce61fdd/sample/libuv-tls/libuv/docs/src/static/favicon.ico -------------------------------------------------------------------------------- /sample/libuv-tls/libuv/docs/src/static/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deleisha/evt-tls/ba53a3bebc1cf8d3e93d828bc6c7da0f0ce61fdd/sample/libuv-tls/libuv/docs/src/static/logo.png -------------------------------------------------------------------------------- /sample/libuv-tls/libuv/docs/src/static/loop_iteration.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deleisha/evt-tls/ba53a3bebc1cf8d3e93d828bc6c7da0f0ce61fdd/sample/libuv-tls/libuv/docs/src/static/loop_iteration.png -------------------------------------------------------------------------------- /sample/libuv-tls/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. When a particular 16 | function makes use of the threadpool (i.e. when using :c:func:`uv_queue_work`) 17 | libuv preallocates and initializes the maximum number of threads allowed by 18 | ``UV_THREADPOOL_SIZE``. This causes a relatively minor memory overhead 19 | (~1MB for 128 threads) but increases the performance of threading at runtime. 20 | 21 | .. note:: 22 | Note that even though a global thread pool which is shared across all events 23 | loops is used, the functions are not thread safe. 24 | 25 | 26 | Data types 27 | ---------- 28 | 29 | .. c:type:: uv_work_t 30 | 31 | Work request type. 32 | 33 | .. c:type:: void (*uv_work_cb)(uv_work_t* req) 34 | 35 | Callback passed to :c:func:`uv_queue_work` which will be run on the thread 36 | pool. 37 | 38 | .. c:type:: void (*uv_after_work_cb)(uv_work_t* req, int status) 39 | 40 | Callback passed to :c:func:`uv_queue_work` which will be called on the loop 41 | thread after the work on the threadpool has been completed. If the work 42 | was cancelled using :c:func:`uv_cancel` `status` will be ``UV_ECANCELED``. 43 | 44 | 45 | Public members 46 | ^^^^^^^^^^^^^^ 47 | 48 | .. c:member:: uv_loop_t* uv_work_t.loop 49 | 50 | Loop that started this request and where completion will be reported. 51 | Readonly. 52 | 53 | .. seealso:: The :c:type:`uv_req_t` members also apply. 54 | 55 | 56 | API 57 | --- 58 | 59 | .. 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) 60 | 61 | Initializes a work request which will run the given `work_cb` in a thread 62 | from the threadpool. Once `work_cb` is completed, `after_work_cb` will be 63 | called on the loop thread. 64 | 65 | This request can be cancelled with :c:func:`uv_cancel`. 66 | 67 | .. seealso:: The :c:type:`uv_req_t` API functions also apply. 68 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 interval value in milliseconds. The timer will be scheduled 58 | to run on the given interval, regardless of the callback execution 59 | duration, and will follow normal timer semantics in the case of a 60 | time-slice overrun. 61 | 62 | For example, if a 50ms repeating timer first runs for 17ms, it will be 63 | scheduled to run again 33ms later. If other tasks consume more than the 64 | 33ms following the first timer callback, then the callback will run as soon 65 | as possible. 66 | 67 | .. note:: 68 | If the repeat value is set from a timer callback it does not immediately take effect. 69 | If the timer was non-repeating before, it will have been stopped. If it was repeating, 70 | then the old repeat value will have been used to schedule the next timeout. 71 | 72 | .. c:function:: uint64_t uv_timer_get_repeat(const uv_timer_t* handle) 73 | 74 | Get the timer repeat value. 75 | 76 | .. seealso:: The :c:type:`uv_handle_t` API functions also apply. 77 | -------------------------------------------------------------------------------- /sample/libuv-tls/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* loop, uv_tty_t* handle, 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 62 | file descriptor refers to a TTY. This lets libuv put the tty in non-blocking 63 | mode without affecting other processes that share the tty. 64 | 65 | .. note:: 66 | If opening ``/dev/tty`` fails, libuv falls back to blocking writes for 67 | non-readable TTY streams. 68 | 69 | .. versionchanged:: 1.5.0: trying to initialize a TTY stream with a file 70 | descriptor that refers to a file returns `UV_EINVAL` 71 | on UNIX. 72 | 73 | .. c:function:: int uv_tty_set_mode(uv_tty_t* handle, uv_tty_mode_t mode) 74 | 75 | .. versionchanged:: 1.2.0: the mode is specified as a 76 | :c:type:`uv_tty_mode_t` value. 77 | 78 | Set the TTY using the specified terminal mode. 79 | 80 | .. c:function:: int uv_tty_reset_mode(void) 81 | 82 | To be called when the program exits. Resets TTY settings to default 83 | values for the next process to take over. 84 | 85 | This function is async signal-safe on Unix platforms but can fail with error 86 | code ``UV_EBUSY`` if you call it when execution is inside 87 | :c:func:`uv_tty_set_mode`. 88 | 89 | .. c:function:: int uv_tty_get_winsize(uv_tty_t* handle, int* width, int* height) 90 | 91 | Gets the current Window size. On success it returns 0. 92 | 93 | .. seealso:: The :c:type:`uv_stream_t` API functions also apply. 94 | -------------------------------------------------------------------------------- /sample/libuv-tls/libuv/docs/src/version.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _version: 3 | 4 | Version-checking macros and functions 5 | ===================================== 6 | 7 | Starting with version 1.0.0 libuv follows the `semantic versioning`_ 8 | scheme. This means that new APIs can be introduced throughout the lifetime of 9 | a major release. In this section you'll find all macros and functions that 10 | will allow you to write or compile code conditionally, in order to work with 11 | multiple libuv versions. 12 | 13 | .. _semantic versioning: http://semver.org 14 | 15 | 16 | Macros 17 | ------ 18 | 19 | .. c:macro:: UV_VERSION_MAJOR 20 | 21 | libuv version's major number. 22 | 23 | .. c:macro:: UV_VERSION_MINOR 24 | 25 | libuv version's minor number. 26 | 27 | .. c:macro:: UV_VERSION_PATCH 28 | 29 | libuv version's patch number. 30 | 31 | .. c:macro:: UV_VERSION_IS_RELEASE 32 | 33 | Set to 1 to indicate a release version of libuv, 0 for a development 34 | snapshot. 35 | 36 | .. c:macro:: UV_VERSION_SUFFIX 37 | 38 | libuv version suffix. Certain development releases such as Release Candidates 39 | might have a suffix such as "rc". 40 | 41 | .. c:macro:: UV_VERSION_HEX 42 | 43 | Returns the libuv version packed into a single integer. 8 bits are used for 44 | each component, with the patch number stored in the 8 least significant 45 | bits. E.g. for libuv 1.2.3 this would be 0x010203. 46 | 47 | .. versionadded:: 1.7.0 48 | 49 | 50 | Functions 51 | --------- 52 | 53 | .. c:function:: unsigned int uv_version(void) 54 | 55 | Returns :c:macro:`UV_VERSION_HEX`. 56 | 57 | .. c:function:: const char* uv_version_string(void) 58 | 59 | Returns the libuv version number as a string. For non-release versions the 60 | version suffix is included. 61 | -------------------------------------------------------------------------------- /sample/libuv-tls/libuv/img/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deleisha/evt-tls/ba53a3bebc1cf8d3e93d828bc6c7da0f0ce61fdd/sample/libuv-tls/libuv/img/banner.png -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 7 35 | #define UV_VERSION_PATCH 5 36 | #define UV_VERSION_IS_RELEASE 1 37 | #define UV_VERSION_SUFFIX "" 38 | 39 | #define UV_VERSION_HEX ((UV_VERSION_MAJOR << 16) | \ 40 | (UV_VERSION_MINOR << 8) | \ 41 | (UV_VERSION_PATCH)) 42 | 43 | #endif /* UV_VERSION_H */ 44 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/libuv/m4/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore libtoolize-generated files. 2 | *.m4 3 | !as_case.m4 4 | !libuv-check-flags.m4 5 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | #elif defined(_AIX) && defined(__xlC__) 37 | const int out = (*(volatile int*) ptr); 38 | __compare_and_swap(ptr, &oldval, newval); 39 | return out; 40 | #else 41 | return __sync_val_compare_and_swap(ptr, oldval, newval); 42 | #endif 43 | } 44 | 45 | UV_UNUSED(static long cmpxchgl(long* ptr, long oldval, long newval)) { 46 | #if defined(__i386__) || defined(__x86_64__) 47 | long out; 48 | __asm__ __volatile__ ("lock; cmpxchg %2, %1;" 49 | : "=a" (out), "+m" (*(volatile long*) ptr) 50 | : "r" (newval), "0" (oldval) 51 | : "memory"); 52 | return out; 53 | #elif defined(_AIX) && defined(__xlC__) 54 | const long out = (*(volatile int*) ptr); 55 | # if defined(__64BIT__) 56 | __compare_and_swaplp(ptr, &oldval, newval); 57 | # else 58 | __compare_and_swap(ptr, &oldval, newval); 59 | # endif /* if defined(__64BIT__) */ 60 | return out; 61 | #else 62 | return __sync_val_compare_and_swap(ptr, oldval, newval); 63 | #endif 64 | } 65 | 66 | UV_UNUSED(static void cpu_relax(void)) { 67 | #if defined(__i386__) || defined(__x86_64__) 68 | __asm__ __volatile__ ("rep; nop"); /* a.k.a. PAUSE */ 69 | #endif 70 | } 71 | 72 | #endif /* UV_ATOMIC_OPS_H_ */ 73 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | uv__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 | uv__free(lib->errmsg); 72 | 73 | errmsg = dlerror(); 74 | 75 | if (errmsg) { 76 | lib->errmsg = uv__strdup(errmsg); 77 | return -1; 78 | } 79 | else { 80 | lib->errmsg = NULL; 81 | return 0; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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_STRINGIFY(v) UV_STRINGIFY_HELPER(v) 25 | #define UV_STRINGIFY_HELPER(v) #v 26 | 27 | #define UV_VERSION_STRING_BASE UV_STRINGIFY(UV_VERSION_MAJOR) "." \ 28 | UV_STRINGIFY(UV_VERSION_MINOR) "." \ 29 | UV_STRINGIFY(UV_VERSION_PATCH) 30 | 31 | #if UV_VERSION_IS_RELEASE 32 | # define UV_VERSION_STRING UV_VERSION_STRING_BASE 33 | #else 34 | # define UV_VERSION_STRING UV_VERSION_STRING_BASE "-" UV_VERSION_SUFFIX 35 | #endif 36 | 37 | 38 | unsigned int uv_version(void) { 39 | return UV_VERSION_HEX; 40 | } 41 | 42 | 43 | const char* uv_version_string(void) { 44 | return UV_VERSION_STRING; 45 | } 46 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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->stream.conn.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->stream.conn.shutdown_req = NULL; 53 | } 54 | 55 | 56 | #endif /* UV_WIN_STREAM_INL_H_ */ 57 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | fprintf(stderr, "getaddrinfo: %.0f req/s\n", 87 | (double) calls_completed / (double) (end_time - start_time) * 1000.0); 88 | fflush(stderr); 89 | 90 | MAKE_VALGRIND_HAPPY(); 91 | return 0; 92 | } 93 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | fprintf(stderr, "loop_count: %d ticks in %.2fs (%.0f/s)\n", 66 | NUM_TICKS, 67 | ns / 1e9, 68 | NUM_TICKS / (ns / 1e9)); 69 | fflush(stderr); 70 | 71 | MAKE_VALGRIND_HAPPY(); 72 | return 0; 73 | } 74 | 75 | 76 | BENCHMARK_IMPL(loop_count_timed) { 77 | uv_loop_t* loop = uv_default_loop(); 78 | 79 | uv_idle_init(loop, &idle_handle); 80 | uv_idle_start(&idle_handle, idle2_cb); 81 | 82 | uv_timer_init(loop, &timer_handle); 83 | uv_timer_start(&timer_handle, timer_cb, 5000, 0); 84 | 85 | uv_run(loop, UV_RUN_DEFAULT); 86 | 87 | fprintf(stderr, "loop_count: %lu ticks (%.0f ticks/s)\n", ticks, ticks / 5.0); 88 | fflush(stderr); 89 | 90 | MAKE_VALGRIND_HAPPY(); 91 | return 0; 92 | } 93 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | fprintf(stderr, "%.2f seconds total\n", (after_all - before_all) / 1e9); 79 | fprintf(stderr, "%.2f seconds init\n", (before_run - before_all) / 1e9); 80 | fprintf(stderr, "%.2f seconds dispatch\n", (after_run - before_run) / 1e9); 81 | fprintf(stderr, "%.2f seconds cleanup\n", (after_all - after_run) / 1e9); 82 | fflush(stderr); 83 | 84 | MAKE_VALGRIND_HAPPY(); 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | fprintf(stderr, "uv_shutdown_t: %u bytes\n", (unsigned int) sizeof(uv_shutdown_t)); 28 | fprintf(stderr, "uv_write_t: %u bytes\n", (unsigned int) sizeof(uv_write_t)); 29 | fprintf(stderr, "uv_connect_t: %u bytes\n", (unsigned int) sizeof(uv_connect_t)); 30 | fprintf(stderr, "uv_udp_send_t: %u bytes\n", (unsigned int) sizeof(uv_udp_send_t)); 31 | fprintf(stderr, "uv_tcp_t: %u bytes\n", (unsigned int) sizeof(uv_tcp_t)); 32 | fprintf(stderr, "uv_pipe_t: %u bytes\n", (unsigned int) sizeof(uv_pipe_t)); 33 | fprintf(stderr, "uv_tty_t: %u bytes\n", (unsigned int) sizeof(uv_tty_t)); 34 | fprintf(stderr, "uv_prepare_t: %u bytes\n", (unsigned int) sizeof(uv_prepare_t)); 35 | fprintf(stderr, "uv_check_t: %u bytes\n", (unsigned int) sizeof(uv_check_t)); 36 | fprintf(stderr, "uv_idle_t: %u bytes\n", (unsigned int) sizeof(uv_idle_t)); 37 | fprintf(stderr, "uv_async_t: %u bytes\n", (unsigned int) sizeof(uv_async_t)); 38 | fprintf(stderr, "uv_timer_t: %u bytes\n", (unsigned int) sizeof(uv_timer_t)); 39 | fprintf(stderr, "uv_fs_poll_t: %u bytes\n", (unsigned int) sizeof(uv_fs_poll_t)); 40 | fprintf(stderr, "uv_fs_event_t: %u bytes\n", (unsigned int) sizeof(uv_fs_event_t)); 41 | fprintf(stderr, "uv_process_t: %u bytes\n", (unsigned int) sizeof(uv_process_t)); 42 | fprintf(stderr, "uv_poll_t: %u bytes\n", (unsigned int) sizeof(uv_poll_t)); 43 | fprintf(stderr, "uv_loop_t: %u bytes\n", (unsigned int) sizeof(uv_loop_t)); 44 | fflush(stderr); 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/libuv/test/fixtures/empty_file: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deleisha/evt-tls/ba53a3bebc1cf8d3e93d828bc6c7da0f0ce61fdd/sample/libuv-tls/libuv/test/fixtures/empty_file -------------------------------------------------------------------------------- /sample/libuv-tls/libuv/test/fixtures/load_error.node: -------------------------------------------------------------------------------- 1 | foobar 2 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | fprintf(stderr, "Too many arguments.\n"); 45 | fflush(stderr); 46 | return EXIT_FAILURE; 47 | } 48 | 49 | return EXIT_SUCCESS; 50 | } 51 | 52 | 53 | static int maybe_run_test(int argc, char **argv) { 54 | if (strcmp(argv[1], "--list") == 0) { 55 | print_tests(stdout); 56 | return 0; 57 | } 58 | 59 | if (strcmp(argv[1], "spawn_helper") == 0) { 60 | printf("hello world\n"); 61 | return 42; 62 | } 63 | 64 | return run_test(argv[1], 1, 1); 65 | } 66 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/libuv/test/test-homedir.c: -------------------------------------------------------------------------------- 1 | #include "uv.h" 2 | #include "task.h" 3 | #include 4 | 5 | #define PATHMAX 1024 6 | #define SMALLPATH 1 7 | 8 | TEST_IMPL(homedir) { 9 | char homedir[PATHMAX]; 10 | size_t len; 11 | char last; 12 | int r; 13 | 14 | /* Test the normal case */ 15 | len = sizeof homedir; 16 | homedir[0] = '\0'; 17 | ASSERT(strlen(homedir) == 0); 18 | r = uv_os_homedir(homedir, &len); 19 | ASSERT(r == 0); 20 | ASSERT(strlen(homedir) == len); 21 | ASSERT(len > 0); 22 | ASSERT(homedir[len] == '\0'); 23 | 24 | if (len > 1) { 25 | last = homedir[len - 1]; 26 | #ifdef _WIN32 27 | ASSERT(last != '\\'); 28 | #else 29 | ASSERT(last != '/'); 30 | #endif 31 | } 32 | 33 | /* Test the case where the buffer is too small */ 34 | len = SMALLPATH; 35 | r = uv_os_homedir(homedir, &len); 36 | ASSERT(r == UV_ENOBUFS); 37 | ASSERT(len > SMALLPATH); 38 | 39 | /* Test invalid inputs */ 40 | r = uv_os_homedir(NULL, &len); 41 | ASSERT(r == UV_EINVAL); 42 | r = uv_os_homedir(homedir, NULL); 43 | ASSERT(r == UV_EINVAL); 44 | len = 0; 45 | r = uv_os_homedir(homedir, &len); 46 | ASSERT(r == UV_EINVAL); 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/libuv/test/test-pipe-connect-prepare.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2015 Saúl Ibarra Corretgé . 2 | * All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #include "uv.h" 24 | #include "task.h" 25 | #include 26 | #include 27 | 28 | 29 | #ifdef _WIN32 30 | # define BAD_PIPENAME "bad-pipe" 31 | #else 32 | # define BAD_PIPENAME "/path/to/unix/socket/that/really/should/not/be/there" 33 | #endif 34 | 35 | 36 | static int close_cb_called = 0; 37 | static int connect_cb_called = 0; 38 | 39 | static uv_pipe_t pipe_handle; 40 | static uv_prepare_t prepare_handle; 41 | static uv_connect_t conn_req; 42 | 43 | 44 | static void close_cb(uv_handle_t* handle) { 45 | ASSERT(handle != NULL); 46 | close_cb_called++; 47 | } 48 | 49 | 50 | static void connect_cb(uv_connect_t* connect_req, int status) { 51 | ASSERT(status == UV_ENOENT); 52 | connect_cb_called++; 53 | uv_close((uv_handle_t*)&prepare_handle, close_cb); 54 | uv_close((uv_handle_t*)&pipe_handle, close_cb); 55 | } 56 | 57 | 58 | static void prepare_cb(uv_prepare_t* handle) { 59 | ASSERT(handle == &prepare_handle); 60 | uv_pipe_connect(&conn_req, &pipe_handle, BAD_PIPENAME, connect_cb); 61 | } 62 | 63 | 64 | TEST_IMPL(pipe_connect_on_prepare) { 65 | int r; 66 | 67 | r = uv_pipe_init(uv_default_loop(), &pipe_handle, 0); 68 | ASSERT(r == 0); 69 | 70 | r = uv_prepare_init(uv_default_loop(), &prepare_handle); 71 | ASSERT(r == 0); 72 | r = uv_prepare_start(&prepare_handle, prepare_cb); 73 | ASSERT(r == 0); 74 | 75 | r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); 76 | ASSERT(r == 0); 77 | 78 | ASSERT(close_cb_called == 2); 79 | ASSERT(connect_cb_called == 1); 80 | 81 | MAKE_VALGRIND_HAPPY(); 82 | return 0; 83 | } 84 | -------------------------------------------------------------------------------- /sample/libuv-tls/libuv/test/test-pipe-pending-instances.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2015 Saúl Ibarra Corretgé . 2 | * All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #include "uv.h" 24 | #include "task.h" 25 | 26 | 27 | static void connection_cb(uv_stream_t* server, int status) { 28 | ASSERT(0 && "this will never be called"); 29 | } 30 | 31 | 32 | TEST_IMPL(pipe_pending_instances) { 33 | int r; 34 | uv_pipe_t pipe_handle; 35 | uv_loop_t* loop; 36 | 37 | loop = uv_default_loop(); 38 | 39 | r = uv_pipe_init(loop, &pipe_handle, 0); 40 | ASSERT(r == 0); 41 | 42 | uv_pipe_pending_instances(&pipe_handle, 8); 43 | 44 | r = uv_pipe_bind(&pipe_handle, TEST_PIPENAME); 45 | ASSERT(r == 0); 46 | 47 | uv_pipe_pending_instances(&pipe_handle, 16); 48 | 49 | r = uv_listen((uv_stream_t*)&pipe_handle, 128, connection_cb); 50 | ASSERT(r == 0); 51 | 52 | uv_close((uv_handle_t*)&pipe_handle, NULL); 53 | 54 | r = uv_run(loop, UV_RUN_DEFAULT); 55 | ASSERT(r == 0); 56 | 57 | MAKE_VALGRIND_HAPPY(); 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/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 | -------------------------------------------------------------------------------- /sample/libuv-tls/test_tls.c: -------------------------------------------------------------------------------- 1 | //%LICENSE//////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) 2015 Devchandra M. Leishangthem (dlmeetei at gmail dot com) 4 | // 5 | // Distributed under the MIT License (See accompanying file LICENSE) 6 | // 7 | ////////////////////////////////////////////////////////////////////////// 8 | // 9 | //%/////////////////////////////////////////////////////////////////////////// 10 | 11 | #include "uv_tls.h" 12 | #include 13 | 14 | void on_write(uv_tls_t *tls, int status) { 15 | uv_tls_close(tls, (uv_tls_close_cb)free); 16 | } 17 | 18 | void uv_rd_cb( uv_tls_t *strm, ssize_t nrd, const uv_buf_t *bfr) { 19 | if ( nrd <= 0 ) 20 | { 21 | return; 22 | } 23 | uv_tls_write(strm, (uv_buf_t*)bfr, on_write); 24 | } 25 | 26 | void on_uv_handshake(uv_tls_t *ut, int status) { 27 | if ( 0 == status ) 28 | uv_tls_read(ut, uv_rd_cb); 29 | else 30 | uv_tls_close(ut, (uv_tls_close_cb)free); 31 | } 32 | 33 | void on_connect_cb(uv_stream_t *server, int status) { 34 | if( status ) return; 35 | uv_tcp_t *tcp = malloc(sizeof(*tcp)); //freed on uv_close callback 36 | uv_tcp_init(uv_default_loop(), tcp); 37 | if (uv_accept(server, (uv_stream_t*)tcp)) { 38 | return; 39 | } 40 | 41 | uv_tls_t *sclient = malloc(sizeof(*sclient)); //freed on uv_close callback 42 | if( uv_tls_init((evt_ctx_t*)server->data, tcp, sclient) < 0 ) { 43 | free(sclient); 44 | return; 45 | } 46 | uv_tls_accept(sclient, on_uv_handshake); 47 | } 48 | 49 | int main() { 50 | uv_loop_t *loop = uv_default_loop(); 51 | int port = 8000, r = 0; 52 | evt_ctx_t ctx; 53 | struct sockaddr_in bind_local; 54 | 55 | signal(SIGPIPE, SIG_IGN); 56 | evt_ctx_init_ex(&ctx, "server-cert.pem", "server-key.pem"); 57 | evt_ctx_set_nio(&ctx, NULL, uv_tls_writer); 58 | 59 | uv_tcp_t listener_local; 60 | uv_tcp_init(loop, &listener_local); 61 | listener_local.data = &ctx; 62 | uv_ip4_addr("127.0.0.1", port, &bind_local); 63 | if ((r = uv_tcp_bind(&listener_local, (struct sockaddr*)&bind_local, 0))) 64 | fprintf( stderr, "bind: %s\n", uv_strerror(r)); 65 | 66 | if ((r = uv_listen((uv_stream_t*)&listener_local, 128, on_connect_cb))) 67 | fprintf( stderr, "listen: %s\n", uv_strerror(r)); 68 | printf("Listening on %d\n", port); 69 | uv_run(loop, UV_RUN_DEFAULT); 70 | evt_ctx_free(&ctx); 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /sample/libuv-tls/tls_client_test.c: -------------------------------------------------------------------------------- 1 | //%LICENSE//////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) 2015 Devchandra M. Leishangthem (dlmeetei at gmail dot com) 4 | // 5 | // Distributed under the MIT License (See accompanying file LICENSE) 6 | // 7 | ////////////////////////////////////////////////////////////////////////// 8 | // 9 | //%/////////////////////////////////////////////////////////////////////////// 10 | 11 | #include "uv_tls.h" 12 | #include 13 | #include 14 | 15 | void echo_read(uv_tls_t *strm, ssize_t nrd, const uv_buf_t *bfr) 16 | { 17 | if ( nrd <= 0 ) return; 18 | fprintf( stdout, "%s\n", bfr->base); 19 | 20 | uv_tls_close(strm, (uv_tls_close_cb)free); 21 | } 22 | 23 | void on_write(uv_tls_t *utls, int status) 24 | { 25 | assert(utls->tcp_hdl->data == utls); 26 | if (status == -1) { 27 | fprintf(stderr, "error on_write"); 28 | return; 29 | } 30 | 31 | uv_tls_read(utls, echo_read); 32 | } 33 | 34 | void on_tls_handshake(uv_tls_t *tls, int status) 35 | { 36 | assert(tls->tcp_hdl->data == tls); 37 | uv_buf_t dcrypted; 38 | dcrypted.base = "Hello from evt-tls"; 39 | dcrypted.len = strlen(dcrypted.base); 40 | 41 | if ( 0 == status ) // TLS connection not failed 42 | { 43 | uv_tls_write(tls, &dcrypted, on_write); 44 | } 45 | else { 46 | uv_tls_close(tls, (uv_tls_close_cb)free); 47 | } 48 | } 49 | 50 | void on_connect(uv_connect_t *req, int status) 51 | { 52 | // TCP connection error check 53 | if( status ) { 54 | return; 55 | } 56 | 57 | evt_ctx_t *ctx = req->data; 58 | uv_tcp_t *tcp = (uv_tcp_t*)req->handle; 59 | 60 | //free on uv_tls_close 61 | uv_tls_t *sclient = malloc(sizeof(*sclient)); 62 | if( uv_tls_init(ctx, tcp, sclient) < 0 ) { 63 | free(sclient); 64 | return; 65 | } 66 | assert(tcp->data == sclient); 67 | uv_tls_connect(sclient, on_tls_handshake); 68 | } 69 | 70 | 71 | int main() 72 | { 73 | uv_loop_t *loop = uv_default_loop(); 74 | //free on uv_close_cb via uv_tls_close call 75 | uv_tcp_t *client = malloc(sizeof *client); 76 | uv_tcp_init(loop, client); 77 | int port = 8000; 78 | 79 | evt_ctx_t ctx; 80 | evt_ctx_init_ex(&ctx, "server-cert.pem", "server-key.pem"); 81 | evt_ctx_set_nio(&ctx, NULL, uv_tls_writer); 82 | 83 | struct sockaddr_in conn_addr; 84 | uv_ip4_addr("127.0.0.1", port, &conn_addr); 85 | 86 | uv_connect_t req; 87 | req.data = &ctx; 88 | uv_tcp_connect(&req, client,(const struct sockaddr*)&conn_addr,on_connect); 89 | 90 | uv_run(loop, UV_RUN_DEFAULT); 91 | evt_ctx_free(&ctx); 92 | return 0; 93 | } 94 | -------------------------------------------------------------------------------- /sample/libuv-tls/uv_tls.h: -------------------------------------------------------------------------------- 1 | //%LICENSE//////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) 2015 Devchandra M. Leishangthem (dlmeetei at gmail dot com) 4 | // 5 | // Distributed under the MIT License (See accompanying file LICENSE) 6 | // 7 | ////////////////////////////////////////////////////////////////////////// 8 | // 9 | //%/////////////////////////////////////////////////////////////////////////// 10 | 11 | #ifndef UV_TLS_H 12 | #define UV_TLS_H 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | #include "evt_tls.h" 18 | #include "libuv/include/uv.h" 19 | 20 | //copied gladly from libuv 21 | #define CONTAINER_OF(ptr, type, member) \ 22 | ((type *) ((char *) (ptr) - offsetof(type, member))) 23 | 24 | 25 | typedef struct uv_tls_s uv_tls_t; 26 | 27 | typedef void (*uv_handshake_cb)(uv_tls_t*, int); 28 | typedef void (*uv_tls_write_cb)(uv_tls_t*, int); 29 | typedef void (*uv_tls_read_cb)(uv_tls_t*, ssize_t, const uv_buf_t*); 30 | typedef void (*uv_tls_close_cb)(uv_tls_t*); 31 | 32 | struct uv_tls_s { 33 | uv_tcp_t *tcp_hdl; 34 | evt_tls_t *tls; 35 | 36 | uv_tls_read_cb tls_rd_cb; 37 | uv_tls_close_cb tls_cls_cb; 38 | uv_handshake_cb tls_hsk_cb; 39 | uv_tls_write_cb tls_wr_cb; 40 | }; 41 | 42 | //implementation of network writer for libuv using uv_try_write 43 | int uv_tls_writer(evt_tls_t *t, void *bfr, int sz); 44 | 45 | //int uv_tls_init(uv_loop_t *loop, evt_ctx_t *ctx, uv_tls_t *endpt); 46 | int uv_tls_init(evt_ctx_t *ctx, uv_tcp_t *tcp, uv_tls_t *endpt); 47 | 48 | int uv_tls_connect(uv_tls_t *t, uv_handshake_cb cb); 49 | int uv_tls_accept(uv_tls_t *tls, uv_handshake_cb cb); 50 | int uv_tls_read(uv_tls_t *tls, uv_tls_read_cb on_read); 51 | int uv_tls_close(uv_tls_t* session, uv_tls_close_cb close_cb); 52 | 53 | 54 | int uv_tls_write(uv_tls_t *stream, uv_buf_t* buf, uv_tls_write_cb cb); 55 | #ifdef __cplusplus 56 | } 57 | #endif //extern C 58 | 59 | #endif //UV_TLS_H 60 | -------------------------------------------------------------------------------- /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 = evt 9 | OU = evt 10 | CN = DONT USE - test cert for evt-tls 11 | --------------------------------------------------------------------------------