Skip to main content
LibCore is Ladybird’s foundational library for event-driven programming and operating system abstractions. It provides the event loop, timers, file I/O, networking primitives, and process management.

Event loop system

The event loop is the heart of LibCore, enabling asynchronous I/O and event handling. See the event loop architecture for more details.

Creating and running an event loop

There is at most one running event loop per thread. Event loops can be nested for modal dialogs and other temporary UI states.

Event loop capabilities

Deferred invocation

Execute callbacks on next event loop iteration

Timers

Schedule callbacks to run after delays or repeatedly

I/O notifications

React when file descriptors become readable/writable

Signal handling

Handle POSIX signals in event-driven manner

How it works

The event loop uses select(2) to efficiently wait for events:
  1. exec() repeatedly calls pump() to process events
  2. pump() uses select() to sleep until an event occurs
  3. When awakened, callbacks for expired timers and I/O are invoked
  4. The loop returns to sleep until the next event
Do not store event loops in global variables due to initialization order issues. Create them in main() and pass them to classes that need them.

Timers

Core::Timer

Schedule callbacks to run after a delay:
Timers are not super accurate due to event loop scheduling. Don’t rely on them for precise timing in real-time scenarios like audio processing.

I/O and notifications

Core::Notifier

React when file descriptors become readable or writable:
Notifier types:
  • Read - File descriptor has data to read
  • Write - File descriptor is ready for writing
  • Exception - Exception condition occurred

File system operations

Core::File

Cross-platform file I/O:

Core::Directory

Directory operations:

Core::DirIterator

Iterate over directory entries:

File watching

Monitor file system changes:

Networking

Core::Socket

Base class for network sockets with async I/O:

Core::TCPServer

TCP server with event-driven connection handling:

Core::UDPServer

UDP socket for connectionless communication:

Process management

Core::Process

Spawn and manage child processes:

Environment and system info

Environment variables

Standard paths

Platform abstraction

LibCore provides cross-platform abstractions for:
  • File I/O: Works on Linux, macOS, Windows (WSL), and Unix systems
  • Networking: Portable socket API across platforms
  • Process management: Unified process spawning and control
  • Event loops: Platform-specific implementations (EventLoopImplementationUnix, EventLoopImplementationWindows)

Resource loading

Core::Resource

Load embedded or file-based resources:

Promises and async operations

Core::Promise

Type-safe async value resolution:

Core::ThreadedPromise

Promise that resolves on a background thread:

Configuration files

Core::ConfigFile

INI-style configuration file handling:

Argument parsing

Core::ArgsParser

User-friendly command-line argument parsing:

Source location

  • Repository: ~/workspace/source/Libraries/LibCore/
  • Key headers: EventLoop.h, Timer.h, File.h, Socket.h, Process.h
  • Documentation: ~/workspace/source/Documentation/EventLoop.md
  • Platform code: LibCore/Platform/
LibCore’s event loop is designed for I/O-bound operations and UI events. For CPU-intensive work, use LibThreading to run tasks on background threads.