1e66f31c5Sopenharmony_ci![libuv][libuv_banner]
2e66f31c5Sopenharmony_ci
3e66f31c5Sopenharmony_ci## Overview
4e66f31c5Sopenharmony_ci
5e66f31c5Sopenharmony_cilibuv is a multi-platform support library with a focus on asynchronous I/O. It
6e66f31c5Sopenharmony_ciwas primarily developed for use by [Node.js][], but it's also
7e66f31c5Sopenharmony_ciused by [Luvit](http://luvit.io/), [Julia](http://julialang.org/),
8e66f31c5Sopenharmony_ci[uvloop](https://github.com/MagicStack/uvloop), and [others](https://github.com/libuv/libuv/blob/v1.x/LINKS.md).
9e66f31c5Sopenharmony_ci
10e66f31c5Sopenharmony_ci## Feature highlights
11e66f31c5Sopenharmony_ci
12e66f31c5Sopenharmony_ci * Full-featured event loop backed by epoll, kqueue, IOCP, event ports.
13e66f31c5Sopenharmony_ci
14e66f31c5Sopenharmony_ci * Asynchronous TCP and UDP sockets
15e66f31c5Sopenharmony_ci
16e66f31c5Sopenharmony_ci * Asynchronous DNS resolution
17e66f31c5Sopenharmony_ci
18e66f31c5Sopenharmony_ci * Asynchronous file and file system operations
19e66f31c5Sopenharmony_ci
20e66f31c5Sopenharmony_ci * File system events
21e66f31c5Sopenharmony_ci
22e66f31c5Sopenharmony_ci * ANSI escape code controlled TTY
23e66f31c5Sopenharmony_ci
24e66f31c5Sopenharmony_ci * IPC with socket sharing, using Unix domain sockets or named pipes (Windows)
25e66f31c5Sopenharmony_ci
26e66f31c5Sopenharmony_ci * Child processes
27e66f31c5Sopenharmony_ci
28e66f31c5Sopenharmony_ci * Thread pool
29e66f31c5Sopenharmony_ci
30e66f31c5Sopenharmony_ci * Signal handling
31e66f31c5Sopenharmony_ci
32e66f31c5Sopenharmony_ci * High resolution clock
33e66f31c5Sopenharmony_ci
34e66f31c5Sopenharmony_ci * Threading and synchronization primitives
35e66f31c5Sopenharmony_ci
36e66f31c5Sopenharmony_ci## Versioning
37e66f31c5Sopenharmony_ci
38e66f31c5Sopenharmony_ciStarting with version 1.0.0 libuv follows the [semantic versioning](http://semver.org/)
39e66f31c5Sopenharmony_cischeme. The API change and backwards compatibility rules are those indicated by
40e66f31c5Sopenharmony_ciSemVer. libuv will keep a stable ABI across major releases.
41e66f31c5Sopenharmony_ci
42e66f31c5Sopenharmony_ciThe ABI/API changes can be tracked [here](http://abi-laboratory.pro/tracker/timeline/libuv/).
43e66f31c5Sopenharmony_ci
44e66f31c5Sopenharmony_ci## Licensing
45e66f31c5Sopenharmony_ci
46e66f31c5Sopenharmony_cilibuv is licensed under the MIT license. Check the [LICENSE](LICENSE) and
47e66f31c5Sopenharmony_ci[LICENSE-extra](LICENSE-extra) files.
48e66f31c5Sopenharmony_ci
49e66f31c5Sopenharmony_ciThe documentation is licensed under the CC BY 4.0 license. Check the [LICENSE-docs file](LICENSE-docs).
50e66f31c5Sopenharmony_ci
51e66f31c5Sopenharmony_ci## Community
52e66f31c5Sopenharmony_ci
53e66f31c5Sopenharmony_ci * [Support](https://github.com/libuv/libuv/discussions)
54e66f31c5Sopenharmony_ci * [Mailing list](http://groups.google.com/group/libuv)
55e66f31c5Sopenharmony_ci
56e66f31c5Sopenharmony_ci## Documentation
57e66f31c5Sopenharmony_ci
58e66f31c5Sopenharmony_ci### Official documentation
59e66f31c5Sopenharmony_ci
60e66f31c5Sopenharmony_ciLocated in the docs/ subdirectory. It uses the [Sphinx](http://sphinx-doc.org/)
61e66f31c5Sopenharmony_ciframework, which makes it possible to build the documentation in multiple
62e66f31c5Sopenharmony_ciformats.
63e66f31c5Sopenharmony_ci
64e66f31c5Sopenharmony_ciShow different supported building options:
65e66f31c5Sopenharmony_ci
66e66f31c5Sopenharmony_ci```bash
67e66f31c5Sopenharmony_ci$ make help
68e66f31c5Sopenharmony_ci```
69e66f31c5Sopenharmony_ci
70e66f31c5Sopenharmony_ciBuild documentation as HTML:
71e66f31c5Sopenharmony_ci
72e66f31c5Sopenharmony_ci```bash
73e66f31c5Sopenharmony_ci$ make html
74e66f31c5Sopenharmony_ci```
75e66f31c5Sopenharmony_ci
76e66f31c5Sopenharmony_ciBuild documentation as HTML and live reload it when it changes (this requires
77e66f31c5Sopenharmony_cisphinx-autobuild to be installed and is only supported on Unix):
78e66f31c5Sopenharmony_ci
79e66f31c5Sopenharmony_ci```bash
80e66f31c5Sopenharmony_ci$ make livehtml
81e66f31c5Sopenharmony_ci```
82e66f31c5Sopenharmony_ci
83e66f31c5Sopenharmony_ciBuild documentation as man pages:
84e66f31c5Sopenharmony_ci
85e66f31c5Sopenharmony_ci```bash
86e66f31c5Sopenharmony_ci$ make man
87e66f31c5Sopenharmony_ci```
88e66f31c5Sopenharmony_ci
89e66f31c5Sopenharmony_ciBuild documentation as ePub:
90e66f31c5Sopenharmony_ci
91e66f31c5Sopenharmony_ci```bash
92e66f31c5Sopenharmony_ci$ make epub
93e66f31c5Sopenharmony_ci```
94e66f31c5Sopenharmony_ci
95e66f31c5Sopenharmony_ciNOTE: Windows users need to use make.bat instead of plain 'make'.
96e66f31c5Sopenharmony_ci
97e66f31c5Sopenharmony_ciDocumentation can be browsed online [here](http://docs.libuv.org).
98e66f31c5Sopenharmony_ci
99e66f31c5Sopenharmony_ciThe [tests and benchmarks](https://github.com/libuv/libuv/tree/master/test)
100e66f31c5Sopenharmony_cialso serve as API specification and usage examples.
101e66f31c5Sopenharmony_ci
102e66f31c5Sopenharmony_ci### Other resources
103e66f31c5Sopenharmony_ci
104e66f31c5Sopenharmony_ci * [LXJS 2012 talk](http://www.youtube.com/watch?v=nGn60vDSxQ4)
105e66f31c5Sopenharmony_ci   — High-level introductory talk about libuv.
106e66f31c5Sopenharmony_ci * [libuv-dox](https://github.com/thlorenz/libuv-dox)
107e66f31c5Sopenharmony_ci   — Documenting types and methods of libuv, mostly by reading uv.h.
108e66f31c5Sopenharmony_ci * [learnuv](https://github.com/thlorenz/learnuv)
109e66f31c5Sopenharmony_ci   — Learn uv for fun and profit, a self guided workshop to libuv.
110e66f31c5Sopenharmony_ci
111e66f31c5Sopenharmony_ciThese resources are not handled by libuv maintainers and might be out of
112e66f31c5Sopenharmony_cidate. Please verify it before opening new issues.
113e66f31c5Sopenharmony_ci
114e66f31c5Sopenharmony_ci## Downloading
115e66f31c5Sopenharmony_ci
116e66f31c5Sopenharmony_cilibuv can be downloaded either from the
117e66f31c5Sopenharmony_ci[GitHub repository](https://github.com/libuv/libuv)
118e66f31c5Sopenharmony_cior from the [downloads site](http://dist.libuv.org/dist/).
119e66f31c5Sopenharmony_ci
120e66f31c5Sopenharmony_ciBefore verifying the git tags or signature files, importing the relevant keys
121e66f31c5Sopenharmony_ciis necessary. Key IDs are listed in the
122e66f31c5Sopenharmony_ci[MAINTAINERS](https://github.com/libuv/libuv/blob/master/MAINTAINERS.md)
123e66f31c5Sopenharmony_cifile, but are also available as git blob objects for easier use.
124e66f31c5Sopenharmony_ci
125e66f31c5Sopenharmony_ciImporting a key the usual way:
126e66f31c5Sopenharmony_ci
127e66f31c5Sopenharmony_ci```bash
128e66f31c5Sopenharmony_ci$ gpg --keyserver pool.sks-keyservers.net --recv-keys AE9BC059
129e66f31c5Sopenharmony_ci```
130e66f31c5Sopenharmony_ci
131e66f31c5Sopenharmony_ciImporting a key from a git blob object:
132e66f31c5Sopenharmony_ci
133e66f31c5Sopenharmony_ci```bash
134e66f31c5Sopenharmony_ci$ git show pubkey-saghul | gpg --import
135e66f31c5Sopenharmony_ci```
136e66f31c5Sopenharmony_ci
137e66f31c5Sopenharmony_ci### Verifying releases
138e66f31c5Sopenharmony_ci
139e66f31c5Sopenharmony_ciGit tags are signed with the developer's key, they can be verified as follows:
140e66f31c5Sopenharmony_ci
141e66f31c5Sopenharmony_ci```bash
142e66f31c5Sopenharmony_ci$ git verify-tag v1.6.1
143e66f31c5Sopenharmony_ci```
144e66f31c5Sopenharmony_ci
145e66f31c5Sopenharmony_ciStarting with libuv 1.7.0, the tarballs stored in the
146e66f31c5Sopenharmony_ci[downloads site](http://dist.libuv.org/dist/) are signed and an accompanying
147e66f31c5Sopenharmony_cisignature file sit alongside each. Once both the release tarball and the
148e66f31c5Sopenharmony_cisignature file are downloaded, the file can be verified as follows:
149e66f31c5Sopenharmony_ci
150e66f31c5Sopenharmony_ci```bash
151e66f31c5Sopenharmony_ci$ gpg --verify libuv-1.7.0.tar.gz.sign
152e66f31c5Sopenharmony_ci```
153e66f31c5Sopenharmony_ci
154e66f31c5Sopenharmony_ci## Build Instructions
155e66f31c5Sopenharmony_ci
156e66f31c5Sopenharmony_ciFor UNIX-like platforms, including macOS, there are two build methods:
157e66f31c5Sopenharmony_ciautotools or [CMake][].
158e66f31c5Sopenharmony_ci
159e66f31c5Sopenharmony_ciFor Windows, [CMake][] is the only supported build method and has the
160e66f31c5Sopenharmony_cifollowing prerequisites:
161e66f31c5Sopenharmony_ci
162e66f31c5Sopenharmony_ci<details>
163e66f31c5Sopenharmony_ci
164e66f31c5Sopenharmony_ci* One of:
165e66f31c5Sopenharmony_ci  * [Visual C++ Build Tools][]
166e66f31c5Sopenharmony_ci  * [Visual Studio 2015 Update 3][], all editions
167e66f31c5Sopenharmony_ci    including the Community edition (remember to select
168e66f31c5Sopenharmony_ci    "Common Tools for Visual C++ 2015" feature during installation).
169e66f31c5Sopenharmony_ci  * [Visual Studio 2017][], any edition (including the Build Tools SKU).
170e66f31c5Sopenharmony_ci    **Required Components:** "MSbuild", "VC++ 2017 v141 toolset" and one of the
171e66f31c5Sopenharmony_ci    Windows SDKs (10 or 8.1).
172e66f31c5Sopenharmony_ci* Basic Unix tools required for some tests,
173e66f31c5Sopenharmony_ci  [Git for Windows][] includes Git Bash
174e66f31c5Sopenharmony_ci  and tools which can be included in the global `PATH`.
175e66f31c5Sopenharmony_ci
176e66f31c5Sopenharmony_ci</details>
177e66f31c5Sopenharmony_ci
178e66f31c5Sopenharmony_ciTo build with autotools:
179e66f31c5Sopenharmony_ci
180e66f31c5Sopenharmony_ci```bash
181e66f31c5Sopenharmony_ci$ sh autogen.sh
182e66f31c5Sopenharmony_ci$ ./configure
183e66f31c5Sopenharmony_ci$ make
184e66f31c5Sopenharmony_ci$ make check
185e66f31c5Sopenharmony_ci$ make install
186e66f31c5Sopenharmony_ci```
187e66f31c5Sopenharmony_ci
188e66f31c5Sopenharmony_ciTo build with [CMake][]:
189e66f31c5Sopenharmony_ci
190e66f31c5Sopenharmony_ci```bash
191e66f31c5Sopenharmony_ci$ mkdir -p build
192e66f31c5Sopenharmony_ci
193e66f31c5Sopenharmony_ci$ (cd build && cmake .. -DBUILD_TESTING=ON) # generate project with tests
194e66f31c5Sopenharmony_ci$ cmake --build build                       # add `-j <n>` with cmake >= 3.12
195e66f31c5Sopenharmony_ci
196e66f31c5Sopenharmony_ci# Run tests:
197e66f31c5Sopenharmony_ci$ (cd build && ctest -C Debug --output-on-failure)
198e66f31c5Sopenharmony_ci
199e66f31c5Sopenharmony_ci# Or manually run tests:
200e66f31c5Sopenharmony_ci$ build/uv_run_tests                        # shared library build
201e66f31c5Sopenharmony_ci$ build/uv_run_tests_a                      # static library build
202e66f31c5Sopenharmony_ci```
203e66f31c5Sopenharmony_ci
204e66f31c5Sopenharmony_ciTo cross-compile with [CMake][] (unsupported but generally works):
205e66f31c5Sopenharmony_ci
206e66f31c5Sopenharmony_ci```bash
207e66f31c5Sopenharmony_ci$ cmake ../..                 \
208e66f31c5Sopenharmony_ci  -DCMAKE_SYSTEM_NAME=Windows \
209e66f31c5Sopenharmony_ci  -DCMAKE_SYSTEM_VERSION=6.1  \
210e66f31c5Sopenharmony_ci  -DCMAKE_C_COMPILER=i686-w64-mingw32-gcc
211e66f31c5Sopenharmony_ci```
212e66f31c5Sopenharmony_ci
213e66f31c5Sopenharmony_ci### Install with Homebrew
214e66f31c5Sopenharmony_ci
215e66f31c5Sopenharmony_ci```bash
216e66f31c5Sopenharmony_ci$ brew install --HEAD libuv
217e66f31c5Sopenharmony_ci```
218e66f31c5Sopenharmony_ci
219e66f31c5Sopenharmony_ciNote to OS X users:
220e66f31c5Sopenharmony_ci
221e66f31c5Sopenharmony_ciMake sure that you specify the architecture you wish to build for in the
222e66f31c5Sopenharmony_ci"ARCHS" flag. You can specify more than one by delimiting with a space
223e66f31c5Sopenharmony_ci(e.g. "x86_64 i386").
224e66f31c5Sopenharmony_ci
225e66f31c5Sopenharmony_ci### Install with vcpkg
226e66f31c5Sopenharmony_ci
227e66f31c5Sopenharmony_ci```bash
228e66f31c5Sopenharmony_ci$ git clone https://github.com/microsoft/vcpkg.git
229e66f31c5Sopenharmony_ci$ ./bootstrap-vcpkg.bat # for powershell
230e66f31c5Sopenharmony_ci$ ./bootstrap-vcpkg.sh # for bash
231e66f31c5Sopenharmony_ci$ ./vcpkg install libuv
232e66f31c5Sopenharmony_ci```
233e66f31c5Sopenharmony_ci
234e66f31c5Sopenharmony_ci### Running tests
235e66f31c5Sopenharmony_ci
236e66f31c5Sopenharmony_ciSome tests are timing sensitive. Relaxing test timeouts may be necessary
237e66f31c5Sopenharmony_cion slow or overloaded machines:
238e66f31c5Sopenharmony_ci
239e66f31c5Sopenharmony_ci```bash
240e66f31c5Sopenharmony_ci$ env UV_TEST_TIMEOUT_MULTIPLIER=2 build/uv_run_tests # 10s instead of 5s
241e66f31c5Sopenharmony_ci```
242e66f31c5Sopenharmony_ci
243e66f31c5Sopenharmony_ci#### Run one test
244e66f31c5Sopenharmony_ci
245e66f31c5Sopenharmony_ciThe list of all tests is in `test/test-list.h`.
246e66f31c5Sopenharmony_ci
247e66f31c5Sopenharmony_ciThis invocation will cause the test driver to fork and execute `TEST_NAME` in
248e66f31c5Sopenharmony_cia child process:
249e66f31c5Sopenharmony_ci
250e66f31c5Sopenharmony_ci```bash
251e66f31c5Sopenharmony_ci$ build/uv_run_tests_a TEST_NAME
252e66f31c5Sopenharmony_ci```
253e66f31c5Sopenharmony_ci
254e66f31c5Sopenharmony_ciThis invocation will cause the test driver to execute the test in
255e66f31c5Sopenharmony_cithe same process:
256e66f31c5Sopenharmony_ci
257e66f31c5Sopenharmony_ci```bash
258e66f31c5Sopenharmony_ci$ build/uv_run_tests_a TEST_NAME TEST_NAME
259e66f31c5Sopenharmony_ci```
260e66f31c5Sopenharmony_ci
261e66f31c5Sopenharmony_ci#### Debugging tools
262e66f31c5Sopenharmony_ci
263e66f31c5Sopenharmony_ciWhen running the test from within the test driver process
264e66f31c5Sopenharmony_ci(`build/uv_run_tests_a TEST_NAME TEST_NAME`), tools like gdb and valgrind
265e66f31c5Sopenharmony_ciwork normally.
266e66f31c5Sopenharmony_ci
267e66f31c5Sopenharmony_ciWhen running the test from a child of the test driver process
268e66f31c5Sopenharmony_ci(`build/uv_run_tests_a TEST_NAME`), use these tools in a fork-aware manner.
269e66f31c5Sopenharmony_ci
270e66f31c5Sopenharmony_ci##### Fork-aware gdb
271e66f31c5Sopenharmony_ci
272e66f31c5Sopenharmony_ciUse the [follow-fork-mode](https://sourceware.org/gdb/onlinedocs/gdb/Forks.html) setting:
273e66f31c5Sopenharmony_ci
274e66f31c5Sopenharmony_ci```
275e66f31c5Sopenharmony_ci$ gdb --args build/uv_run_tests_a TEST_NAME
276e66f31c5Sopenharmony_ci
277e66f31c5Sopenharmony_ci(gdb) set follow-fork-mode child
278e66f31c5Sopenharmony_ci...
279e66f31c5Sopenharmony_ci```
280e66f31c5Sopenharmony_ci
281e66f31c5Sopenharmony_ci##### Fork-aware valgrind
282e66f31c5Sopenharmony_ci
283e66f31c5Sopenharmony_ciUse the `--trace-children=yes` parameter:
284e66f31c5Sopenharmony_ci
285e66f31c5Sopenharmony_ci```bash
286e66f31c5Sopenharmony_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
287e66f31c5Sopenharmony_ci```
288e66f31c5Sopenharmony_ci
289e66f31c5Sopenharmony_ci### Running benchmarks
290e66f31c5Sopenharmony_ci
291e66f31c5Sopenharmony_ciSee the section on running tests.
292e66f31c5Sopenharmony_ciThe benchmark driver is `./uv_run_benchmarks_a` and the benchmarks are
293e66f31c5Sopenharmony_cilisted in `test/benchmark-list.h`.
294e66f31c5Sopenharmony_ci
295e66f31c5Sopenharmony_ci## Supported Platforms
296e66f31c5Sopenharmony_ci
297e66f31c5Sopenharmony_ciCheck the [SUPPORTED_PLATFORMS file](SUPPORTED_PLATFORMS.md).
298e66f31c5Sopenharmony_ci
299e66f31c5Sopenharmony_ci### `-fno-strict-aliasing`
300e66f31c5Sopenharmony_ci
301e66f31c5Sopenharmony_ciIt is recommended to turn on the `-fno-strict-aliasing` compiler flag in
302e66f31c5Sopenharmony_ciprojects that use libuv. The use of ad hoc "inheritance" in the libuv API
303e66f31c5Sopenharmony_cimay not be safe in the presence of compiler optimizations that depend on
304e66f31c5Sopenharmony_cistrict aliasing.
305e66f31c5Sopenharmony_ci
306e66f31c5Sopenharmony_ciMSVC does not have an equivalent flag but it also does not appear to need it
307e66f31c5Sopenharmony_ciat the time of writing (December 2019.)
308e66f31c5Sopenharmony_ci
309e66f31c5Sopenharmony_ci### AIX Notes
310e66f31c5Sopenharmony_ci
311e66f31c5Sopenharmony_ciAIX compilation using IBM XL C/C++ requires version 12.1 or greater.
312e66f31c5Sopenharmony_ci
313e66f31c5Sopenharmony_ciAIX support for filesystem events requires the non-default IBM `bos.ahafs`
314e66f31c5Sopenharmony_cipackage to be installed.  This package provides the AIX Event Infrastructure
315e66f31c5Sopenharmony_cithat is detected by `autoconf`.
316e66f31c5Sopenharmony_ci[IBM documentation](http://www.ibm.com/developerworks/aix/library/au-aix_event_infrastructure/)
317e66f31c5Sopenharmony_cidescribes the package in more detail.
318e66f31c5Sopenharmony_ci
319e66f31c5Sopenharmony_ci### z/OS Notes
320e66f31c5Sopenharmony_ci
321e66f31c5Sopenharmony_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):
322e66f31c5Sopenharmony_ci
323e66f31c5Sopenharmony_ci```bash
324e66f31c5Sopenharmony_ci$ (cd build && cmake .. -DBUILD_TESTING=ON -DZOSLIB_DIR=/path/to/zoslib)
325e66f31c5Sopenharmony_ci$ cmake --build build
326e66f31c5Sopenharmony_ci```
327e66f31c5Sopenharmony_ci
328e66f31c5Sopenharmony_ciz/OS creates System V semaphores and message queues. These persist on the system
329e66f31c5Sopenharmony_ciafter the process terminates unless the event loop is closed.
330e66f31c5Sopenharmony_ci
331e66f31c5Sopenharmony_ciUse the `ipcrm` command to manually clear up System V resources.
332e66f31c5Sopenharmony_ci
333e66f31c5Sopenharmony_ci## Patches
334e66f31c5Sopenharmony_ci
335e66f31c5Sopenharmony_ciSee the [guidelines for contributing][].
336e66f31c5Sopenharmony_ci
337e66f31c5Sopenharmony_ci[CMake]: https://cmake.org/
338e66f31c5Sopenharmony_ci[node.js]: http://nodejs.org/
339e66f31c5Sopenharmony_ci[guidelines for contributing]: https://github.com/libuv/libuv/blob/master/CONTRIBUTING.md
340e66f31c5Sopenharmony_ci[libuv_banner]: https://raw.githubusercontent.com/libuv/libuv/master/img/banner.png
341e66f31c5Sopenharmony_ci[Visual C++ Build Tools]: https://visualstudio.microsoft.com/visual-cpp-build-tools/
342e66f31c5Sopenharmony_ci[Visual Studio 2015 Update 3]: https://www.visualstudio.com/vs/older-downloads/
343e66f31c5Sopenharmony_ci[Visual Studio 2017]: https://www.visualstudio.com/downloads/
344e66f31c5Sopenharmony_ci[Git for Windows]: http://git-scm.com/download/win
345