libuv 介绍

Cross-platform asynchronous I/O

背景:
特别说明的是libev 中包含了libevent 的内容,而libuv从libev修改而来。
node.js 最初发起于 2009 年, 是一个可以让 Javascript 代码脱离浏览器的执行环境, libuv 使用了 Google 的 V8 执行引擎 和 Marc Lehmann 的 libev. Node.js 将事件驱动的 I/O 模型与适合该模型的编程语言(Javascript)融合在了一起, 随着 node.js 的日益流行, node.js 的开发者们也意识到应该让 node.js 在 Windows 平台下也能工作, 但是 libev 只能在 Unix 环境下运行. Windows 平台上与 kqueue(FreeBSD) 或者 (e)poll(Linux) 等内核事件通知相应的机制 是 IOCP, libuv 依据不同平台的特性(Unix 平台为 libev, Windows 平台为 IOCP) 给上层应用提供了统一基于 libev API 的抽象, 不过 node-v0.9.0 版本的 libuv 中 libev 的依赖已被移除, 参见: libev has been removed libuv 直接与 Unix 平台交互.

详情见下面 书籍 《 An Introduction to libuv》的序言


libuv官方网站
libuv官方github

Overview

libuv is a multi-platform support library with a focus on asynchronous I/O. It was primarily developed for use by Node.js, but it’s also used by Luvit, Julia, pyuv, and others.

Features

  • Full-featured event loop backed by epoll, kqueue, IOCP, event ports.
  • Asynchronous TCP and UDP sockets
  • Asynchronous DNS resolution
  • Asynchronous file and file system operations
  • File system events
  • ANSI escape code controlled TTY
  • IPC with socket sharing, using Unix domain sockets or named pipes (Windows)
  • Child processes
  • Thread pool
  • Signal handling
  • High resolution clock
  • Threading and synchronization primitives

Supported Platforms

  • Microsoft Windows operating systems since Windows XP SP2. It can be built with either Visual Studio or MinGW. Consider using Visual Studio Express 2010 or later if you do not have a full Visual Studio license.

  • Linux using the GCC toolchain.

  • OS X using the GCC or XCode toolchain.

  • Solaris 121 and later using GCC toolchain.

  • AIX 6 and later using GCC toolchain (see notes).

官方 Docs

书籍

《 An Introduction to libuv》英文版
pdf

《An Introduction to libuv》中文翻译,在线地址,还有github地址
uvbook 中文翻译

学习这个库,最重要的是 看源码 + 练习
用example 进入最好。非常快!!

Tips:

代码跳转,查看定义问题

在libev,libuv,libevent的源代码, 或者复杂点的.h/.c文件中,
想查看 宏定义、自定义类型、struct 里面的内容, 如果写代码找不到这些内容,会坑死人。

下面有几款推荐IDE

差评:

  • sourceInsight 导入时,会提示header太复杂,无法解析,所以无法跳转 宏定义。(只能跳转函数)

好评:(优先级从高到低)

posted @ 2015-11-09 22:19  scott_h  阅读(7445)  评论(0编辑  收藏  举报