Struct kcp::Kcp
[−]
[src]
pub struct Kcp<Output: Write> { /* fields omitted */ }
KCP control
Methods
impl<Output: Write> Kcp<Output>
[src]
fn new(conv: 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.
fn expired(&mut self)
Set expired
fn peeksize(&self) -> KcpResult<usize>
Check buffer size without actually consuming it
fn recv(&mut self, buf: &mut [u8]) -> KcpResult<usize>
Receive data from buffer
fn send(&mut self, buf: &[u8]) -> KcpResult<usize>
Send bytes into buffer
fn input(&mut self, buf: &[u8]) -> KcpResult<()>
Call this when you received a packet from raw connection
fn flush(&mut self) -> KcpResult<()>
Flush pending data in buffer.
fn update(&mut self, current: u32) -> KcpResult<()>
Update state every 10ms ~ 100ms.
Or you can ask check
when to call this again.
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.
fn set_mtu(&mut self, mtu: usize) -> KcpResult<()>
Change MTU size, default is 1400
MTU = Maximum Transmission Unit
fn mtu(&self) -> usize
Get MTU
fn set_interval(&mut self, interval: u32)
Set check interval
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
fn set_wndsize(&mut self, sndwnd: u16, rcvwnd: u16)
Set wndsize
set maximum window size: sndwnd=32
, rcvwnd=32
by default
fn snd_wnd(&self) -> u16
snd_wnd
Send window
fn rcv_wnd(&self) -> u16
rcv_wnd
Receive window
fn waitsnd(&self) -> usize
Get waitsnd
, how many packet is waiting to be sent
fn set_rx_minrto(&mut self, rto: u32)
Set rx_minrto
fn set_fast_resend(&mut self, fr: u32)
Set fastresend
fn header_len() -> usize
KCP header size
fn set_stream(&mut self, s: bool)
Enable stream mode
fn is_stream(&self) -> bool
Enabled stream or not