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:48:57 +0100
User-agent: Mozilla Thunderbird 0.5 (Windows/20040207)

Hello David,

pls. ignore my earlier reply. It did contain a wrong explanation.

I just looked in the code as I became curious what goes on.


David Aldrich wrote:

my_pcb = tcp_new();
[my_pcb = ValueA]

tcp_bind(my_pcb);

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

tcp_accept(my_pcb);


tcp_new() returns a full TCP protocol control block (PCB).
tcp_listen() returns a minimal PCB, as it does not have to keep connection state.

During listening, when a connect is received (SYN | ACK),
tcp_listen_inputs() gets called, which once again, allocates a
full TCP PCB.

Now, as the first (ValueA) had been de-allocated earlier, that
same memory area makes a good chance of being allocated again.

So, your callback is called with ValueC, that happens to be
equal to ValueA. Do not count on it.

Co-developers, is there a way to allocate a listening TCP PCB
from start? The above looks quite over-the-head for simply
accepting a connection, although it does hide the gory details.

Leon.





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?

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()?

Thank you

David


_______________________________________________
lwip-users mailing list
address@hidden
http://mail.gnu.org/mailman/listinfo/lwip-users





reply via email to

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