lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] Global reference to pbufs


From: Kieran Mansley
Subject: Re: [lwip-users] Global reference to pbufs
Date: Mon, 16 May 2011 11:53:15 +0100

On Mon, 2011-05-16 at 12:35 +0200, Enrico Murador - Research &
Development - CET wrote:
> Is it possible to "ask" the TCP stack to check if a pcb reference is 
> still "usable"?
> Actually, when I have to close a pcb outside of one of its callbacks,
> I 
> first check if the pcb is referenced in one of the
> tcp_listen_pcbs, tcp_active_pcbs, tcp_bound_pcbs and tcp_tw_pcbs
> lists; 
> if the reference is not found, I consider that the pcb is
> already deallocated.
> Similarly, before I have to call tcp_write outside callbacks, I check 
> for a reference but only in tcp_active_pcbs list.
> But I'm not sure that this approach is correct...

This is all a bit of an API violation, so I wouldn't do it that way.

The PCB should remain valid after you have accepted it until either (i)
the application closes it (and so you should already know about this);
or (ii) the stack closes it (e.g. because it receives a reset from the
other end) and it will then call your tcp_err() callback (I think, from
memory, so worth checking) to tell you about this.  If you use this
callback to update your application state then you should find that the
PCBs you are referencing are always valid.

Be careful about the context you are using to access these PCBs.  For
example, if you are closing connections from the accept callback (as
described above) this will be in the context of whatever is executing
the stack; you need to make sure that other contexts aren't also using
that PCB to send data.

Kieran





reply via email to

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