kopia lustrzana https://github.com/ge0rg/aprsdroid
bt, tcp: kill race condition on service start
rodzic
68f559acca
commit
f5249add10
|
@ -61,7 +61,7 @@ class BluetoothTnc(service : AprsService, prefs : PrefsWrapper) extends AprsIsUp
|
||||||
class BtSocketThread(ba : BluetoothAdapter, tnc : BluetoothDevice)
|
class BtSocketThread(ba : BluetoothAdapter, tnc : BluetoothDevice)
|
||||||
extends Thread("APRSdroid Bluetooth connection") {
|
extends Thread("APRSdroid Bluetooth connection") {
|
||||||
val TAG = "BtSocketThread"
|
val TAG = "BtSocketThread"
|
||||||
var running = false
|
var running = true
|
||||||
var socket : BluetoothSocket = null
|
var socket : BluetoothSocket = null
|
||||||
var reader : KissReader = null
|
var reader : KissReader = null
|
||||||
var writer : KissWriter = null
|
var writer : KissWriter = null
|
||||||
|
@ -96,7 +96,6 @@ class BluetoothTnc(service : AprsService, prefs : PrefsWrapper) extends AprsIsUp
|
||||||
this.synchronized {
|
this.synchronized {
|
||||||
reader = new KissReader(socket.getInputStream())
|
reader = new KissReader(socket.getInputStream())
|
||||||
writer = new KissWriter(socket.getOutputStream())
|
writer = new KissWriter(socket.getOutputStream())
|
||||||
running = true
|
|
||||||
}
|
}
|
||||||
Log.d(TAG, "init_socket() done")
|
Log.d(TAG, "init_socket() done")
|
||||||
}
|
}
|
||||||
|
@ -105,10 +104,10 @@ class BluetoothTnc(service : AprsService, prefs : PrefsWrapper) extends AprsIsUp
|
||||||
Log.d(TAG, "BtSocketThread.run()")
|
Log.d(TAG, "BtSocketThread.run()")
|
||||||
try {
|
try {
|
||||||
init_socket()
|
init_socket()
|
||||||
|
service.postPosterStarted()
|
||||||
} catch {
|
} catch {
|
||||||
case e : Exception => e.printStackTrace(); service.postAbort(e.toString())
|
case e : Exception => e.printStackTrace(); service.postAbort(e.toString()); running = false;
|
||||||
}
|
}
|
||||||
service.postPosterStarted()
|
|
||||||
while (running) {
|
while (running) {
|
||||||
try {
|
try {
|
||||||
Log.d(TAG, "waiting for data...")
|
Log.d(TAG, "waiting for data...")
|
||||||
|
|
|
@ -55,7 +55,7 @@ class TcpUploader(service : AprsService, prefs : PrefsWrapper) extends AprsIsUpl
|
||||||
class TcpSocketThread(host : String, port : Int)
|
class TcpSocketThread(host : String, port : Int)
|
||||||
extends Thread("APRSdroid TCP connection") {
|
extends Thread("APRSdroid TCP connection") {
|
||||||
val TAG = "APRSdroid.TcpSocketThread"
|
val TAG = "APRSdroid.TcpSocketThread"
|
||||||
var running = false
|
var running = true
|
||||||
var socket : Socket = null
|
var socket : Socket = null
|
||||||
var reader : BufferedReader = null
|
var reader : BufferedReader = null
|
||||||
var writer : PrintWriter = null
|
var writer : PrintWriter = null
|
||||||
|
@ -65,6 +65,10 @@ class TcpUploader(service : AprsService, prefs : PrefsWrapper) extends AprsIsUpl
|
||||||
service.postAddPost(StorageDatabase.Post.TYPE_INFO, R.string.post_info,
|
service.postAddPost(StorageDatabase.Post.TYPE_INFO, R.string.post_info,
|
||||||
service.getString(R.string.post_connecting, host, port.asInstanceOf[AnyRef]))
|
service.getString(R.string.post_connecting, host, port.asInstanceOf[AnyRef]))
|
||||||
this.synchronized {
|
this.synchronized {
|
||||||
|
if (!running) {
|
||||||
|
Log.d(TAG, "init_socket() aborted")
|
||||||
|
return;
|
||||||
|
}
|
||||||
socket = new Socket(host, port)
|
socket = new Socket(host, port)
|
||||||
socket.setKeepAlive(true)
|
socket.setKeepAlive(true)
|
||||||
socket.setSoTimeout(so_timeout*1000)
|
socket.setSoTimeout(so_timeout*1000)
|
||||||
|
@ -74,7 +78,6 @@ class TcpUploader(service : AprsService, prefs : PrefsWrapper) extends AprsIsUpl
|
||||||
socket.getOutputStream()), true)
|
socket.getOutputStream()), true)
|
||||||
Log.d(TAG, login + setupFilter())
|
Log.d(TAG, login + setupFilter())
|
||||||
writer.println(login + setupFilter())
|
writer.println(login + setupFilter())
|
||||||
running = true
|
|
||||||
}
|
}
|
||||||
Log.d(TAG, "init_socket() done")
|
Log.d(TAG, "init_socket() done")
|
||||||
}
|
}
|
||||||
|
@ -85,10 +88,10 @@ class TcpUploader(service : AprsService, prefs : PrefsWrapper) extends AprsIsUpl
|
||||||
Log.d(TAG, "TcpSocketThread.run()")
|
Log.d(TAG, "TcpSocketThread.run()")
|
||||||
try {
|
try {
|
||||||
init_socket()
|
init_socket()
|
||||||
|
service.postPosterStarted()
|
||||||
} catch {
|
} catch {
|
||||||
case e : Exception => service.postAbort(e.toString())
|
case e : Exception => service.postAbort(e.toString()); running = false
|
||||||
}
|
}
|
||||||
service.postPosterStarted()
|
|
||||||
while (running) {
|
while (running) {
|
||||||
try {
|
try {
|
||||||
if (need_reconnect) {
|
if (need_reconnect) {
|
||||||
|
|
Ładowanie…
Reference in New Issue