2017-07-19 3 views
1

LwIP netconn API(stm32f4ディスカバリボード上)を使用していくつかの同時接続を確立しようとしています。それらのすべては、自分のスレッドにあり、完全に動作します。しかし何らかの理由で同時に1つの接続しか確立できません。netconnを使用して複数のLwIP接続を同時に処理する

私のコードは、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を返します。つまり、a connection has been aborted: out of pcbs or out of netconns during acceptを意味します。 私はここで何が欠けていますか?

答えて

1

私は解決策を見つけた。 MEMP_NUM_NETBUFとMEMP_NUM_NETCONNを増やすことで問題が解決しました。

関連する問題