mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-10 15:44:32 +00:00
don't send daemon disconnected on thread interrupted
This commit is contained in:
parent
9461a321be
commit
2001ebf1de
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user