Altera_Forum
Honored Contributor
19 years agoWhy is sending tcp so much slower than receiving?
I have some code running under uC-OS that receives a file via TCP and then writes it to flash. This is very quick, a 4MB file is received in 20 seconds or so. I then have another piece of code that dumps the content of flash via TCP. This is extremely slow, it takes at least 20 minutes to send all 16MB. Here's the code:
void send_flash_data(struct tcp_pcb * tpcb, alt_u32 * offset)
{
err_t err;
alt_u32 send_data_length = EXT_FLASH_BASE + EXT_FLASH_SIZE - *offset;
INT8U error_code;
//printf("send_data_length: %d\n", send_data_length);
if ( send_data_length > 0 ) //data left to send
{
if ( send_data_length > 1400 )
{
send_data_length = 1400;
}
//printf("Sending %d bytes from %08x\n", send_data_length, EXT_FLASH_BASE + *offset);
err = tcp_write(tpcb, (void *)(EXT_FLASH_BASE + *offset), send_data_length, 0);
*offset += send_data_length;
}
else
{
tcp_arg(tpcb, NULL);
tcp_sent(tpcb, NULL);
tcp_close(tpcb);
error_code = OSQPost(TcpTransmissionDoneQ, 4194304);
alt_SSSErrorHandler(error_code, 0);
}
}
err_t flash_data_sent(void * arg, struct tcp_pcb * tpcb, alt_u16 len)
{
//printf("%d bytes acknowledged\n", len);
send_flash_data(tpcb, arg);
}
err_t tcp_connected(void * arg, struct tcp_pcb * tpcb, err_t err)
{
if ( err == ERR_OK )
{
send_flash_data(tpcb, arg);
}
else
{
printf("tcp_connected called with error value %d\n", err);
tcp_arg(tpcb, NULL);
tcp_sent(tpcb, NULL);
tcp_close(tpcb);
}
}
void dump_flash(void * arg)
{
struct ip_addr ip;
IP4_ADDR(&ip, lwip_config.remote_ip_0, lwip_config.remote_ip_1, lwip_config.remote_ip_2, lwip_config.remote_ip_3);
tcp_snd_pcb = tcp_new();
tcp_arg(tcp_snd_pcb, arg);
tcp_sent(tcp_snd_pcb, flash_data_sent);
tcp_connect(tcp_snd_pcb, &ip, lwip_config.rule_receive_tcp_port, tcp_connected);
}