11cb0ef41Sopenharmony_ci![libuv][libuv_banner]
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci## Overview
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_cilibuv is a multi-platform support library with a focus on asynchronous I/O. It
61cb0ef41Sopenharmony_ciwas primarily developed for use by [Node.js][], but it's also
71cb0ef41Sopenharmony_ciused by [Luvit](http://luvit.io/), [Julia](http://julialang.org/),
81cb0ef41Sopenharmony_ci[uvloop](https://github.com/MagicStack/uvloop), and [others](https://github.com/libuv/libuv/blob/v1.x/LINKS.md).
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci## Feature highlights
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci * Full-featured event loop backed by epoll, kqueue, IOCP, event ports.
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci * Asynchronous TCP and UDP sockets
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci * Asynchronous DNS resolution
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci * Asynchronous file and file system operations
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ci * File system events
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci * ANSI escape code controlled TTY
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci * IPC with socket sharing, using Unix domain sockets or named pipes (Windows)
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci * Child processes
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ci * Thread pool
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci * Signal handling
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci * High resolution clock
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci * Threading and synchronization primitives
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci## Versioning
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ciStarting with version 1.0.0 libuv follows the [semantic versioning](http://semver.org/)
391cb0ef41Sopenharmony_cischeme. The API change and backwards compatibility rules are those indicated by
401cb0ef41Sopenharmony_ciSemVer. libuv will keep a stable ABI across major releases.
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ciThe ABI/API changes can be tracked [here](http://abi-laboratory.pro/tracker/timeline/libuv/).
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ci## Licensing
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_cilibuv is licensed under the MIT license. Check the [LICENSE file](LICENSE).
471cb0ef41Sopenharmony_ciThe documentation is licensed under the CC BY 4.0 license. Check the [LICENSE-docs file](LICENSE-docs).
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ci## Community
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ci * [Support](https://github.com/libuv/libuv/discussions)
521cb0ef41Sopenharmony_ci * [Mailing list](http://groups.google.com/group/libuv)
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_ci## Documentation
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_ci### Official documentation
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_ciLocated in the docs/ subdirectory. It uses the [Sphinx](http://sphinx-doc.org/)
591cb0ef41Sopenharmony_ciframework, which makes it possible to build the documentation in multiple
601cb0ef41Sopenharmony_ciformats.
611cb0ef41Sopenharmony_ci
621cb0ef41Sopenharmony_ciShow different supported building options:
631cb0ef41Sopenharmony_ci
641cb0ef41Sopenharmony_ci```bash
651cb0ef41Sopenharmony_ci$ make help
661cb0ef41Sopenharmony_ci```
671cb0ef41Sopenharmony_ci
681cb0ef41Sopenharmony_ciBuild documentation as HTML:
691cb0ef41Sopenharmony_ci
701cb0ef41Sopenharmony_ci```bash
711cb0ef41Sopenharmony_ci$ make html
721cb0ef41Sopenharmony_ci```
731cb0ef41Sopenharmony_ci
741cb0ef41Sopenharmony_ciBuild documentation as HTML and live reload it when it changes (this requires
751cb0ef41Sopenharmony_cisphinx-autobuild to be installed and is only supported on Unix):
761cb0ef41Sopenharmony_ci
771cb0ef41Sopenharmony_ci```bash
781cb0ef41Sopenharmony_ci$ make livehtml
791cb0ef41Sopenharmony_ci```
801cb0ef41Sopenharmony_ci
811cb0ef41Sopenharmony_ciBuild documentation as man pages:
821cb0ef41Sopenharmony_ci
831cb0ef41Sopenharmony_ci```bash
841cb0ef41Sopenharmony_ci$ make man
851cb0ef41Sopenharmony_ci```
861cb0ef41Sopenharmony_ci
871cb0ef41Sopenharmony_ciBuild documentation as ePub:
881cb0ef41Sopenharmony_ci
891cb0ef41Sopenharmony_ci```bash
901cb0ef41Sopenharmony_ci$ make epub
911cb0ef41Sopenharmony_ci```
921cb0ef41Sopenharmony_ci
931cb0ef41Sopenharmony_ciNOTE: Windows users need to use make.bat instead of plain 'make'.
941cb0ef41Sopenharmony_ci
951cb0ef41Sopenharmony_ciDocumentation can be browsed online [here](http://docs.libuv.org).
961cb0ef41Sopenharmony_ci
971cb0ef41Sopenharmony_ciThe [tests and benchmarks](https://github.com/libuv/libuv/tree/master/test)
981cb0ef41Sopenharmony_cialso serve as API specification and usage examples.
991cb0ef41Sopenharmony_ci
1001cb0ef41Sopenharmony_ci### Other resources
1011cb0ef41Sopenharmony_ci
1021cb0ef41Sopenharmony_ci * [LXJS 2012 talk](http://www.youtube.com/watch?v=nGn60vDSxQ4)
1031cb0ef41Sopenharmony_ci   — High-level introductory talk about libuv.
1041cb0ef41Sopenharmony_ci * [libuv-dox](https://github.com/thlorenz/libuv-dox)
1051cb0ef41Sopenharmony_ci   — Documenting types and methods of libuv, mostly by reading uv.h.
1061cb0ef41Sopenharmony_ci * [learnuv](https://github.com/thlorenz/learnuv)
1071cb0ef41Sopenharmony_ci   — Learn uv for fun and profit, a self guided workshop to libuv.
1081cb0ef41Sopenharmony_ci
1091cb0ef41Sopenharmony_ciThese resources are not handled by libuv maintainers and might be out of
1101cb0ef41Sopenharmony_cidate. Please verify it before opening new issues.
1111cb0ef41Sopenharmony_ci
1121cb0ef41Sopenharmony_ci## Downloading
1131cb0ef41Sopenharmony_ci
1141cb0ef41Sopenharmony_cilibuv can be downloaded either from the
1151cb0ef41Sopenharmony_ci[GitHub repository](https://github.com/libuv/libuv)
1161cb0ef41Sopenharmony_cior from the [downloads site](http://dist.libuv.org/dist/).
1171cb0ef41Sopenharmony_ci
1181cb0ef41Sopenharmony_ciBefore verifying the git tags or signature files, importing the relevant keys
1191cb0ef41Sopenharmony_ciis necessary. Key IDs are listed in the
1201cb0ef41Sopenharmony_ci[MAINTAINERS](https://github.com/libuv/libuv/blob/master/MAINTAINERS.md)
1211cb0ef41Sopenharmony_cifile, but are also available as git blob objects for easier use.
1221cb0ef41Sopenharmony_ci
1231cb0ef41Sopenharmony_ciImporting a key the usual way:
1241cb0ef41Sopenharmony_ci
1251cb0ef41Sopenharmony_ci```bash
1261cb0ef41Sopenharmony_ci$ gpg --keyserver pool.sks-keyservers.net --recv-keys AE9BC059
1271cb0ef41Sopenharmony_ci```
1281cb0ef41Sopenharmony_ci
1291cb0ef41Sopenharmony_ciImporting a key from a git blob object:
1301cb0ef41Sopenharmony_ci
1311cb0ef41Sopenharmony_ci```bash
1321cb0ef41Sopenharmony_ci$ git show pubkey-saghul | gpg --import
1331cb0ef41Sopenharmony_ci```
1341cb0ef41Sopenharmony_ci
1351cb0ef41Sopenharmony_ci### Verifying releases
1361cb0ef41Sopenharmony_ci
1371cb0ef41Sopenharmony_ciGit tags are signed with the developer's key, they can be verified as follows:
1381cb0ef41Sopenharmony_ci
1391cb0ef41Sopenharmony_ci```bash
1401cb0ef41Sopenharmony_ci$ git verify-tag v1.6.1
1411cb0ef41Sopenharmony_ci```
1421cb0ef41Sopenharmony_ci
1431cb0ef41Sopenharmony_ciStarting with libuv 1.7.0, the tarballs stored in the
1441cb0ef41Sopenharmony_ci[downloads site](http://dist.libuv.org/dist/) are signed and an accompanying
1451cb0ef41Sopenharmony_cisignature file sit alongside each. Once both the release tarball and the
1461cb0ef41Sopenharmony_cisignature file are downloaded, the file can be verified as follows:
1471cb0ef41Sopenharmony_ci
1481cb0ef41Sopenharmony_ci```bash
1491cb0ef41Sopenharmony_ci$ gpg --verify libuv-1.7.0.tar.gz.sign
1501cb0ef41Sopenharmony_ci```
1511cb0ef41Sopenharmony_ci
1521cb0ef41Sopenharmony_ci## Build Instructions
1531cb0ef41Sopenharmony_ci
1541cb0ef41Sopenharmony_ciFor UNIX-like platforms, including macOS, there are two build methods:
1551cb0ef41Sopenharmony_ciautotools or [CMake][].
1561cb0ef41Sopenharmony_ci
1571cb0ef41Sopenharmony_ciFor Windows, [CMake][] is the only supported build method and has the
1581cb0ef41Sopenharmony_cifollowing prerequisites:
1591cb0ef41Sopenharmony_ci
1601cb0ef41Sopenharmony_ci<details>
1611cb0ef41Sopenharmony_ci
1621cb0ef41Sopenharmony_ci* One of:
1631cb0ef41Sopenharmony_ci  * [Visual C++ Build Tools][]
1641cb0ef41Sopenharmony_ci  * [Visual Studio 2015 Update 3][], all editions
1651cb0ef41Sopenharmony_ci    including the Community edition (remember to select
1661cb0ef41Sopenharmony_ci    "Common Tools for Visual C++ 2015" feature during installation).
1671cb0ef41Sopenharmony_ci  * [Visual Studio 2017][], any edition (including the Build Tools SKU).
1681cb0ef41Sopenharmony_ci    **Required Components:** "MSbuild", "VC++ 2017 v141 toolset" and one of the
1691cb0ef41Sopenharmony_ci    Windows SDKs (10 or 8.1).
1701cb0ef41Sopenharmony_ci* Basic Unix tools required for some tests,
1711cb0ef41Sopenharmony_ci  [Git for Windows][] includes Git Bash
1721cb0ef41Sopenharmony_ci  and tools which can be included in the global `PATH`.
1731cb0ef41Sopenharmony_ci
1741cb0ef41Sopenharmony_ci</details>
1751cb0ef41Sopenharmony_ci
1761cb0ef41Sopenharmony_ciTo build with autotools:
1771cb0ef41Sopenharmony_ci
1781cb0ef41Sopenharmony_ci```bash
1791cb0ef41Sopenharmony_ci$ sh autogen.sh
1801cb0ef41Sopenharmony_ci$ ./configure
1811cb0ef41Sopenharmony_ci$ make
1821cb0ef41Sopenharmony_ci$ make check
1831cb0ef41Sopenharmony_ci$ make install
1841cb0ef41Sopenharmony_ci```
1851cb0ef41Sopenharmony_ci
1861cb0ef41Sopenharmony_ciTo build with [CMake][]:
1871cb0ef41Sopenharmony_ci
1881cb0ef41Sopenharmony_ci```bash
1891cb0ef41Sopenharmony_ci$ mkdir -p build
1901cb0ef41Sopenharmony_ci
1911cb0ef41Sopenharmony_ci$ (cd build && cmake .. -DBUILD_TESTING=ON) # generate project with tests
1921cb0ef41Sopenharmony_ci$ cmake --build build                       # add `-j <n>` with cmake >= 3.12
1931cb0ef41Sopenharmony_ci
1941cb0ef41Sopenharmony_ci# Run tests:
1951cb0ef41Sopenharmony_ci$ (cd build && ctest -C Debug --output-on-failure)
1961cb0ef41Sopenharmony_ci
1971cb0ef41Sopenharmony_ci# Or manually run tests:
1981cb0ef41Sopenharmony_ci$ build/uv_run_tests                        # shared library build
1991cb0ef41Sopenharmony_ci$ build/uv_run_tests_a                      # static library build
2001cb0ef41Sopenharmony_ci```
2011cb0ef41Sopenharmony_ci
2021cb0ef41Sopenharmony_ciTo cross-compile with [CMake][] (unsupported but generally works):
2031cb0ef41Sopenharmony_ci
2041cb0ef41Sopenharmony_ci```bash
2051cb0ef41Sopenharmony_ci$ cmake ../..                 \
2061cb0ef41Sopenharmony_ci  -DCMAKE_SYSTEM_NAME=Windows \
2071cb0ef41Sopenharmony_ci  -DCMAKE_SYSTEM_VERSION=6.1  \
2081cb0ef41Sopenharmony_ci  -DCMAKE_C_COMPILER=i686-w64-mingw32-gcc
2091cb0ef41Sopenharmony_ci```
2101cb0ef41Sopenharmony_ci
2111cb0ef41Sopenharmony_ci### Install with Homebrew
2121cb0ef41Sopenharmony_ci
2131cb0ef41Sopenharmony_ci```bash
2141cb0ef41Sopenharmony_ci$ brew install --HEAD libuv
2151cb0ef41Sopenharmony_ci```
2161cb0ef41Sopenharmony_ci
2171cb0ef41Sopenharmony_ciNote to OS X users:
2181cb0ef41Sopenharmony_ci
2191cb0ef41Sopenharmony_ciMake sure that you specify the architecture you wish to build for in the
2201cb0ef41Sopenharmony_ci"ARCHS" flag. You can specify more than one by delimiting with a space
2211cb0ef41Sopenharmony_ci(e.g. "x86_64 i386").
2221cb0ef41Sopenharmony_ci
2231cb0ef41Sopenharmony_ci### Running tests
2241cb0ef41Sopenharmony_ci
2251cb0ef41Sopenharmony_ciSome tests are timing sensitive. Relaxing test timeouts may be necessary
2261cb0ef41Sopenharmony_cion slow or overloaded machines:
2271cb0ef41Sopenharmony_ci
2281cb0ef41Sopenharmony_ci```bash
2291cb0ef41Sopenharmony_ci$ env UV_TEST_TIMEOUT_MULTIPLIER=2 build/uv_run_tests # 10s instead of 5s
2301cb0ef41Sopenharmony_ci```
2311cb0ef41Sopenharmony_ci
2321cb0ef41Sopenharmony_ci#### Run one test
2331cb0ef41Sopenharmony_ci
2341cb0ef41Sopenharmony_ciThe list of all tests is in `test/test-list.h`.
2351cb0ef41Sopenharmony_ci
2361cb0ef41Sopenharmony_ciThis invocation will cause the test driver to fork and execute `TEST_NAME` in
2371cb0ef41Sopenharmony_cia child process:
2381cb0ef41Sopenharmony_ci
2391cb0ef41Sopenharmony_ci```bash
2401cb0ef41Sopenharmony_ci$ build/uv_run_tests_a TEST_NAME
2411cb0ef41Sopenharmony_ci```
2421cb0ef41Sopenharmony_ci
2431cb0ef41Sopenharmony_ciThis invocation will cause the test driver to execute the test in
2441cb0ef41Sopenharmony_cithe same process:
2451cb0ef41Sopenharmony_ci
2461cb0ef41Sopenharmony_ci```bash
2471cb0ef41Sopenharmony_ci$ build/uv_run_tests_a TEST_NAME TEST_NAME
2481cb0ef41Sopenharmony_ci```
2491cb0ef41Sopenharmony_ci
2501cb0ef41Sopenharmony_ci#### Debugging tools
2511cb0ef41Sopenharmony_ci
2521cb0ef41Sopenharmony_ciWhen running the test from within the test driver process
2531cb0ef41Sopenharmony_ci(`build/uv_run_tests_a TEST_NAME TEST_NAME`), tools like gdb and valgrind
2541cb0ef41Sopenharmony_ciwork normally.
2551cb0ef41Sopenharmony_ci
2561cb0ef41Sopenharmony_ciWhen running the test from a child of the test driver process
2571cb0ef41Sopenharmony_ci(`build/uv_run_tests_a TEST_NAME`), use these tools in a fork-aware manner.
2581cb0ef41Sopenharmony_ci
2591cb0ef41Sopenharmony_ci##### Fork-aware gdb
2601cb0ef41Sopenharmony_ci
2611cb0ef41Sopenharmony_ciUse the [follow-fork-mode](https://sourceware.org/gdb/onlinedocs/gdb/Forks.html) setting:
2621cb0ef41Sopenharmony_ci
2631cb0ef41Sopenharmony_ci```
2641cb0ef41Sopenharmony_ci$ gdb --args build/uv_run_tests_a TEST_NAME
2651cb0ef41Sopenharmony_ci
2661cb0ef41Sopenharmony_ci(gdb) set follow-fork-mode child
2671cb0ef41Sopenharmony_ci...
2681cb0ef41Sopenharmony_ci```
2691cb0ef41Sopenharmony_ci
2701cb0ef41Sopenharmony_ci##### Fork-aware valgrind
2711cb0ef41Sopenharmony_ci
2721cb0ef41Sopenharmony_ciUse the `--trace-children=yes` parameter:
2731cb0ef41Sopenharmony_ci
2741cb0ef41Sopenharmony_ci```bash
2751cb0ef41Sopenharmony_ci$ valgrind --trace-children=yes -v --tool=memcheck --leak-check=full --track-origins=yes --leak-resolution=high --show-reachable=yes --log-file=memcheck-%p.log build/uv_run_tests_a TEST_NAME
2761cb0ef41Sopenharmony_ci```
2771cb0ef41Sopenharmony_ci
2781cb0ef41Sopenharmony_ci### Running benchmarks
2791cb0ef41Sopenharmony_ci
2801cb0ef41Sopenharmony_ciSee the section on running tests.
2811cb0ef41Sopenharmony_ciThe benchmark driver is `./uv_run_benchmarks_a` and the benchmarks are
2821cb0ef41Sopenharmony_cilisted in `test/benchmark-list.h`.
2831cb0ef41Sopenharmony_ci
2841cb0ef41Sopenharmony_ci## Supported Platforms
2851cb0ef41Sopenharmony_ci
2861cb0ef41Sopenharmony_ciCheck the [SUPPORTED_PLATFORMS file](SUPPORTED_PLATFORMS.md).
2871cb0ef41Sopenharmony_ci
2881cb0ef41Sopenharmony_ci### `-fno-strict-aliasing`
2891cb0ef41Sopenharmony_ci
2901cb0ef41Sopenharmony_ciIt is recommended to turn on the `-fno-strict-aliasing` compiler flag in
2911cb0ef41Sopenharmony_ciprojects that use libuv. The use of ad hoc "inheritance" in the libuv API
2921cb0ef41Sopenharmony_cimay not be safe in the presence of compiler optimizations that depend on
2931cb0ef41Sopenharmony_cistrict aliasing.
2941cb0ef41Sopenharmony_ci
2951cb0ef41Sopenharmony_ciMSVC does not have an equivalent flag but it also does not appear to need it
2961cb0ef41Sopenharmony_ciat the time of writing (December 2019.)
2971cb0ef41Sopenharmony_ci
2981cb0ef41Sopenharmony_ci### AIX Notes
2991cb0ef41Sopenharmony_ci
3001cb0ef41Sopenharmony_ciAIX compilation using IBM XL C/C++ requires version 12.1 or greater.
3011cb0ef41Sopenharmony_ci
3021cb0ef41Sopenharmony_ciAIX support for filesystem events requires the non-default IBM `bos.ahafs`
3031cb0ef41Sopenharmony_cipackage to be installed.  This package provides the AIX Event Infrastructure
3041cb0ef41Sopenharmony_cithat is detected by `autoconf`.
3051cb0ef41Sopenharmony_ci[IBM documentation](http://www.ibm.com/developerworks/aix/library/au-aix_event_infrastructure/)
3061cb0ef41Sopenharmony_cidescribes the package in more detail.
3071cb0ef41Sopenharmony_ci
3081cb0ef41Sopenharmony_ci### z/OS Notes
3091cb0ef41Sopenharmony_ci
3101cb0ef41Sopenharmony_ciz/OS compilation requires [ZOSLIB](https://github.com/ibmruntimes/zoslib) to be installed. When building with [CMake][], use the flag `-DZOSLIB_DIR` to specify the path to [ZOSLIB](https://github.com/ibmruntimes/zoslib):
3111cb0ef41Sopenharmony_ci
3121cb0ef41Sopenharmony_ci```bash
3131cb0ef41Sopenharmony_ci$ (cd build && cmake .. -DBUILD_TESTING=ON -DZOSLIB_DIR=/path/to/zoslib)
3141cb0ef41Sopenharmony_ci$ cmake --build build
3151cb0ef41Sopenharmony_ci```
3161cb0ef41Sopenharmony_ci
3171cb0ef41Sopenharmony_ciz/OS creates System V semaphores and message queues. These persist on the system
3181cb0ef41Sopenharmony_ciafter the process terminates unless the event loop is closed.
3191cb0ef41Sopenharmony_ci
3201cb0ef41Sopenharmony_ciUse the `ipcrm` command to manually clear up System V resources.
3211cb0ef41Sopenharmony_ci
3221cb0ef41Sopenharmony_ci## Patches
3231cb0ef41Sopenharmony_ci
3241cb0ef41Sopenharmony_ciSee the [guidelines for contributing][].
3251cb0ef41Sopenharmony_ci
3261cb0ef41Sopenharmony_ci[CMake]: https://cmake.org/
3271cb0ef41Sopenharmony_ci[node.js]: http://nodejs.org/
3281cb0ef41Sopenharmony_ci[guidelines for contributing]: https://github.com/libuv/libuv/blob/master/CONTRIBUTING.md
3291cb0ef41Sopenharmony_ci[libuv_banner]: https://raw.githubusercontent.com/libuv/libuv/master/img/banner.png
3301cb0ef41Sopenharmony_ci[Visual C++ Build Tools]: https://visualstudio.microsoft.com/visual-cpp-build-tools/
3311cb0ef41Sopenharmony_ci[Visual Studio 2015 Update 3]: https://www.visualstudio.com/vs/older-downloads/
3321cb0ef41Sopenharmony_ci[Visual Studio 2017]: https://www.visualstudio.com/downloads/
3331cb0ef41Sopenharmony_ci[Git for Windows]: http://git-scm.com/download/win
334