From a872b5413e12fbf0fefed9d20b40f5d6caccd66f Mon Sep 17 00:00:00 2001 From: Samuel Carlsson Date: Mon, 17 Mar 2014 21:57:57 +0100 Subject: [PATCH] Support for responding to multiple requests on the same connection --- .../jadb/test/fakes/AdbResponder.java | 70 +++++++++++-------- 1 file changed, 42 insertions(+), 28 deletions(-) diff --git a/test/se/vidstige/jadb/test/fakes/AdbResponder.java b/test/se/vidstige/jadb/test/fakes/AdbResponder.java index fd81fb8..3ce1698 100644 --- a/test/se/vidstige/jadb/test/fakes/AdbResponder.java +++ b/test/se/vidstige/jadb/test/fakes/AdbResponder.java @@ -16,35 +16,49 @@ public class AdbResponder implements Runnable { @Override public void run() - { + { + System.out.println("Serving client"); + try { - System.out.println("Serving client"); - DataInput input = new DataInputStream(socket.getInputStream()); - OutputStreamWriter output = new OutputStreamWriter(socket.getOutputStream()); - byte[] buffer = new byte[4]; - input.readFully(buffer); - String encodedLength = new String(buffer, Charset.forName("utf-8")); - int length = Integer.parseInt(encodedLength, 16); - - buffer = new byte[length]; - input.readFully(buffer); - String command = new String(buffer, Charset.forName("utf-8")); - System.out.println("Command: " + command); - - if ("host:version".equals(command)) { - output.write("OKAY"); - send(output, "001F"); - } - else if ("host:devices".equals(command)) { - output.write("OKAY"); - send(output, "X\tdevice\nY\tdevice"); - } - else - { - output.write("FAIL"); - } - output.flush(); - + + while (true) + { + DataInput input = new DataInputStream(socket.getInputStream()); + OutputStreamWriter output = new OutputStreamWriter(socket.getOutputStream()); + byte[] buffer = new byte[4]; + input.readFully(buffer); + String encodedLength = new String(buffer, Charset.forName("utf-8")); + System.out.println("DEBUG: " + encodedLength); + int length = Integer.parseInt(encodedLength, 16); + + buffer = new byte[length]; + input.readFully(buffer); + String command = new String(buffer, Charset.forName("utf-8")); + System.out.println("Command: " + command); + + if ("host:version".equals(command)) { + output.write("OKAY"); + send(output, "001F"); // version. required to be 31 + System.out.println("OK"); + } + else if ("host:transport-any".equals(command)) + { + output.write("OKAY"); + System.out.println("OK"); + } + else if ("host:devices".equals(command)) { + output.write("OKAY"); + send(output, "X\tdevice\nY\tdevice"); + System.out.println("OK"); + } + else + { + output.write("FAIL"); + send(output, "Unknown command: " + command); + System.out.println("FAIL"); + } + output.flush(); + } } catch (IOException e) { System.out.println(e.getMessage()); }