private String mSocket;
private INativeDaemonConnectorCallbacks mCallbacks;
+ private final int BUFFER_SIZE = 4096;
+
class ResponseCode {
public static final int ActionInitiated = 100;
}
private void listenToSocket() throws IOException {
- LocalSocket socket = null;
+ LocalSocket socket = null;
try {
socket = new LocalSocket();
InputStream inputStream = socket.getInputStream();
mOutputStream = socket.getOutputStream();
- byte[] buffer = new byte[4096];
+ byte[] buffer = new byte[BUFFER_SIZE];
+ int start = 0;
while (true) {
- int count = inputStream.read(buffer);
+ int count = inputStream.read(buffer, start, BUFFER_SIZE - start);
if (count < 0) break;
- int start = 0;
for (int i = 0; i < count; i++) {
if (buffer[i] == 0) {
String event = new String(buffer, start, i - start);
start = i + 1;
}
}
+ if (start != count) {
+ final int remaining = BUFFER_SIZE - start;
+ System.arraycopy(buffer, start, buffer, 0, remaining);
+ start = remaining;
+ } else {
+ start = 0;
+ }
}
} catch (IOException ex) {
Slog.e(TAG, "Communications error", ex);