The mock imitates FlatBuffersServerConnection and FlatBuffersParser (spec 3.2), including the priority handling, the idle timeout and the reject paths, so the client can be tested against it over a real socket. It doubles as a standalone example binary for end-to-end runs.
61 lines
1.7 KiB
Rust
61 lines
1.7 KiB
Rust
//! Standalone HyperHDR flatbuffers server mock, the same code the integration tests use.
|
|
//!
|
|
//! cargo run --example mock_hyperhdr -- --listen 127.0.0.1:19400
|
|
|
|
use std::io::IsTerminal;
|
|
use std::time::Duration;
|
|
|
|
use clap::{Parser, ValueEnum};
|
|
use gamescope_hyperhdr::hyperhdr::mock::{Behavior, MockOptions, MockServer};
|
|
use tracing::info;
|
|
|
|
#[derive(Debug, Clone, Copy, ValueEnum)]
|
|
enum Mode {
|
|
Normal,
|
|
Reject,
|
|
NoRead,
|
|
ErrorReplies,
|
|
}
|
|
|
|
#[derive(Parser)]
|
|
#[command(about = "Imitation of HyperHDR's flatbuffers server")]
|
|
struct Opt {
|
|
/// Address to listen on
|
|
#[arg(long, default_value = "127.0.0.1:19400")]
|
|
listen: String,
|
|
/// Close connections after this many seconds without data (HyperHDR's `timeout`)
|
|
#[arg(long, default_value_t = 5)]
|
|
timeout_secs: u64,
|
|
/// How to treat connections
|
|
#[arg(long, value_enum, default_value_t = Mode::Normal)]
|
|
behavior: Mode,
|
|
}
|
|
|
|
fn main() -> anyhow::Result<()> {
|
|
let opt = Opt::parse();
|
|
tracing_subscriber::fmt()
|
|
.with_target(false)
|
|
.with_writer(std::io::stderr)
|
|
.with_ansi(std::io::stderr().is_terminal())
|
|
.init();
|
|
|
|
let server = MockServer::start(
|
|
opt.listen.as_str(),
|
|
MockOptions {
|
|
idle_timeout: Duration::from_secs(opt.timeout_secs),
|
|
record_events: false,
|
|
log_events: true,
|
|
},
|
|
)?;
|
|
server.set_behavior(match opt.behavior {
|
|
Mode::Normal => Behavior::Normal,
|
|
Mode::Reject => Behavior::Reject,
|
|
Mode::NoRead => Behavior::NoRead,
|
|
Mode::ErrorReplies => Behavior::ErrorReplies,
|
|
});
|
|
info!("listening on {} ({:?})", server.addr(), opt.behavior);
|
|
loop {
|
|
std::thread::park();
|
|
}
|
|
}
|