In my project I want to use an LED to show whether there are any ongoing TCP sessions (or, more generally, any "network connection").
I've tried using a global counter that is incremented when a session is established, and decremented when a session is closed; so, if the counter is greater than zero, then it means there is some session established.
I haven't really gotten this to work well. What happens is that the counter ends up getting decremented multiple times when a session closes. I searched out the places in tcp.c where the listening application is sent the TCP_EVENT_CONNECTED and TCP_EVENT_CLOSED, but it seems like in some cases several of the TCP_EVENT_CLOSED locations are hit when the session is closed. The behavior I see is that if I just open and close a Telnet session, the status works fine. But if I copy files to the unit via FTP while the Telnet session is still open, the status gets changed back to "no session established' (i.e. the counter gets decrement to <= 0), even though the Telnet session has not been closed.
I realize another way to do this would be to update the global counter at the application level (i.e. in the Telnet server, and Web server, and FTP server, and so on, but it would obviously be better for it to be more generic.
Can anyone suggest a way to do this?