Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 18 additions & 0 deletions src/client/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub struct Config {
pub(crate) trust: TrustConfig,
pub(crate) auth: AuthMethod,
pub(crate) readonly: bool,
pub(crate) packet_size: Option<u32>,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -65,6 +66,7 @@ impl Default for Config {
trust: TrustConfig::Default,
auth: AuthMethod::None,
readonly: false,
packet_size: None,
}
}
}
Expand Down Expand Up @@ -115,6 +117,22 @@ impl Config {
self.application_name = Some(name.to_string());
}

/// Sets the TDS packet size for the connection.
///
/// Larger packet sizes can improve bulk insert performance by reducing
/// the number of network round-trips. Valid values are 512 to 32767.
/// The server may negotiate a different size.
///
/// - Defaults to 4096 bytes.
pub fn packet_size(&mut self, size: u32) {
self.packet_size = Some(size);
}

/// Gets the configured packet size, if set.
pub fn get_packet_size(&self) -> Option<u32> {
self.packet_size
}

/// Set the preferred encryption level.
///
/// - With `tls` feature, defaults to `Required`.
Expand Down
6 changes: 6 additions & 0 deletions src/client/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl<S: AsyncRead + AsyncWrite + Unpin + Send> Connection<S> {
config.host,
config.application_name,
config.readonly,
config.packet_size,
prelogin,
)
.await?;
Expand Down Expand Up @@ -293,6 +294,7 @@ impl<S: AsyncRead + AsyncWrite + Unpin + Send> Connection<S> {
server_name: Option<String>,
application_name: Option<String>,
readonly: bool,
packet_size: Option<u32>,
prelogin: PreloginMessage,
) -> crate::Result<Self> {
let mut login_message = LoginMessage::new();
Expand All @@ -311,6 +313,10 @@ impl<S: AsyncRead + AsyncWrite + Unpin + Send> Connection<S> {

login_message.readonly(readonly);

if let Some(size) = packet_size {
login_message.packet_size(size);
}

match auth {
#[cfg(all(windows, feature = "winauth"))]
AuthMethod::Integrated => {
Expand Down
8 changes: 8 additions & 0 deletions src/tds/codec/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ impl<'a> LoginMessage<'a> {
self.type_flags.remove(LoginTypeFlag::ReadOnlyIntent);
}
}

/// Sets the requested TDS packet size.
///
/// Valid values are 512 to 32767. The server may negotiate a different size.
/// Larger packet sizes can improve bulk insert performance.
pub fn packet_size(&mut self, size: u32) {
self.packet_size = size;
}
}

impl<'a> Encode<BytesMut> for LoginMessage<'a> {
Expand Down