@@ -116,11 +116,20 @@ class ProcessorAccess(
116116 while (true ) {
117117 Log .info(" Waiting for clients..." )
118118 val client = serverSocket.accept()
119- launch {
120- handleClient(client)
119+
120+ if (runOnMainThread { build.isValid }) {
121+ launch {
122+ handleClient(client)
123+ }
124+ } else {
125+ Log .err(" ProcessorAccess build invalid, stopping server." )
126+ client.close()
127+ stopServer()
128+ break
121129 }
122130 }
123131 }
132+ } catch (_: CancellationException ) {
124133 } catch (e: Exception ) {
125134 Log .err(" ProcessorAccess server failed" , e)
126135 }
@@ -301,23 +310,23 @@ private fun linkedBuild(build: LogicBuild, name: String) =
301310
302311private fun LVar.numu () = num().toUInt()
303312
304- @Serializable
305- sealed class Request {
306- abstract suspend fun handle (processor : ProcessorAccess , rx : ByteReadChannel , tx : ByteWriteChannel ): Response
307-
308- protected suspend fun <T > runOnMainThread (block : () -> T ): T {
309- return suspendCancellableCoroutine { continuation ->
310- Core .app.post {
311- try {
312- continuation.resume(block())
313- } catch (e: Exception ) {
314- continuation.resumeWithException(e)
315- }
313+ private suspend fun <T > runOnMainThread (block : () -> T ): T {
314+ return suspendCancellableCoroutine { continuation ->
315+ Core .app.post {
316+ try {
317+ continuation.resume(block())
318+ } catch (e: Exception ) {
319+ continuation.resumeWithException(e)
316320 }
317321 }
318322 }
319323}
320324
325+ @Serializable
326+ sealed class Request {
327+ abstract suspend fun handle (processor : ProcessorAccess , rx : ByteReadChannel , tx : ByteWriteChannel ): Response
328+ }
329+
321330@Serializable
322331@SerialName(" flash" )
323332data class FlashRequest (
0 commit comments