OK, I've had a chance to try the proposed patch (after much fiddling around with updates).
My conclusion: it fixes the big problem everyone has been having, but still contains a bug.
The bug is this: if two clients try to connect at the same time, then the second one will block (which I think is OK, that's not the problem). However, when the first one disconnects, the second one will receive a "connection reset by peer".
The problem as I see it is that
is in the wrong place. You really ought not to put it there! It closes the listening socket on disconnecting the first client, which means that anything that was connected to it at the time will be disconnected.
The code I presented in my previous post fixes that issue. (It may contain other problems, though.)