Reorganizing the removal of awaiting commands and so forth in hopes that lock-ups don't happen on reconnect.

This commit is contained in:
Manevolent
2018-10-22 13:40:43 -04:00
parent a85904555e
commit efd4b4b771
@@ -359,8 +359,16 @@ public class LocalTeamspeakClientSocket
// Free stuff // Free stuff
serverId = null; serverId = null;
synchronized (commandSendLock) {
for (Integer id : new ArrayList<>(awaitingCommands.keySet())) {
ClientCommandResponse response = awaitingCommands.get(id);
response.completeFailure(new IOException("client disconnected"));
}
awaitingCommands.clear(); awaitingCommands.clear();
acceptingReturnCode = 0; calculateAcceptingReturnCode();
}
setOption("client.hostname", remote.getHostString()); setOption("client.hostname", remote.getHostString());
@@ -604,11 +612,6 @@ public class LocalTeamspeakClientSocket
private void handleComplete(SingleCommand command) throws IOException, TimeoutException { private void handleComplete(SingleCommand command) throws IOException, TimeoutException {
try { try {
synchronized (commandSendLock) {
awaitingCommands.remove(returnCode);
acceptingReturnCode = calculateAcceptingReturnCode();
}
int errorId = Integer.parseInt(command.get("id").getValue()); int errorId = Integer.parseInt(command.get("id").getValue());
switch (errorId) { switch (errorId) {
@@ -621,9 +624,13 @@ public class LocalTeamspeakClientSocket
} catch (Throwable e) { } catch (Throwable e) {
completeFailure(e); completeFailure(e);
} finally { } finally {
synchronized (commandSendLock) {
awaitingCommands.remove(getReturnCode());
acceptingReturnCode = calculateAcceptingReturnCode();
sendNextCommand(); sendNextCommand();
} }
} }
}
public int getReturnCode() { public int getReturnCode() {
return returnCode; return returnCode;