[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [lwip-users] Releasing pcb after tcp_new()
From: |
Bill Auerbach |
Subject: |
RE: [lwip-users] Releasing pcb after tcp_new() |
Date: |
Tue, 15 Jan 2008 17:24:13 -0500 |
Simon,
Sorry it's not clear - I know I have a problem but it's hard to put down.
In code fragments, I'm using:
pcb = tcp_new();
tcp_bind(pcb, ipAddr, port );
pcb = tcp_listen( pcb );
LWIP_ASSERT( " NULL pcb", pcb != NULL );
tcp_accept(pcb, accept_handler );
The accept_handler does:
tcp_arg( pcb, an_arg );
tcp_sent( pcb, sent_handler );
tcp_recv( pcb, receive_handler );
tcp_poll( pcb, poll_handler, 4 );
tcp_err( pcb, error_handler );
When the sent_handler has no more data to send, it closes the pcb and reruns
the bind/listen code above to bind and listen to the port (80). This way
I'm always waiting for an HTTP requests and can send a status page back.
Eventually, that LWIP_ASSERT fails because the allocation of the listen pcb
is NULL, and memp_stats for listen pcbs has an error and all listen pcbs are
allocated. I've left things running for a long time and never see the
listen pcbs freed. tcp_close eventually does close the waiting pcb from the
bind, but the listen pcb is orphaned.
In httpd, add code in close_conn to call httpd_init to start the connection
over. Refresh the page a few times and you'll see the error - the
tcp_listen returns NULL.
My solution mentioned was just a (bad) idea to, on the bind pcb close and
free, free the listen pcb used at the same time.
Thanks,
Bill Auerbach
> -----Original Message-----
> From: address@hidden
> [mailto:address@hidden On Behalf
> Of address@hidden
> Sent: Tuesday, January 15, 2008 1:22 PM
> To: Mailing list for lwIP users
> Subject: Re: [lwip-users] Releasing pcb after tcp_new()
>
> Bill,
>
> I don't quite seem to understand your problem: you have 2 pcbs (one
> listening - lpcb - and another accepted through that listen pcb - cpcb)?
> If so, where exactly is the problem? Can't you tcp_close(lpcb) after
> accepting and tcp_close(cpcb) when you're done with that connection? The
> lpcb should be deallocated right away and the cpcb should be deallocated
> after its obligatory time in TIME_WATE state.
>
> How does connecting the listen pcb to the connected pcb solve problems
> here? - Which problems?
>
> Simon
>
> Bill Auerbach schrieb:
> >
> > Simon,
> >
> > Does it make sense to include a listen_pcb pointer in tcp_pcb that
> > tcp_bind fills in (otherwise it's NULL). On the final close of the
> > pcb, if tcp_listen isn't NULL, memp_free it as well. In spite of you
> > asking if it's valid to bind to an open pcb, this resolves the leak
> > because tcp_listen is grabbing a new tcp.
> >
> > Bill Auerbach
> >
> > ------------------------------------------------------------------------
> >
> > *From:* address@hidden
> > [mailto:address@hidden *On
> > Behalf Of *Goldschmidt Simon
> > *Sent:* Monday, January 14, 2008 10:02 AM
> > *To:* Rick Culver; Mailing list for lwIP users
> > *Subject:* RE: [lwip-users] Releasing pcb after tcp_new()
> >
> > I have filed a bug report about the tcp_bind() question, so that it
> > doesn't get lost:
> >
> > http://savannah.nongnu.org/bugs/?22020
> >
> > Simon
> >
> > --------------------------------------------------------------------
> ----
> >
> > *Von:*
> > address@hidden
> > [mailto:lwip-users-bounces+sgoldschmidt=de.pepperl-
> address@hidden
> > *Im Auftrag von *Rick Culver
> > *Gesendet:* Montag, 14. Januar 2008 15:28
> > *An:* Mailing list for lwIP users
> > *Betreff:* Re: [lwip-users] Releasing pcb after tcp_new()
> >
> > Bill,
> >
> > Thanks for the response. After some more investigation I
> > discovered that you are correct, it appears the pcb does get
> > released by the stack but not immediately after the tcp_close()
> > function. I can wait until the state == CLOSED but I would think
> > that by then the pcb would have already been released by the stack
> > and my pointer to the pcb could be pointing to erroneous memory.
> > Not sure about that. Anyway, thanks for the help and hopefully
> > someone else will pick up on this tread and provide some more input.
> >
> > Rick
> >
> > ----- Original Message -----
> >
> > *From:* Bill Auerbach <mailto:address@hidden>
> >
> > *To:* 'Mailing list for lwIP users'
> > <mailto:address@hidden>
> >
> > *Sent:* Wednesday, January 09, 2008 12:17 PM
> >
> > *Subject:* RE: [lwip-users] Releasing pcb after tcp_new()
> >
> > Rick,
> >
> > We're going down the same path, more or less. One thing to
> > watch on tcp_close is the tcb_pcb isn't actually finished
> > being used until later - one of the tcp timers is completing
> > the connection. This ties up pcbs internally for older
> > connections until they are closed. Allocate MEMP_NUM_TCP_PCB
> > to twice what you think - or more if you are opening and
> > closing connections a lot.
> >
> > One thing I would like to see is a callback when the pcb is
> > going to be deallocated so that dynamic memory associated with
> > it can be released when the data is sent and the connection
> > completes later. Maybe someone knows already how to do this?
> >
> > Thanks,
> >
> > Bill Auerbach
> >
> > ----------------------------------------------------------------
> --------
> >
> > *From:*
> > address@hidden
> > [mailto:address@hidden
> > *On Behalf Of *Rick Culver
> > *Sent:* Wednesday, January 09, 2008 12:29 PM
> > *To:* address@hidden
> > *Subject:* [lwip-users] Releasing pcb after tcp_new()
> >
> > I am using CALLBACK API and set up a pcb using tcp_new()
> > followed by tcp_bind() followed by tcp_listen() &
> > tcp_accept(). In my accept() for a valid connection I use
> > tcp_close() to close the LISTEN connection to avoid any
> > additional connection requests for a new connection. When I am
> > done using the connection I use tcp_close() to shut it down
> > and then repeat the process with tcp_new() to start a new
> > LISTEN port. My problem is 2 fold.
> >
> > First I find that the 2nd time through the tcp_bind() function
> > I get an ERR_USE return which appears to be caused by the
> > active list of pcb still having the old port number in it. I
> > think ther is a problem with tcp_bind() which causes this to
> > happen.
> >
> > Secondly (and the biggest problem) is that once I get the
> > ERR_USE then I have a pcb allocated and this consumes pcb
> > space and I eventually run out of space. So the question is,
> > if I get an error with tcp_bind() how can I release the pcb
> > allocated by the tcp_new() so I do not consume pcb memory
> > space and fill it up. I think there could be a problem with
> > tcp_bind() giving this error which is also an issue. Can
> > anyone suggest how to approach these problems?
> >
> > Rick
> >
> > ----------------------------------------------------------------
> --------
> >
> > _______________________________________________
> > lwip-users mailing list
> > address@hidden
> > http://lists.nongnu.org/mailman/listinfo/lwip-users
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > lwip-users mailing list
> > address@hidden
> > http://lists.nongnu.org/mailman/listinfo/lwip-users
> > ------------------------------------------------------------------------
> >
> > No virus found in this incoming message.
> > Checked by AVG Free Edition.
> > Version: 7.5.516 / Virus Database: 269.19.0/1216 - Release Date:
> 09.01.2008 10:16
> >
>
>
>
> _______________________________________________
> lwip-users mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/lwip-users
- [lwip-users] Releasing pcb after tcp_new(), Rick Culver, 2008/01/09
- RE: [lwip-users] Releasing pcb after tcp_new(), Bill Auerbach, 2008/01/09
- Re: [lwip-users] Releasing pcb after tcp_new(), address@hidden, 2008/01/09
- Re: [lwip-users] Releasing pcb after tcp_new(), Rick Culver, 2008/01/14
- RE: [lwip-users] Releasing pcb after tcp_new(), Goldschmidt Simon, 2008/01/14
- RE: [lwip-users] Releasing pcb after tcp_new(), Bill Auerbach, 2008/01/14
- Re: [lwip-users] Releasing pcb after tcp_new(), address@hidden, 2008/01/15
- RE: [lwip-users] Releasing pcb after tcp_new(),
Bill Auerbach <=
- Re: [lwip-users] Releasing pcb after tcp_new(), Jonathan Larmour, 2008/01/15
- RE: [lwip-users] Releasing pcb after tcp_new(), Bill Auerbach, 2008/01/16