代码之家  ›  专栏  ›  技术社区  ›  Logen Sand

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

  •  2
  • Logen Sand  · 技术社区  · 9 年前

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

    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 a connection has been aborted: out of pcbs or out of netconns during accept .

    1 回复  |  直到 9 年前
        1
  •  3
  •   Logen Sand    9 年前

    好的。我找到了解决办法。 增加MEMP_NUM_NETBUF和MEMP_NUM_NETCONN可以使事情顺利进行。