use std::time::Duration;
use crate::proto::header::Command;
use crate::proto::messages::Dialect;
pub const MAX_SMALL_REQUEST: usize = 68 * 1024;
pub fn max_request_frame(dialect: Option<Dialect>, max_read: u32, max_write: u32) -> usize {
match dialect {
None | Some(Dialect::Smb2Wildcard) => MAX_SMALL_REQUEST,
Some(_) => max_read.max(max_write) as usize + 256,
}
}
pub fn is_bulk(command: Command) -> bool {
matches!(
command,
Command::Read
| Command::Write
| Command::Ioctl
| Command::QueryDirectory
| Command::ChangeNotify
| Command::QueryInfo
| Command::SetInfo
)
}
pub fn supports_multi_credit(dialect: Option<Dialect>) -> bool {
matches!(
dialect,
Some(Dialect::Smb210 | Dialect::Smb300 | Dialect::Smb302 | Dialect::Smb311)
)
}
#[derive(Debug, Clone)]
pub struct Limits {
pub max_connections: usize,
pub handshake_timeout: Duration,
pub idle_timeout: Duration,
pub io_timeout: Duration,
pub tcp_keepalive: Option<Duration>,
pub durable_handle_timeout: Duration,
pub max_disconnected_opens: usize,
}
impl Default for Limits {
fn default() -> Self {
Self {
max_connections: 1024,
handshake_timeout: Duration::from_secs(30),
idle_timeout: Duration::from_mins(15),
io_timeout: Duration::from_secs(60),
tcp_keepalive: Some(Duration::from_secs(60)),
durable_handle_timeout: crate::files::DEFAULT_DURABLE_HANDLE_TIMEOUT,
max_disconnected_opens: crate::files::DEFAULT_MAX_DISCONNECTED_OPENS,
}
}
}