On 6/26/17 2:40 PM, Sönke Ludwig wrote:

In general, nothing speaks against adding a way to discard connections.
It's mostly just that all previous use cases involved high level
connections that had to carry a connection reestablishment logic anyway,
and removing an arbitrary connection is not efficient for many
concurrent connections, because right now they are kept in an array.

Well, you return them by value anyway. So swapping the removed
connection with the last element should work and be an O(1) operation.

(Having said that, I've just looked at the code and lockConnection
currently iterates over the array to find a free connection, so the
efficiency argument is kind of moot, and this needs to be improved anyway.)

You could use a free list if you allocate a pointer along with each
array element.

There are also other ways to optimize. You are actually storing a hash
for the semaphores, which is allocating a bunch of little blocks anyway.
I think the whole structure can be made much faster with some better
design ideas.

-Steve