Продолжу тему. Память куда-то съедает. Ситуация - шлём UDP пакеты, потом перестаёт. Попробовал сообщения включить - ну да, памяти не хватает, а почему не пишет. Фрагменты логов с терминала и функции. Кому не лениво, гляньте пожалуйста.
send - 0, UDP: 43
send - 0, UDP: 44
send - 0, UDP: 45
send - 0, UDP: 46
send - 0, UDP: 46
send - 0, UDP: 46
send - 0, UDP: 47
send - 0, UDP: 48
send - 0, UDP: 68
send - 0, UDP: 69
send - 0, UDP: 69
memp_malloc: out of memory in pool UDP_PCB
problem in udp_new()
вывод
echotool
11:51:40 from 192.168.1.10:49221 received [sending udp client message 64]
11:51:41 from 192.168.1.10:49222 received [sending udp client message 65]
11:51:41 from 192.168.1.10:49223 received [sending udp client message 66]
11:51:42 from 192.168.1.10:49224 received [sending udp client message 67]
11:51:42 from 192.168.1.10:49225 received [sending udp client message 68]
void udp_echoclient_connect(void)
{
struct udp_pcb *upcb;
struct pbuf *p;
struct ip_addr DestIPaddr;
err_t err;
/* Create a new UDP control block */
upcb = udp_new();
if (upcb!=NULL)
{
/*assign destination IP address */
IP4_ADDR( &DestIPaddr, DEST_IP_ADDR0, DEST_IP_ADDR1, DEST_IP_ADDR2, DEST_IP_ADDR3 );
/* configure destination IP address and port */
err= udp_connect(upcb, &DestIPaddr, UDP_SERVER_PORT);
//last_Err = err;
if (err == ERR_OK)
{
/* Set a receive callback for the upcb */
udp_recv(upcb, udp_receive_callback, NULL);
sprintf((char*)data, "sending udp client message %d", (int*)message_count);
/* allocate pbuf from pool*/
p = pbuf_alloc(PBUF_TRANSPORT,strlen((char*)data), PBUF_POOL);
if (p != NULL)
{
/* copy data to pbuf */
pbuf_take(p, (char*)data, strlen((char*)data));
/* send udp data */
last_Err = udp_send(upcb, p);
#ifdef SERIAL_DEBUG
printf("send - %d, ", last_Err);
#endif
last_Err++;
/* free pbuf */
pbuf_free(p);
#ifdef SERIAL_DEBUG
printf("UDP: %d \n\r", message_count);
#endif
}
else
{
/* free the UDP connection, so we can accept new clients */
udp_remove(upcb);
#ifdef SERIAL_DEBUG
printf("\n\r can not allocate pbuf ");
#endif
}
}
else
{
/* free the UDP connection, so we can accept new clients */
udp_remove(upcb);
#ifdef SERIAL_DEBUG
printf("\n\r can not connect udp pcb");
#endif
}
}
else
{
#ifdef SERIAL_DEBUG
printf("\n\r can not create udp pcb");
#endif
}
}
struct udp_pcb *
udp_new(void)
{
struct udp_pcb *pcb;
pcb = (struct udp_pcb *)memp_malloc(MEMP_UDP_PCB);
/* could allocate UDP PCB? */
if (pcb != NULL) {
/* UDP Lite: by initializing to all zeroes, chksum_len is set to 0
* which means checksum is generated over the whole datagram per default
* (recommended as default by RFC 3828). */
/* initialize PCB to all zeroes */
memset(pcb, 0, sizeof(struct udp_pcb));
pcb->ttl = UDP_TTL;
}
#ifdef SERIAL_DEBUG
else {
printf(" problem in udp_new()\r\n");
}
#endif
return pcb;
}