Are these out of order connect/disconnect requests from the same client?
Discussion
I guess I am confused as to how they could overlap. Are you waiting on a handshake? Is this Aedile?
It’s not Aedile. If it was, I would’ve said so already. It’s a library at work for which I am now one of 2 maintainers.
They could overlap because they are executed concurrently.
Yes, it is from the same client.
I have to admit I am confused, but if you get a disconnect request from a client for which there is no established connection you can increment a disconnect counter in a mutex then whenever you complete a connect check for a positive disconnect counter, disconnect, and decrement.
If there is an established connection as indicated by a connection counter in the mutex then disconnect right away. It's kind of like counting parentheses.
Are there other sorts of requests that are arriving out of order that require an open connection to be processed? Does the close connection request give any indication of how many to expect?
No it’s all several connections (and disconnections) from the same client. But what you said have given me an idea. I’ll try using semaphores to protect the sensitive parts of the connection and disconnection code.
This worked by the way. I used it to lock access to the bare metal connection and disconnection code so it doesn’t overlap.