iqiyi/libfiber logo

iqiyi/libfiber

Free

The high performance c/c++ coroutine/fiber library for Linux/FreeBSD/MacOS/Windows, supporting select/poll/epoll/kqueue/iouring/iocp/windows GUI.

FreeFree tier
Type
Open Source
Company
iQiyi

About iqiyi/libfiber

libfiber is a high-performance coroutine library for C/C++ developed by iQiyi. It enables writing network application services with high concurrency and performance more easily than traditional asynchronous event-driven models. The library supports multiple platforms including Linux, FreeBSD, macOS, and Windows, and integrates various I/O event mechanisms such as select, poll, epoll, kqueue, io_uring, and IOCP. Notably, it also supports Windows GUI message handling, allowing coroutine-based network modules in MFC, WTL, or other GUI frameworks. The library includes a rich set of APIs: base fiber management, I/O operations, networking (including socket and DNS), channels for inter-fiber communication, and synchronization primitives (mutex, event, wait_group). It offers both C and C++ (including C++11/14) APIs, API hooking for transparent coroutine support of blocking system calls, and comprehensive sample code for server/client, domain resolution, shared stack, inter-fiber/thread sync, HTTP server with routing, and Windows GUI.

Key Features

Cross-platform support: Linux, FreeBSD, macOS, Windows
Multiple I/O events: select, poll, epoll, kqueue, io_uring, IOCP, Windows GUI messages
C and C++ API (including C++11/14 support)
API hooking to transparently turn blocking syscalls into coroutine-friendly calls
Channel API for inter-fiber communication
Synchronization primitives: mutex, event, wait_group
Fiber pool for task execution
Shared stack fibers to reduce memory usage
Built-in HTTP server with URL routing
Support for Windows GUI applications (MFC, WTL)

Pros & Cons

Pros
  • Supports a wide range of OS platforms and I/O event mechanisms
  • Enables writing concurrent network code in a synchronous style, reducing complexity
  • Includes Windows GUI message integration, unique among coroutine libraries
  • Provides both C and modern C++ APIs (C++11/14)
  • API hooking allows seamless integration with existing blocking system calls
  • Well-documented with many sample programs covering common patterns
Cons
  • Relative to some alternatives (e.g., libuv, Boost.Asio), community adoption may be narrower
  • API hooking may introduce overhead or compatibility issues in edge cases
  • Documentation is primarily in the README and sample code; no separate extensive manual

Best For

Building high-concurrency network servers (e.g., chat, web, proxy)Developing large-scale concurrent network applications with simpler synchronous codeAdding coroutine-based networking to Windows GUI applicationsReplacing traditional event-driven asynchronous models in C/C++ projectsCreating lightweight cooperative multitasking in performance-sensitive applications