ikcp_send failed after sometimes.

6jygbczu  于 2022-10-25  发布在  其他
关注(0)|答案(1)|浏览(227)

Problem : I am using kcp, after sending few packets ikcp_send fails. data is not getting transmitted

sending  10bytes of data + 24 bytes kcp header  = 34 bytes 
             `// flash remain 
                    size = (int)(ptr - buffer);
                if (size > 0) {
	          ikcp_output(kcp, buffer, size);
                }`
         In the above code while data is sent correctly size is always 34 bytes. after some time  no data is send size is 0.
         so no ikcp_output happening.

            `int needsend = 0;
	if (segment->xmit == 0) {
		needsend = 1;
		segment->xmit++;
		segment->rto = kcp->rx_rto;
		segment->resendts = current + segment->rto + rtomin;
	}`
  1. in correct case when data is getting send ,needsend is set to 1 in above condition.
  2. in Error case needsend is always 0.

-> kcp create :
auto *ptr = ikcp_create(unique_id, reinterpret_cast<void *>(user_pointer)); ptr->output = callback_handler; ikcp_nodelay(ptr, 1, 10, 2, 1); // Turbo mode
-> using ikcp_send
int sent = ikcp_send(kcp_ptr, payload_buffer, payload_len); // kcp_ptr from ikcp_create call above ikcp_flush(kcp_ptr); ikcp_update(kcp_ptr, 10);

628mspwn

628mspwn1#

Hi,
Findings on above issue:
After ikcp_send. and once we receive data in ikcp_recv we dont want kcp to sent ACK back to sender. but as ACK is not
sent , packets are re-sent, this causing buffer of KCP to cross limit of 1400.
so we forcibly changes application code to delete un acknowlege segment so that sender dont need to re transmit pkt.

so after ikcp_send  below calls are made

ikcp_parse_una(ikcpcb *kcp, IUINT32 una); ikcp_shrink_buf(kcp);
hence packets are getting transmitted correctly.
Let me know if any side-effect using this way.

相关问题