lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] Global reference to pbufs


From: Enrico Murador - Research & Development - CET
Subject: [lwip-users] Global reference to pbufs
Date: Mon, 16 May 2011 12:35:36 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10

Hi all,

On my application (TCP-server based with callback API) I need to limit the number of TCP connections in this way:

the application keeps a list of connection information structures of limited size; when a client requests a connection, the accept callback searches the list for an empty slot. If all the slots are filled (so the maximum number of connections is reached) the callback searches for the oldest "inactive" connection (if present) and closes it; then assigns the slot to the new connection (a connection is marked as "inactive" after every successful query-response cycle, or after a
timeout).
To make this working, I have to keep a reference to the connection pcb as a parameter of the connection info structure; this reference will be used to close the connection from the accept callback of another connection, as I explained.

But how can I ensure that the reference is still valid when I use it to close the connection? (Of course, I have to free the relative connection info structure when the receive callback is called for a pcb with NULL data...)

Another case in wich I must check the validity of the pcb reference is when I have to send data to the client outside of a callback (in this case I think it is also necessary to know if the connection is in a state that allows transfer of data, but maybe I'm wrong...).

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...

Thank you very much

Enrico




reply via email to

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