diff --git a/puffin_http/src/lib.rs b/puffin_http/src/lib.rs index 4f0afaf6..90989e3f 100644 --- a/puffin_http/src/lib.rs +++ b/puffin_http/src/lib.rs @@ -25,4 +25,4 @@ mod server; pub use client::Client; #[cfg(not(target_arch = "wasm32"))] -pub use server::Server; +pub use server::{Server, ServerOptions}; diff --git a/puffin_http/src/server.rs b/puffin_http/src/server.rs index e55f3032..c8eaf6d8 100644 --- a/puffin_http/src/server.rs +++ b/puffin_http/src/server.rs @@ -12,6 +12,18 @@ use std::{ /// Maximum size of the backlog of packets to send to a client if they aren't reading fast enough. const MAX_FRAMES_IN_QUEUE: usize = 30; +#[derive(Default)] +pub struct ServerOptions { + frame_view_max_recent: Option, +} + +impl ServerOptions { + pub fn set_frame_view_max_recent(mut self, max_recent: usize) -> Self { + self.frame_view_max_recent = Some(max_recent); + self + } +} + /// Listens for incoming connections /// and streams them puffin profiler data. /// @@ -26,6 +38,10 @@ pub struct Server { impl Server { /// Start listening for connections on this addr (e.g. "0.0.0.0:8585") pub fn new(bind_addr: &str) -> anyhow::Result { + Self::new_options(bind_addr, ServerOptions::default()) + } + + pub fn new_options(bind_addr: &str, opts: ServerOptions) -> anyhow::Result { let tcp_listener = TcpListener::bind(bind_addr).context("binding server TCP socket")?; tcp_listener .set_nonblocking(true) @@ -52,6 +68,10 @@ impl Server { frame_view: Default::default(), }; + if let Some(max_recent) = opts.frame_view_max_recent { + server_impl.frame_view.set_max_recent(max_recent); + } + while let Ok(frame) = rx.recv() { server_impl.frame_view.add_frame(frame.clone()); if let Err(err) = server_impl.accept_new_clients() {