[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [lwip-users] Newbie question (tcp_pcb* allocation)
From: |
David Aldrich |
Subject: |
RE: [lwip-users] Newbie question (tcp_pcb* allocation) |
Date: |
Fri, 27 Feb 2004 11:37:41 -0000 |
Hi Leon
Thanks for your response. So I conclude that if I want to use a simple
global variable for my connection identifier (leaving aside the
arguments about globals, handles etc) I should reassign the global
variable with the value passed to tcp_accept(). Am I correct?
I wonder whether this could be made clearer in rawapi.txt? This
document explains that tcp_listen returns a new connection identifier,
but it does not explain that the identifier will change again when a
connection is established.
Thanks again
David
> -----Original Message-----
> From: Leon Woestenberg [mailto:address@hidden
> Sent: Thursday, February 26, 2004 9:49 PM
> To: Mailing list for lwIP users
> Subject: Re: [lwip-users] Newbie question (tcp_pcb* allocation)
>
>
> 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
>
>
>
>
> _______________________________________________
>
> lwip-users mailing list
> address@hidden http://mail.gnu.org/mailman/listinfo/lwip-users
>
- RE: [lwip-users] Newbie question (tcp_pcb* allocation),
David Aldrich <=