don't send daemon disconnected on thread interrupted

This commit is contained in:
matthias.ringwald@gmail.com 2015-01-11 22:20:58 +00:00
parent 9461a321be
commit 2001ebf1de
3 changed files with 11 additions and 3 deletions

View File

@ -42,7 +42,7 @@ public class SocketConnectionUnix extends SocketConnection {
* @see com.bluekitchen.btstack.SocketConnection#sendPacket(com.bluekitchen.btstack.Packet)
*/
@Override
public boolean sendPacket(Packet packet) {
public synchronized boolean sendPacket(Packet packet) {
if (out == null) return false;

View File

@ -69,8 +69,11 @@ public class BTstackClient {
rxThread = new Thread(new Runnable(){
@Override
public void run() {
while (socketConnection != null && !Thread.currentThread().isInterrupted()){
while (socketConnection != null){
Packet packet = socketConnection.receivePacket();
if (Thread.currentThread().isInterrupted()){
return;
}
if (packet == null) {
// server disconnected
System.out.println("Rx Thread: Daemon Disconnected");
@ -116,8 +119,13 @@ public class BTstackClient {
public void disconnect(){
if (socketConnection == null) return;
if (rxThread == null) return;
// signal rx thread to stop
rxThread.interrupt();
// wait for thread stopped
rxThread.join();
// disconnect socket
socketConnection.disconnect();
// done
socketConnection = null;
}
}

View File

@ -43,7 +43,7 @@ public class SocketConnectionTCP extends SocketConnection {
* @see com.bluekitchen.btstack.SocketConnection#sendPacket(com.bluekitchen.btstack.Packet)
*/
@Override
public boolean sendPacket(Packet packet) {
public synchronized boolean sendPacket(Packet packet) {
if (out == null) return false;