Commit 8c55630e authored by Mygod's avatar Mygod

Remove file socket on thread finishes

parent b808920e
......@@ -42,6 +42,7 @@ abstract class LocalSocketListener(protected val tag: String) : Thread() {
*/
protected abstract fun accept(socket: LocalSocket)
override fun run() {
try {
while (!socketFile.delete()) Thread.sleep(100)
try {
val localSocket = LocalSocket()
......@@ -61,12 +62,16 @@ abstract class LocalSocketListener(protected val tag: String) : Thread() {
null
}?.use(this::accept)
}
} finally {
stopThread()
}
}
fun stopThread() {
val old = serverSocket.getAndSet(null) ?: return
try {
old.close()
if (!socketFile.delete()) socketFile.deleteOnExit()
} catch (_: Exception) { } // ignore
}
}
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