Module: Lich::Common::Buffer
- Defined in:
- documented/common/buffer.rb
Overview
Thread-safe circular buffer for game server output and script input streams.
Buffer maintains a fixed-size ring of lines, each tagged with a stream identifier that indicates the source (game server downstream output, upstream commands, script output, etc.). Each thread maintains its own read cursor and stream filter, allowing independent consumption of the shared buffer while preserving thread safety via mutex.
Threads are registered automatically on their first call to .gets, .gets?, .rewind, or .clear; stale entries are cleaned up automatically via throttled sweeps to prevent unbounded memory growth in long-running sessions.
Constant Summary collapse
- DOWNSTREAM_STRIPPED =
1- DOWNSTREAM_RAW =
2- DOWNSTREAM_MOD =
4- UPSTREAM =
8- UPSTREAM_MOD =
16- SCRIPT_OUTPUT =
32- @@index =
Hash.new
- @@streams =
Hash.new
- @@mutex =
Mutex.new
- @@offset =
0- @@buffer =
Array.new
- @@max_size =
3000- @@cleanup_throttle =
@@index / @@streams are keyed by Thread#object_id and were never pruned, so every thread that ever read the buffer leaked an entry that outlived it. maybe_cleanup sweeps dead-thread entries from the registration path, at most once every 60s via this throttle.
Throttle.new(60.0)