|
160
|
1 Introduction
|
|
|
2 ============
|
|
|
3
|
|
|
4 This 'book' is a small set of tutorials about using libuv_ as
|
|
|
5 a high performance evented I/O library which offers the same API on Windows and Unix.
|
|
|
6
|
|
|
7 It is meant to cover the main areas of libuv, but is not a comprehensive
|
|
|
8 reference discussing every function and data structure. The `official libuv
|
|
|
9 documentation`_ may be consulted for full details.
|
|
|
10
|
|
|
11 .. _official libuv documentation: https://docs.libuv.org/en/v1.x/
|
|
|
12
|
|
|
13 This book is still a work in progress, so sections may be incomplete, but
|
|
|
14 I hope you will enjoy it as it grows.
|
|
|
15
|
|
|
16 Who this book is for
|
|
|
17 --------------------
|
|
|
18
|
|
|
19 If you are reading this book, you are either:
|
|
|
20
|
|
|
21 1) a systems programmer, creating low-level programs such as daemons or network
|
|
|
22 services and clients. You have found that the event loop approach is well
|
|
|
23 suited for your application and decided to use libuv.
|
|
|
24
|
|
|
25 2) a node.js module writer, who wants to wrap platform APIs
|
|
|
26 written in C or C++ with a set of (a)synchronous APIs that are exposed to
|
|
|
27 JavaScript. You will use libuv purely in the context of node.js. For
|
|
|
28 this you will require some other resources as the book does not cover parts
|
|
|
29 specific to v8/node.js.
|
|
|
30
|
|
|
31 This book assumes that you are comfortable with the C programming language.
|
|
|
32
|
|
|
33 Background
|
|
|
34 ----------
|
|
|
35
|
|
|
36 The node.js_ project began in 2009 as a JavaScript environment decoupled
|
|
|
37 from the browser. Using Google's V8_ and Marc Lehmann's libev_, node.js
|
|
|
38 combined a model of I/O -- evented -- with a language that was well suited to
|
|
|
39 the style of programming; due to the way it had been shaped by browsers. As
|
|
|
40 node.js grew in popularity, it was important to make it work on Windows, but
|
|
|
41 libev ran only on Unix. The Windows equivalent of kernel event notification
|
|
|
42 mechanisms like kqueue or (e)poll is IOCP. libuv was an abstraction around libev
|
|
|
43 or IOCP depending on the platform, providing users an API based on libev.
|
|
|
44 In the node-v0.9.0 version of libuv `libev was removed`_.
|
|
|
45
|
|
|
46 Since then libuv has continued to mature and become a high quality standalone
|
|
|
47 library for system programming. Users outside of node.js include Mozilla's
|
|
|
48 Rust_ programming language, and a variety_ of language bindings.
|
|
|
49
|
|
|
50 This book and the code is based on libuv version `v1.42.0`_.
|
|
|
51
|
|
|
52 Code
|
|
|
53 ----
|
|
|
54
|
|
|
55 All the example code and the source of the book is included as part of
|
|
|
56 the libuv_ project on GitHub.
|
|
|
57 Clone or Download libuv_, then build it::
|
|
|
58
|
|
|
59 sh autogen.sh
|
|
|
60 ./configure
|
|
|
61 make
|
|
|
62
|
|
|
63 There is no need to ``make install``. To build the examples run ``make`` in the
|
|
|
64 ``docs/code/`` directory.
|
|
|
65
|
|
|
66 .. _v1.42.0: https://github.com/libuv/libuv/releases/tag/v1.42.0
|
|
|
67 .. _V8: https://v8.dev
|
|
|
68 .. _libev: http://software.schmorp.de/pkg/libev.html
|
|
|
69 .. _libuv: https://github.com/libuv/libuv
|
|
|
70 .. _node.js: https://www.nodejs.org
|
|
|
71 .. _libev was removed: https://github.com/joyent/libuv/issues/485
|
|
|
72 .. _Rust: https://www.rust-lang.org
|
|
|
73 .. _variety: https://github.com/libuv/libuv/blob/v1.x/LINKS.md
|