lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] Newbie question (tcp_pcb* allocation)


From: Leon Woestenberg
Subject: Re: [lwip-users] Newbie question (tcp_pcb* allocation)
Date: Thu, 26 Feb 2004 22:33:20 +0100
User-agent: Mozilla Thunderbird 0.5 (Windows/20040207)

Hello David,

David Aldrich wrote:
At the risk of hogging the mailing list, I would like to ask another
>
There is no such thing as too much intelligent questions :-)

my_pcb = tcp_new();
[my_pcb = ValueA]

tcp_bind(my_pcb);

my_pcb = tcp_listen(my_pcb);
[my_pcb = ValueB]

tcp_accept(my_pcb);

Now I understand that tcp_listen reallocates the connection id, so all
is fine so far,  However, when the connection is established, my accept
callback gets called with pcb = ValueA.  Surely, pcb should have ValueB
at this point.  Can anyone explain this please?

Without looking at the code, we happens is that lwIP (re)allocates a
bigger structure. However, if realloc() has free memory available
after the existing structure, you might get the same pointer back; with the (unvisible) difference that it now points to a bigger area.

I want to keep my connection identifier as a static variable that my
functions can access to pass to tcp_write etc.  However, presently its
not clear to me how to assign this variable: use the value returned by
tcp_new() or tcp_listen()?

static tcp_pcb *my_pcb = tcp_new();

< do not use the pcb here, for things other than cleaning it up >

my_pcb  = tcp_listen(my_pcb);

< now have your app use this pcb >


If the above is incorrect, pls list, correct me.

However, thing twice about using a static variable; why not have a
connection handle that has all the state information about this
TCP connection, that you pass to all functions?

It is much more scalable and allows for multiple connections in the
future, more state variables you might want to take account of in
the future, etc...

Unless you are really really deeply embedded where every byte counts,
I usually allow my code to scale up.

Leon.




reply via email to

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