Commit d240f2bd authored by Mygod's avatar Mygod

Ensure broadcast is finished

parent b4f97b88
...@@ -94,7 +94,7 @@ object BaseService { ...@@ -94,7 +94,7 @@ object BaseService {
} }
class Binder(private var data: Data? = null) : IShadowsocksService.Stub(), CoroutineScope, AutoCloseable { class Binder(private var data: Data? = null) : IShadowsocksService.Stub(), CoroutineScope, AutoCloseable {
val callbacks = object : RemoteCallbackList<IShadowsocksServiceCallback>() { private val callbacks = object : RemoteCallbackList<IShadowsocksServiceCallback>() {
override fun onCallbackDied(callback: IShadowsocksServiceCallback?, cookie: Any?) { override fun onCallbackDied(callback: IShadowsocksServiceCallback?, cookie: Any?) {
super.onCallbackDied(callback, cookie) super.onCallbackDied(callback, cookie)
stopListeningForBandwidth(callback ?: return) stopListeningForBandwidth(callback ?: return)
...@@ -112,15 +112,19 @@ object BaseService { ...@@ -112,15 +112,19 @@ object BaseService {
} }
private fun broadcast(work: (IShadowsocksServiceCallback) -> Unit) { private fun broadcast(work: (IShadowsocksServiceCallback) -> Unit) {
repeat(callbacks.beginBroadcast()) { val count = callbacks.beginBroadcast()
try { try {
work(callbacks.getBroadcastItem(it)) repeat(count) {
} catch (_: RemoteException) { try {
} catch (e: Exception) { work(callbacks.getBroadcastItem(it))
printLog(e) } catch (_: RemoteException) {
} catch (e: Exception) {
printLog(e)
}
} }
} finally {
callbacks.finishBroadcast()
} }
callbacks.finishBroadcast()
} }
private suspend fun loop() { private suspend fun loop() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment