Skip to main content

KcpConfig

Struct KcpConfig 

Source
pub struct KcpConfig {
    pub nodelay: bool,
    pub interval: u32,
    pub resend: i32,
    pub nc: bool,
    pub mtu: u32,
    pub snd_wnd: u32,
    pub rcv_wnd: u32,
    pub stream_mode: bool,
}
Expand description

KCP protocol configuration parameters.

Controls the behavior of the underlying KCP engine. Use the provided presets (default(), fast(), normal()) or customize individual fields.

§Example

use kcp_io::core::KcpConfig;

// Use a preset
let config = KcpConfig::fast();

// Customize from a preset
let config = KcpConfig {
    mtu: 1200,
    snd_wnd: 256,
    rcv_wnd: 256,
    ..KcpConfig::fast()
};

Fields§

§nodelay: bool

Enable nodelay mode. When true, KCP disables the wait-to-send delay and sends packets as soon as possible, reducing latency.

§interval: u32

Internal update interval in milliseconds. Lower values reduce latency but increase CPU usage. Typical range: 10–100 ms.

§resend: i32

Fast retransmit trigger count. When an out-of-order ACK is received this many times, KCP immediately retransmits the packet without waiting for a timeout. Set to 0 to disable fast retransmit.

§nc: bool

Disable congestion control. When true, KCP ignores the congestion window and sends at full speed (uses nocwnd mode). Useful for low-latency scenarios where bandwidth is not a concern.

§mtu: u32

Maximum Transmission Unit in bytes. This is the maximum size of a single KCP output packet (including the 24-byte KCP header). Must account for UDP header overhead (28 bytes for IPv4). Default: 1400.

§snd_wnd: u32

Send window size (number of packets). Larger values allow higher throughput but consume more memory. Default: 32.

§rcv_wnd: u32

Receive window size (number of packets). Should generally be >= snd_wnd. Larger values allow higher throughput. Default: 128.

§stream_mode: bool

Enable stream mode. When true, KCP operates like a byte stream (similar to TCP), merging small packets and splitting large ones. When false (default), KCP preserves message boundaries.

Implementations§

Source§

impl KcpConfig

Source

pub fn fast() -> Self

Returns a low-latency (fast) configuration preset.

Optimized for minimal latency at the cost of higher bandwidth usage.

  • nodelay: true
  • interval: 10 ms
  • resend: 2 (fast retransmit after 2 out-of-order ACKs)
  • nc: true (congestion control disabled)
  • mtu: 1400
  • snd_wnd: 128, rcv_wnd: 128
  • stream_mode: false
Source

pub fn normal() -> Self

Returns a balanced (normal) configuration preset.

Balances latency and bandwidth usage. Good for most use cases.

  • nodelay: true
  • interval: 40 ms
  • resend: 2
  • nc: false (congestion control enabled)
  • mtu: 1400
  • snd_wnd: 64, rcv_wnd: 128
  • stream_mode: false

Trait Implementations§

Source§

impl Clone for KcpConfig

Source§

fn clone(&self) -> KcpConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for KcpConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for KcpConfig

Source§

fn default() -> Self

Returns a conservative default configuration.

  • nodelay: false
  • interval: 100 ms
  • resend: 0 (no fast retransmit)
  • nc: false (congestion control enabled)
  • mtu: 1400
  • snd_wnd: 32, rcv_wnd: 128
  • stream_mode: false

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.