Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ws/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ impl Server {
executor: UninitializedExecutor,
max_connections: usize,
max_payload_bytes: usize,
max_in_buffer_capacity: usize,
max_out_buffer_capacity: usize,
) -> Result<Server>
where
S::Future: Unpin,
Expand All @@ -68,8 +70,8 @@ impl Server {
config.max_connections = max_connections;
// don't accept super large requests
config.max_fragment_size = max_payload_bytes;
config.max_in_buffer_capacity = max_payload_bytes;
config.max_out_buffer_capacity = max_payload_bytes;
config.max_in_buffer_capacity = max_in_buffer_capacity;
config.max_out_buffer_capacity = max_out_buffer_capacity;
// don't grow non-final fragments (to prevent DOS)
config.fragments_grow = false;
config.fragments_capacity = cmp::max(1, max_payload_bytes / config.fragment_size);
Expand Down
20 changes: 20 additions & 0 deletions ws/src/server_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub struct ServerBuilder<M: core::Metadata, S: core::Middleware<M>> {
executor: UninitializedExecutor,
max_connections: usize,
max_payload_bytes: usize,
max_in_buffer_capacity: usize,
max_out_buffer_capacity: usize,
}

impl<M: core::Metadata + Default, S: core::Middleware<M>> ServerBuilder<M, S>
Expand Down Expand Up @@ -61,6 +63,8 @@ where
executor: UninitializedExecutor::Unspawned,
max_connections: 100,
max_payload_bytes: 5 * 1024 * 1024,
max_in_buffer_capacity: 10 * 1024 * 1024,
max_out_buffer_capacity: 10 * 1024 * 1024,
}
}

Expand Down Expand Up @@ -115,6 +119,20 @@ where
self
}

/// The maximum size to which the incoming buffer can grow.
/// Default: 10,485,760
pub fn max_in_buffer_capacity(mut self, max_in_buffer_capacity: usize) -> Self {
self.max_in_buffer_capacity = max_in_buffer_capacity;
self
}

/// The maximum size to which the outgoing buffer can grow.
/// Default: 10,485,760
pub fn max_out_buffer_capacity(mut self, max_out_buffer_capacity: usize) -> Self {
self.max_out_buffer_capacity = max_out_buffer_capacity;
self
}

/// Starts a new `WebSocket` server in separate thread.
/// Returns a `Server` handle which closes the server when droped.
pub fn start(self, addr: &SocketAddr) -> Result<Server> {
Expand All @@ -129,6 +147,8 @@ where
self.executor,
self.max_connections,
self.max_payload_bytes,
self.max_in_buffer_capacity,
self.max_in_buffer_capacity,
)
}
}