Guide

Examples

Run the example programs and use them as practical references for SC::Build, Async, Http, Plugin, and other libraries.

The examples are complete programs built from the same library sources as the test suite. Use them to see how the libraries fit together, then follow the links to the source when you need the implementation details.

See the examples in action

These recordings show the larger examples running before you explore their source or the focused command-line programs below.

Applications and runtime behavior

Plugin loading and hot reload

SCExample loading native plugins and replacing them while the host keeps running.

SC::Build workflows

Native standalone build

The native backend compiling and linking the repository directly, without generating an IDE project first.

External project bootstrap

A small external project fetching the launcher with curl and building from its own SC-build.cpp.

Quick start

Build and run an example from the repository root:

./SC.sh build compile AwaitEcho Debug
./SC.sh build run AwaitEcho Debug

Use SC.bat instead of ./SC.sh on Windows. Project generation, IDE setup, and platform prerequisites are covered in Building (Contributor).

HTTP and networking

  • ApiServer is a small routed HTTP API with health, query, and streaming echo endpoints.
  • SaneHttpGet is the shortest blocking HttpClient example.
  • HttpClientPollSession shows a poll-driven client session with caller-owned storage.
  • HttpClientAsyncGet connects HttpClient to AsyncStreams and an AsyncEventLoop.
  • AsyncWebServer is the advanced HTTP laboratory for static files, uploads, WebSockets, configurable connection storage, and Linux backend selection.

To serve a directory with AsyncWebServer, pass an absolute path after --:

./SC.sh build compile AsyncWebServer Debug
./SC.sh build run AsyncWebServer Debug -- --directory /absolute/path/to/site

Await cookbook

Warning: Await is currently experimental. These examples are complete programs for exploring the coroutine API, not a stable compatibility promise.

Task ownership and coordination

  • AwaitBackgroundJobs manages detached work in fixed caller-owned registry slots.
  • AwaitDeadline applies a deadline and cooperative cancellation to a child task.
  • AwaitFirstResponse races two jobs and cancels the slower one.

Networking

  • AwaitEcho is the baseline TCP client/server conversation.
  • AwaitDatagramPing demonstrates a bounded UDP request and reply.
  • AwaitLineProtocol builds a small CRLF-framed protocol.

File I/O

  • AwaitConfigReload composes a child task that reads a configuration file.
  • AwaitFilePatch performs explicit offset writes and reads.
  • AwaitManifestPreview reads into a bounded preview buffer until full or EOF.
  • AwaitTaskGroupFiles reads multiple files with a task group.
  • AwaitFileCourier combines file operations with file-to-socket transfer.

System integration

  • AwaitBackgroundDigest moves bounded CPU work to a thread pool.
  • AwaitCallbackBridge runs callback-style Async and coroutine-style Await on the same event loop.
  • AwaitProcessExitCodes waits for multiple child processes.
  • AwaitThreadWakeUp delivers another thread's signal to an Await coroutine.

Composed workflow

  • AwaitServiceProbe combines networking, task groups, background work, timeouts, and explicit shutdown.

All Await sources are under the Examples directory and use their directory name as the build target.

Fibers

  • FibersDemo demonstrates CPU fibers, FibersAsync sleeps, and worker-pool work in three focused sections.
  • FibersBenchmark is a maintainer benchmark for scheduler, contention, and sustained micro-task workloads.
  • FibersSkynetBenchmark is an opt-in comparison with Taskflow's upstream Skynet backend. Install it with ./SC.sh package install taskflow-benchmarks before configuring the benchmark target.
  • FibersStackGrowthPrototype is a maintainer prototype for stack-growth behavior.

Benchmark results depend on the machine and build configuration; they are development measurements rather than portable performance claims.

Native integration and hot reload

SCExample is the native Sokol and Dear ImGui host used to exercise Async, plugins, file watching, state handoff, and hot reload. Its plugins are:

  • CollaborativeCanvasExample, which hosts a browser canvas through HTTP and WebSockets;
  • SerializationExample, which demonstrates reflected state and binary/JSON serialization;
  • WebServerExample, which configures a static file server from the native UI.

SCExample is an integration testbed rather than the shortest introduction to any individual library. Start with a focused console example when learning one API.

More source-backed examples

The library pages contain compiled snippets for individual APIs. The tests provide broader executable reference code, including error paths and platform-specific behavior. See Tests and the library catalog when an example above is broader than the question you are trying to answer.