gpt4 book ai didi

multithreading - 使用 netconn 同时处理多个 LwIP 连接

转载 作者:可可西里 更新时间:2023-11-01 02:48:09 24 4
gpt4 key购买 nike

我尝试使用 LwIP netconn API(在 stm32f4 发现板上)建立多个同时连接。他们都在自己的线程中并且完美地工作。但由于某种原因,同一时间只能建立一个连接。

我的代码基于 ST 回显服务器示例,如下所示:

void myTaskStart(void const * argument)
{
struct netconn *conn, *newconn;
err_t err, accept_err;
struct netbuf* buf;
void* data;
u16_t len;
err_t recv_err;

/* Create a new connection identifier. */
conn = netconn_new(NETCONN_TCP);
if (conn != NULL)
{
err = netconn_bind(conn, NULL, <some port>);

if (err == ERR_OK)
{
/* Tell connection to go into listening mode. */
netconn_listen(conn);

while (1)
{
/* Grab new connection. */
accept_err = netconn_accept(conn, &newconn);

/* Process the new connection. */
if (accept_err == ERR_OK)
{
<do stuff here>

netconn_close(newconn);
netconn_delete(newconn);
}
}
}
else
{
netconn_delete(newconn);
printf(" can not bind TCP netconn");
}
}
else
{
printf("can not create TCP netconn");
}
}

所有线程都在监听不同的端口。但是,如果已经建立了另一个使用不同端口的连接,则所有其他线程都会在 netconn_accept 处失败。它返回 ERR_ABRT,这意味着 连接已中止:在接受期间超出 pcbs 或超出 netconns。我在这里想念什么?

最佳答案

好的。我找到了解决方案。增加 MEMP_NUM_NETBUF 和 MEMP_NUM_NETCONN 使一切正常。

关于multithreading - 使用 netconn 同时处理多个 LwIP 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45190941/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com