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: Jonathan Larmour
Subject: Re: [lwip-users] Releasing pcb after tcp_new()
Date: Wed, 16 Jan 2008 02:57:52 +0000
User-agent: Mozilla Thunderbird 1.0.8-1.1.fc4 (X11/20060501)

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.

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.

Jifl
--
eCosCentric Limited      http://www.eCosCentric.com/     The eCos experts
Barnwell House, Barnwell Drive, Cambridge, UK.       Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.
------["The best things in life aren't things."]------      Opinions==mine




reply via email to

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