Skip to content

Commit

Permalink
feat: puffin_http server options
Browse files Browse the repository at this point in the history
feat: puffin_http server options
  • Loading branch information
plasticbox committed Jan 26, 2024
1 parent 5c4b6c5 commit 2f30823
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion puffin_http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ mod server;
pub use client::Client;

#[cfg(not(target_arch = "wasm32"))]
pub use server::Server;
pub use server::{Server, ServerOptions};
20 changes: 20 additions & 0 deletions puffin_http/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize>,
}

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.
///
Expand All @@ -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> {
Self::new_options(bind_addr, ServerOptions::default())
}

pub fn new_options(bind_addr: &str, opts: ServerOptions) -> anyhow::Result<Self> {
let tcp_listener = TcpListener::bind(bind_addr).context("binding server TCP socket")?;
tcp_listener
.set_nonblocking(true)
Expand All @@ -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() {
Expand Down

0 comments on commit 2f30823

Please sign in to comment.