title: TCP Server on LwIP raw API - question about tcp_close and accept callback
body: <p>I'm using <a href="https://github.com/dreamcat4/lwip/blob/master/contrib/apps/tcpecho_raw/echo.c" rel="nofollow noreferrer">this</a> simple echo-server as an example.
  It creates a listening connection, receives a packet, sends it back and then closes the connection.</p>
  
  <p>In the initialization function, accept callback is registered in lwip like this:</p>
  
  <pre><code>void
  echo_init(void)
  {
      echo_pcb = tcp_new();
      ...
      echo_pcb = tcp_listen(echo_pcb);
      tcp_accept(echo_pcb, echo_accept);
  </code></pre>
  
  <p>Connection is closed by the server after each echo session, like this: </p>
  
  <pre><code>void
  echo_close(struct tcp_pcb *tpcb, struct echo_state *es)
  {
    tcp_arg(tpcb, NULL);
    tcp_sent(tpcb, NULL);
    tcp_recv(tpcb, NULL);
    tcp_err(tpcb, NULL);
    tcp_poll(tpcb, NULL, 0);
  
    if (es != NULL)
    {
      mem_free(es);
    }  
    tcp_close(tpcb);
  </code></pre>
  
  <p><a href="http://www.nongnu.org/lwip/2_1_x/group__tcp__raw.html#ga87093e137fcc53ea82a134a3f5b33623" rel="nofollow noreferrer">Documentation</a> says that <code>tcp_close</code> will free pcb structure. All of the callbacks that are used for tcp server are registered with this structure.</p>
  
  <p>But when client sends new packet and starts a new connection, accept callback is called! Even though <code>tcp_accept(echo_pcb, echo_accept);</code> (i.e. callback registration) is done only once in the <code>init</code> function and that <code>echo_pcb</code> structure is already freed after <code>tcp_close</code>.</p>
  
  <p>So I'm confused. Why all the other callbacks are registered multiple times but accept is registered only once? Is it okay to do it like this?</p>