Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/com/cgutman/adblib/AdbConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,15 @@ public void run() {
case AdbProtocol.CMD_OKAY:
case AdbProtocol.CMD_WRTE:
case AdbProtocol.CMD_CLSE:
{
AdbStream waitingStream;

/* We must ignore all packets when not connected */
if (!conn.connected)
continue;

/* Get the stream object corresponding to the packet */
AdbStream waitingStream = openStreams.get(msg.arg1);
waitingStream = openStreams.get(msg.arg1);
if (waitingStream == null)
continue;

Expand All @@ -164,16 +167,15 @@ else if (msg.command == AdbProtocol.CMD_WRTE)
}
else if (msg.command == AdbProtocol.CMD_CLSE)
{
/* He doesn't like us anymore :-( */
conn.openStreams.remove(msg.arg1);

/* Notify readers and writers */
waitingStream.notifyClose();

break;
}
}

break;
continue;
}
case AdbProtocol.CMD_AUTH:

byte[] packet;
Expand All @@ -199,7 +201,7 @@ else if (msg.command == AdbProtocol.CMD_CLSE)
conn.outputStream.write(packet);
conn.outputStream.flush();
}
break;
continue;

case AdbProtocol.CMD_CNXN:
synchronized (conn) {
Expand All @@ -210,22 +212,20 @@ else if (msg.command == AdbProtocol.CMD_CLSE)
conn.connected = true;
conn.notifyAll();
}
break;

default:
/* Unrecognized packet, just drop it */
break;
continue;
}
break;
} catch (Exception e) {
/* The cleanup is taken care of by a combination of this thread
* and close() */
break;
}
}

}
public void interrupt() {
/* This thread takes care of cleaning up pending streams */
synchronized (conn) {
cleanupStreams();
conn.cleanupStreams();
conn.notifyAll();
conn.connectAttempted = false;
}
Expand Down
12 changes: 6 additions & 6 deletions src/com/cgutman/adblib/AdbStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ public byte[] read() throws InterruptedException, IOException

synchronized (readQueue) {
/* Wait for the connection to close or data to be received */
while (!isClosed && (data = readQueue.poll()) == null) {
while (!isClosed() && (data = readQueue.poll()) == null) {
readQueue.wait();
}

if (isClosed) {
if (isClosed()) {
throw new IOException("Stream closed");
}
}
Expand Down Expand Up @@ -163,10 +163,10 @@ public void write(byte[] payload, boolean flush) throws IOException, Interrupted
{
synchronized (this) {
/* Make sure we're ready for a write */
while (!isClosed && !writeReady.compareAndSet(true, false))
while (!isClosed() && !writeReady.compareAndSet(true, false))
wait();

if (isClosed) {
if (isClosed()) {
throw new IOException("Stream closed");
}
}
Expand All @@ -187,7 +187,7 @@ public void write(byte[] payload, boolean flush) throws IOException, Interrupted
public void close() throws IOException {
synchronized (this) {
/* This may already be closed by the remote host */
if (isClosed)
if (isClosed())
return;

/* Notify readers/writers that we've closed */
Expand All @@ -203,7 +203,7 @@ public void close() throws IOException {
* Retreives whether the stream is closed or not
* @return True if the stream is close, false if not
*/
public boolean isClosed() {
public synchronized boolean isClosed() {
return isClosed;
}
}