Skip to content

Commit feea4e7

Browse files
author
pengcheng.tan
committed
Fix MultiConnectionsFileTransfer.kt.
1 parent 6a4e45e commit feea4e7

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

app/src/main/java/com/tans/tfiletransporter/net/filetransporter/MultiConnectionsFileTransfer.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ class MultiConnectionsFileServer(
8080

8181
private val finishCheckChannel = Channel<Unit>(1)
8282

83+
var sendingCoroutineScope: CoroutineScope? = null
84+
8385
internal suspend fun start() = coroutineScope {
86+
sendingCoroutineScope = this
8487
ssc.use {
8588
ssc.setOptionSuspend(StandardSocketOptions.SO_REUSEADDR, true)
8689
ssc.bindSuspend(InetSocketAddress(localAddress, MULTI_CONNECTIONS_FILES_TRANSFER_LISTEN_PORT), MULTI_CONNECTIONS_MAX)
@@ -107,7 +110,7 @@ class MultiConnectionsFileServer(
107110
}
108111
} else {
109112
connectResult.exceptionOrNull()?.printStackTrace()
110-
if (progressLong.get() >= file.size || !isActive) {
113+
if (progressLong.get() >= file.size || !isActive || !ssc.isOpen) {
111114
break
112115
}
113116
}
@@ -119,6 +122,7 @@ class MultiConnectionsFileServer(
119122
}
120123

121124
suspend fun cancel() {
125+
sendingCoroutineScope?.cancel("Canceled by user.")
122126
if (ssc.isOpen) ssc.close()
123127
}
124128

0 commit comments

Comments
 (0)