Building High-Performance Asynchronous Applications in C
Introduction
- What You Will Learn
- Who This Book Is For
- How This Book Is Structured
- A Note on Code Examples
Chapter 1: The World of Asynchronous I/O
- The C10K Problem and Beyond
- Concurrency Models Compared
- What libuv Is and Where It Lives
- Design Goals of libuv
- How to Read This Book
Chapter 2: Getting Started with libuv
- Obtaining libuv
- Building Your First Project with CMake
- The Minimal Event Loop Program
- Understanding the Build Output
- Verifying Your Installation
Chapter 3: Architecture of libuv
- The Platform Abstraction Layer
- Handles vs Requests
- The Event Loop Internals
- Memory Allocation in libuv
- Thread Safety Rules
Chapter 4: The Event Loop
- Anatomy of uv_run()
- Loop Lifecycle
- Custom Event Loops
- Embedding Loops
- Common Pitfalls
Chapter 5: Asynchronous I/O Fundamentals
- The Callback Pattern
- Error Handling in libuv
- Handles Lifecycle
- The Stream Abstraction
- Resource Cleanup Patterns
Chapter 6: Timers and Periodic Operations
- One-Shot Timers with uv_timer_t
- Repeating Timers
- Periodic Handles: Prepare and Check
- Time Management in libuv
- Building a Task Scheduler
Chapter 7: File System Operations
- Synchronous vs Asynchronous File I/O
- Reading and Writing Files
- Directory Operations
- The Thread Pool Behind fs Operations
- File Descriptors and Ownership
Chapter 8: TCP Networking
- TCP Servers
- TCP Clients
- Stream Operations on TCP
- Advanced Socket Options
- Building a Concurrent Echo Server
Chapter 9: UDP and DNS Resolution
- UDP Sockets
- Multicast Support
- Async DNS with getaddrinfo
- Reverse DNS and Hostname Resolution
- Building a Simple UDP Chat Server
Chapter 10: Pipes, Streams, and TTY
- Unix Domain Sockets and Named Pipes
- The Unified Stream Interface
- Duplex Streams
- TTY Support
- Building an IPC Bridge
Chapter 11: Process Management and Signals
- Spawning Processes
- Stdio Inheritance Patterns
- Process Events
- Signal Handling
- Building a Process Supervisor
Chapter 12: Threading and Synchronization
- The Thread Pool
- Creating Custom Threads
- Mutexes and Locks
- Condition Variables
- Atomic Operations and Thread-Local Storage
Chapter 13: Polling and Custom File Descriptors
- The Poll Handle
- Event Types and Their Meanings
- Integrating External Libraries
- File Descriptor Ownership
- Building a Hybrid Reactor
Chapter 14: Error Handling, Debugging, and Testing
- Systematic Error Handling
- Debugging libuv Applications
- Memory Leak Detection
- Testing Asynchronous Code
- Core Dumps and Post-Mortem Analysis
Chapter 15: Performance Optimization
- Reducing Latency
- Throughput Optimization
- CPU Affinity and Multiple Loops
- Profiling libuv Applications
- Tuning for Production
Chapter 16: Portability Across Operating Systems
- Platform Detection in libuv
- Linux-Specific Behavior
- macOS and BSD Considerations
- Windows Portability
- Writing Truly Portable Code
Chapter 17: Embedding libuv and Integration
- Embedding libuv in Existing Applications
- Integrating with SSL/TLS Libraries
- Building on Top of libuv
- Interfacing with C++ and Other Languages
- Microservice Architecture with libuv
Chapter 18: Real-World Applications
- Building an HTTP Server from Scratch
- A WebSocket Implementation
- A Load Balancer
- Deployment Considerations
Conclusion: The Art of Event-Driven Programming
- Patterns That Scale
- When NOT to Use libuv
- The Future of Async C
- Continuing Your Journey