Re-order handleError (handleComplete)

This commit is contained in:
Manevolent
2018-09-20 02:13:05 -04:00
parent 5ee74e6c45
commit 6bf85e3c6c
@@ -562,8 +562,8 @@ public class LocalTeamspeakClientSocket
private final int returnCode; private final int returnCode;
private final Command command; private final Command command;
private final List<MultiCommand> commands = new LinkedList<>(); private final List<MultiCommand> commands = new LinkedList<>();
private final Object sendLock = new Object();
private Object sendLock = new Object();
private boolean sent = false; private boolean sent = false;
public ClientCommandResponse(int returnCode, public ClientCommandResponse(int returnCode,
@@ -580,7 +580,7 @@ public class LocalTeamspeakClientSocket
throws CommandProcessException { throws CommandProcessException {
if (multiCommand.getName().equalsIgnoreCase("error")) if (multiCommand.getName().equalsIgnoreCase("error"))
try { try {
handleError(multiCommand.simplifyOne()); handleComplete(multiCommand.simplifyOne());
} catch (IOException | TimeoutException e) { } catch (IOException | TimeoutException e) {
throw new CommandProcessException(e); throw new CommandProcessException(e);
} }
@@ -594,7 +594,7 @@ public class LocalTeamspeakClientSocket
throws CommandProcessException { throws CommandProcessException {
if (command.getName().equalsIgnoreCase("error")) if (command.getName().equalsIgnoreCase("error"))
try { try {
handleError(command); handleComplete(command);
} catch (IOException | TimeoutException e) { } catch (IOException | TimeoutException e) {
throw new CommandProcessException(e); throw new CommandProcessException(e);
} }
@@ -602,23 +602,24 @@ public class LocalTeamspeakClientSocket
commands.add(new MultiCommand(command.getName(), ProtocolRole.CLIENT, command)); commands.add(new MultiCommand(command.getName(), ProtocolRole.CLIENT, command));
} }
private void handleError(SingleCommand command) throws IOException, TimeoutException { private void handleComplete(SingleCommand command) throws IOException, TimeoutException {
try { try {
int errorId = Integer.parseInt(command.get("id").getValue());
synchronized (commandSendLock) { synchronized (commandSendLock) {
awaitingCommands.remove(returnCode); awaitingCommands.remove(returnCode);
acceptingReturnCode = calculateAcceptingReturnCode(); acceptingReturnCode = calculateAcceptingReturnCode();
} }
int errorId = Integer.parseInt(command.get("id").getValue());
switch (errorId) { switch (errorId) {
case 0: case 0:
completeSuccess(commands); completeSuccess(commands);
break; break;
default: default:
completeFailure(new CommandException(command.get("msg").getValue(), errorId)); throw new CommandException(command.get("msg").getValue(), errorId);
break;
} }
} catch (Throwable e) {
completeFailure(e);
} finally { } finally {
sendNextCommand(); sendNextCommand();
} }
@@ -637,12 +638,8 @@ public class LocalTeamspeakClientSocket
throws IOException, TimeoutException { throws IOException, TimeoutException {
synchronized (sendLock) { synchronized (sendLock) {
if (!sent) { if (!sent) {
LocalTeamspeakClientSocket.this.writePacket( LocalTeamspeakClientSocket.this.writePacket(new PacketBody2Command(ProtocolRole.CLIENT, command));
new PacketBody2Command(ProtocolRole.CLIENT, command)
);
sent = true; sent = true;
return true; return true;
} }