diff --git a/src/pkt_normalizer.c b/src/pkt_normalizer.c index aea1b971..a549e81e 100644 --- a/src/pkt_normalizer.c +++ b/src/pkt_normalizer.c @@ -24,10 +24,9 @@ struct PKTNORM* pn_init(struct ETCP_CONN* etcp) { pn->etcp = etcp; pn->ua = etcp->instance->ua; - // frag_size должен соответствовать размеру блока в data_pool - // data_pool->object_size обычно равен MTU (1500) - pn->frag_size = etcp->instance->data_pool->object_size; - pn->tx_wait_time = 100; // Increased to ensure flush happens between packets + // frag_size = MTU минус резерв для дополнительных опций (ACK и прочие заголовки) + pn->frag_size = etcp->mtu - 100; + pn->tx_wait_time = 1; // 1ms timer for packet coalescing pn->input = queue_new(pn->ua, 0); // No hash needed pn->output = queue_new(pn->ua, 0); // No hash needed @@ -278,9 +277,18 @@ static void etcp_input_ready_cb(struct ll_queue* q, void* arg) { queue_dgram_free(in_dgram); queue_entry_free(in_dgram); - // Send immediately to ensure packet is not lost - pn_send_to_etcp(pn); - pn_buf_renew(pn); + // Check if buffer is almost full (less than 100 bytes remaining) + if (pn->data_ptr + 100 >= pn->data_size) { + // Buffer is almost full - send immediately + pn_send_to_etcp(pn); + pn_buf_renew(pn); + } else { + // Set flush timer to send after tx_wait_time ms + if (pn->flush_timer) { + uasync_cancel_timeout(pn->ua, pn->flush_timer); + } + pn->flush_timer = uasync_set_timeout(pn->ua, pn->tx_wait_time, pn, pn_flush_cb); + } } DEBUG_INFO(DEBUG_CATEGORY_ETCP, "pn_packer: etcp_input_ready_cb finished, processed=%d", processed);