[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-users] Bind port problem
From: |
Atte Kojo |
Subject: |
Re: [lwip-users] Bind port problem |
Date: |
Fri, 10 Mar 2006 09:55:08 +0200 |
User-agent: |
KMail/1.9.1 |
On Thursday 09 March 2006 16:55, Etienne Lanoy wrote:
> tcp_bind(global_pcb, IP_ADDR_ANY, port_configuration);
> global_pcb = tcp_listen(global_pcb);
> tcp_accept(global_pcb, config_server_ip_accept);
>
> The problem is when I execute this code to change the port binded, after
> it, I can connect to my product with the
> old and the new port. The old port isn't unbind.
>
There is an error here in your code. The trick is to understand what
tcp_listen() actually does. It creates a _new_ connection every time a new
connection is opened. When making a tcp server, one pcb is created for the
server that listens for new connections, then tcp_listen() is used to create
the actual client connections that arrive to the server. The listening socket
is actually never opened or used in any other way. It just, well, listens.
Along these lines:
1. Create a listening pcb, server_pcb in this example, with tcp_new()
2. Bind it to a local port
3. Listen to the pcb with tcp_listen(). Assign the return value of
tcp_listen() to a new descriptor, say conn_pcb.
*** At this point you have two allocated pcbs. The listening pcb server_pcb
and the newly opened connection conn_pcb. ***
4. Accept the new connection (conn_pcb) with tcp_accept().
5. Do stuff with the conn_pcb connection.
6. Close conn_pcb with tcp_close()
7. Repeat from step 3.
The whole server is closed, if necessary, by closing the server_pcb with
tcp_close().
What your code does now is that it loses the pointer to the listening pcb
every time a new connection is opened, creating a memory leak. And then the
open connection becomes the new listening pcb. Which again gets lost and so
on.
> How can change the port of my embedded server without have old and new
> port connection capabilities ?
To reiterate, in your situation you must only listen to the global_pcb and
assing the return value of tcp_listen() to some other pcb pointer and then
close that pointer after the client connection is closed. Then when you
re-bind the global_pcb, things should work as intended.
--
Atte Kojo
Software Development Engineer
Elekta Neuromag Oy
Street address: Elimäenkatu 22, Helsinki, Finland
Mailing address: P.O. Box 68, FIN-00511 HELSINKI, Finland
Tel: +358 9 756 24084 (direct), +358 9 756 2400 (operator)
Fax: +358 9 756 24011
E-mail: address@hidden
www.elekta.com
- Re: [lwip-users] sys_timeout, (continued)
- Re: [lwip-users] sys_timeout, Peter Graf, 2006/03/07
- RE: [lwip-users] sys_timeout, Curt McDowell, 2006/03/07
- RE: [lwip-users] sys_timeout, Christiaan Simons, 2006/03/08
- Re: [lwip-users] sys_timeout, Peter Graf, 2006/03/08
- RE: [lwip-users] sys_timeout, Curt McDowell, 2006/03/08
- Re: [lwip-users] sys_timeout, Peter Graf, 2006/03/08
- Re[2]: [lwip-users] sys_timeout, Paulo Figueiredo, 2006/03/08
- Re: [lwip-users] sys_timeout, Peter Graf, 2006/03/08
- RE: [lwip-users] sys_timeout, Curt McDowell, 2006/03/08
- [lwip-users] Bind port problem, Etienne Lanoy, 2006/03/09
- Re: [lwip-users] Bind port problem,
Atte Kojo <=
- Re: [lwip-users] sys_timeout, Derek Guerdon, 2006/03/07