tcp - TM4C1294NCPDT:发送数据 2/3 小时后以太网连接中断
问题描述
我一直在尝试通过以太网将数据从我的设备/网关发送到 tcp 服务器。与服务器和我的设备连接一次后,我在没有关闭连接的情况下发送数据。我得到了 tcp_echoclient_connected 中的套接字信息,如 es2 和 tpcbSa。获得套接字信息后,我在 tcp_echoserver_send3 函数中使用此信息。因此我能够每 5 秒发送一次所有数据。但是 2/3 小时后 wr_err 返回 ERR_MEM。然后停止发送数据。我想通过以太网发送数据而不每 5 秒停止一次。我想在返回 ERR_MEM 后,我用 tcp_write 函数发送请求。但它没有成功。
所以,
-为什么 wr_err 在 2/3 小时后返回 ERR_MEM?我该如何避免这种情况?
或者
- 返回 ERR_MEM 后,我应该怎么做才能返回 ERR_OK 或继续发送数据?
你有什么想法或建议来解决这个问题吗?
谢谢你
//
// Connect to host address
//
if(ETH_Ctrl.eth_data_repeat == ETH_REPEAT_2 )
{
tcp_echoclient_connect(Gateway.Host_Address,Gateway.Remote_Port_Number);
}
else if(ETH_Ctrl.eth_data_repeat == ETH_REPEAT_1)
{
memcpy(data,Gateway.tcp_message,Gateway.tcp_message_length);
tcp_echoserver_send3(tpcbSa, (unsigned char*)data, sizeof(data), es2);
}
void tcp_echoclient_connect(char* IP_ARR,char* PORT_NUM)
{
{
/* create new tcp pcb */
echoclient_pcb = tcp_new();
if (echoclient_pcb != NULL)
{
ETH_Ctrl.eth_data_repeat = ETH_REPEAT_1;
ipaddr_aton((const char *)IP_ARR,&DestIPaddr);
DestPORTAddr = atoi(PORT_NUM);
/* connect to destination address/port */
tcp_connect(echoclient_pcb,&DestIPaddr,DestPORTAddr,tcp_echoclient_connected);
}
}
}
/**
* @brief Function called when TCP connection established
* @param tpcb: pointer on the connection contol block
* @param err: when connection correctly established err should be ERR_OK
* @retval err_t: returned error
*/
static err_t tcp_echoclient_connected(void *arg, struct tcp_pcb *tpcb, err_t err)
{
struct echoclient *es = NULL;
if (err == ERR_OK)
{
/* allocate structure es to maintain tcp connection informations */
es = (struct echoclient *)mem_malloc(sizeof(struct echoclient));
if (es != NULL)
{
es->state = ES_CONNECTED;
es->pcb = tpcb;
tpcbSa = tpcb;
if(ETH_Ctrl.connectTYPE == ETHERNET_POST)
{
memcpy(data,Gateway.tcp_message,Gateway.tcp_message_length); //1024 tcp message datanın ilk 792 adet datası databuffer içine kaydedilir
/* allocate pbuf */
es->p_tx = pbuf_alloc(PBUF_TRANSPORT, sizeof(data) , PBUF_POOL); //burası gönderilen buffer ile aynı ozellikte bos bir buffer yaratıyor
es2=es;
return ERR_OK;
}
}
else
{
{
/* close connection */
tcp_echoclient_connection_close(tpcb, es);
/* return memory allocation error */
return ERR_MEM;
}
}
}
else
{
/* close connection */
tcp_echoclient_connection_close(tpcb, es);
}
return err;
}
void tcp_echoserver_send3(struct tcp_pcb *tpcb, unsigned char *Source, unsigned int Size, struct echoclient * es)
{
err_t wr_err = ERR_OK;
/* enqueue data for transmission */
wr_err = tcp_write(tpcb, Source, Size, 1); //TCP_WRITE_FLAG_COPY
if(wr_err == ERR_OK)
{
if(es->p_tx != NULL)
{
/* increment reference count for es->p */
pbuf_ref(es->p_tx);
}
}
else if(wr_err == ERR_MEM)
{
tcp_write(tpcb, Source, Size, 1);
if (sizeof(data) > tcp_sndbuf(tpcb))
{
usb_printf("Not enough memory. Could not send data buffer\n", 50);
}
}
else
{
}
}
解决方案
推荐阅读
- pagination - Google 如何避免更改影响分页的算法?
- python - 将公式作为参数传递给函数/列表理解
- xml - XSLT 将值“替换”为通过同级文本内容匹配的另一个文件
- python - Tensorflow:可以释放GPU资源的模型包装器
- java - 将 2D 输入数组转换为非平衡 BST
- c++ - Ns3 - 如何通过 CCH 通道(wave-simple-device.cc 编辑)定期在 VANET 中发送 WSMP 数据包?
- swift - 使用组合框架的按钮操作
- python - Python 3.7 tkinter 8 - 即时更改菜单项“命令”选项
- html - 无法在导航栏 html 中显示徽标
- swift - Swift Decodable,Endpoint 返回完全不同的类型