Skip to main content

Kcp

Struct Kcp 

Source
pub struct Kcp<Output> {
    pub output: KcpOutput<Output>,
    /* private fields */
}
Expand description

KCP control

Fields§

§output: KcpOutput<Output>

Implementations§

Source§

impl<Output> Kcp<Output>

Source

pub fn new(conv: u32, token: u32, output: Output) -> Self

Creates a KCP control object, conv must be equal in both endpoints in one connection. output is the callback object for writing.

conv represents conversation.

Source

pub fn new_stream(conv: u32, token: u32, output: Output) -> Self

Creates a KCP control object in stream mode, conv must be equal in both endpoints in one connection. output is the callback object for writing.

conv represents conversation.

Source

pub fn peeksize(&self) -> KcpResult<usize>

Check buffer size without actually consuming it

Source

pub fn move_buf(&mut self)

Source

pub fn recv(&mut self, buf: &mut [u8]) -> KcpResult<usize>

Receive data from buffer

Source

pub fn send(&mut self, buf: &[u8]) -> KcpResult<usize>

Send bytes into buffer

Source

pub fn input_conv(&mut self)

Get conv from the next input call

Source

pub fn waiting_conv(&self) -> bool

Check if Kcp is waiting for the next input

Source

pub fn set_conv(&mut self, conv: u32)

Set conv value

Source

pub fn conv(&self) -> u32

Get conv

Source

pub fn set_token(&mut self, token: u32)

Set token value

Source

pub fn token(&self) -> u32

Get token

Source

pub fn input(&mut self, buf: &[u8]) -> KcpResult<usize>

Call this when you received a packet from raw connection

Source

pub fn check(&self, current: u32) -> u32

Determine when you should call update. Return when you should invoke update in millisec, if there is no input/send calling. You can call update in that time without calling it repeatly.

Source

pub fn set_mtu(&mut self, mtu: usize) -> KcpResult<()>

Change MTU size, default is 1400

MTU = Maximum Transmission Unit

Source

pub fn mtu(&self) -> usize

Get MTU

Source

pub fn set_interval(&mut self, interval: u32)

Set check interval

Source

pub fn set_nodelay( &mut self, nodelay: bool, interval: i32, resend: i32, nc: bool, )

Set nodelay

fastest config: nodelay(true, 20, 2, true)

nodelay: default is disable (false) interval: internal update timer interval in millisec, default is 100ms resend: 0:disable fast resend(default), 1:enable fast resend nc: false: normal congestion control(default), true: disable congestion control

Source

pub fn set_wndsize(&mut self, sndwnd: u16, rcvwnd: u16)

Set wndsize set maximum window size: sndwnd=32, rcvwnd=32 by default

Source

pub fn snd_wnd(&self) -> u16

snd_wnd Send window

Source

pub fn rcv_wnd(&self) -> u16

rcv_wnd Receive window

Source

pub fn wait_snd(&self) -> usize

Get waitsnd, how many packet is waiting to be sent

Source

pub fn set_rx_minrto(&mut self, rto: u32)

Set rx_minrto

Source

pub fn set_fast_resend(&mut self, fr: u32)

Set fastresend

Source

pub fn header_len(&self) -> usize

KCP header size

Source

pub fn is_stream(&self) -> bool

Enabled stream or not

Source

pub fn mss(&self) -> u32

Maximum Segment Size

Source

pub fn set_maximum_resend_times(&mut self, dead_link: u32)

Set maximum resend times

Check if KCP connection is dead (resend times excceeded)

Source§

impl<Output: Write> Kcp<Output>

Source

pub fn flush_ack(&mut self) -> KcpResult<()>

Flush pending ACKs

Source

pub fn flush(&mut self) -> KcpResult<()>

Flush pending data in buffer.

Source

pub fn update(&mut self, current: u32) -> KcpResult<()>

Update state every 10ms ~ 100ms.

Or you can ask check when to call this again.

Trait Implementations§

Source§

impl<Output: Default> Default for Kcp<Output>

Source§

fn default() -> Kcp<Output>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<Output> Freeze for Kcp<Output>
where Output: Freeze,

§

impl<Output> RefUnwindSafe for Kcp<Output>
where Output: RefUnwindSafe,

§

impl<Output> Send for Kcp<Output>
where Output: Send,

§

impl<Output> Sync for Kcp<Output>
where Output: Sync,

§

impl<Output> Unpin for Kcp<Output>
where Output: Unpin,

§

impl<Output> UnsafeUnpin for Kcp<Output>
where Output: UnsafeUnpin,

§

impl<Output> UnwindSafe for Kcp<Output>
where Output: UnwindSafe,

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> 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, 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.