How skywind3000/kcp works
KCP is a lightweight, reliable ARQ protocol library, not a socket implementation: applications provide packet transport and the clock. The main workflow sends application data through KCP, emits packets via a caller-supplied output callback, accepts received packets back through KCP, and exposes reassembled data to the application. Its core also handles ACKs, retransmission, receive ordering, and configurable flow/congestion control. The excerpts show some internal queue and retransmission behavior; other workflow links are documented in the README.
Main entry points: ikcp.h KCP API · ikcp.c ACK and retransmit
Components 11
Application API
- KCP API
ikcp.h
ARQ protocol core
- Session state
ikcp.c - Send queue
ikcp.c - ACK and retransmit
ikcp.c - Receive ordering
ikcp.c - Flow control
ikcp.c
Host integration
- Output callback
ikcp.c - Update scheduler
ikcp.c
Other components
- Application
- Host clock
- Packet transport
Connections 14
- Application → KCP API: sends data
README.md - KCP API → Session state: creates session
README.md - KCP API → Send queue: queues data
README.md - Send queue → ACK and retransmit: segments data
ikcp.c - ACK and retransmit → Output callback: emits packets
ikcp.c - Output callback → Packet transport: sends packets
README.md - Packet transport → KCP API: supplies packets
README.md - KCP API → Receive ordering: inputs packets
README.md - Receive ordering → ACK and retransmit: processes ACKs
ikcp.c - Receive ordering → Application: delivers data
README.md - Host clock → Update scheduler: provides time
README.md - Update scheduler → ACK and retransmit: updates state
README.md - Flow control → ACK and retransmit: limits sending
ikcp.c - KCP API → Flow control: configures control
README.md