lwip-users
[Top][All Lists]
Advanced

[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: Wed, 16 Jan 2008 08:26:14 -0500

> -----Original Message-----
> From: address@hidden
> [mailto:address@hidden On Behalf
> Of Jonathan Larmour
> Sent: Tuesday, January 15, 2008 9:58 PM
> To: Mailing list for lwIP users
> Subject: Re: [lwip-users] Releasing pcb after tcp_new()
> 
> Bill Auerbach wrote:
> >
> > 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.
> 
> If that's what you want, then don't call tcp_new/tcp_new/tcp_listen again!
> That listening socket still exists. The pcb passed into the accept_handler
>   is not the listening PCB. It's a newly created pcb for the newly
> established connection.

That's what I was missing.  I didn't know I could simply keep the listen pcb
open. 

> If you really want to close the listening PCB then you have to store its
> value somewhere and then explicitly close it. But if you do that, there
> will be a brief window when you are no longer listening.

I didn't know what I wanted, really.  As most (all?) examples show one pcb
pointer in use (the tcp_listen sends in one and gets back another), I
thought I had only one pcb to take care of so I closed it and started over.

I'll do as you suggest - thank you.

Bill Auerbach





reply via email to

[Prev in Thread] Current Thread [Next in Thread]