Procházet zdrojové kódy

Fix concurrency issue writing lines, bump to 0.3.1

tags/v0.3.1
Chris Smith před 5 roky
rodič
revize
4d1b35fa8a

+ 3
- 0
CHANGELOG Zobrazit soubor

1
 vNEXT (in development)
1
 vNEXT (in development)
2
 
2
 
3
+v0.3.1
4
+
3
   * Added more documentation to public methods/classes
5
   * Added more documentation to public methods/classes
6
+  * Fixed exception when sending multiple lines at once (e.g. when connecting!)
4
 
7
 
5
 v0.3.0
8
 v0.3.0
6
 
9
 

+ 1
- 1
build.gradle.kts Zobrazit soubor

1
 import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
1
 import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2
 
2
 
3
-version = "0.3.0"
3
+version = "0.3.1"
4
 group = "com.dmdirc.ktirc"
4
 group = "com.dmdirc.ktirc"
5
 
5
 
6
 plugins {
6
 plugins {

+ 13
- 6
src/main/kotlin/com/dmdirc/ktirc/io/LineBufferedSocket.kt Zobrazit soubor

15
 import kotlinx.coroutines.channels.produce
15
 import kotlinx.coroutines.channels.produce
16
 import kotlinx.coroutines.io.ByteReadChannel
16
 import kotlinx.coroutines.io.ByteReadChannel
17
 import kotlinx.coroutines.io.ByteWriteChannel
17
 import kotlinx.coroutines.io.ByteWriteChannel
18
+import kotlinx.coroutines.sync.Mutex
18
 import java.net.InetSocketAddress
19
 import java.net.InetSocketAddress
19
 import java.security.SecureRandom
20
 import java.security.SecureRandom
20
 import javax.net.ssl.X509TrustManager
21
 import javax.net.ssl.X509TrustManager
45
     var tlsTrustManager: X509TrustManager? = null
46
     var tlsTrustManager: X509TrustManager? = null
46
 
47
 
47
     private val log by logger()
48
     private val log by logger()
49
+    private val writeLock = Mutex()
48
 
50
 
49
     private lateinit var socket: Socket
51
     private lateinit var socket: Socket
50
     private lateinit var readChannel: ByteReadChannel
52
     private lateinit var readChannel: ByteReadChannel
68
     }
70
     }
69
 
71
 
70
     override suspend fun sendLine(line: ByteArray, offset: Int, length: Int) {
72
     override suspend fun sendLine(line: ByteArray, offset: Int, length: Int) {
71
-        with (writeChannel) {
72
-            log.fine { ">>> ${String(line, offset, length)}" }
73
-            writeAvailable(line, offset, length)
74
-            writeByte(CARRIAGE_RETURN)
75
-            writeByte(LINE_FEED)
76
-            flush()
73
+        writeLock.lock()
74
+        try {
75
+            with(writeChannel) {
76
+                log.fine { ">>> ${String(line, offset, length)}" }
77
+                writeAvailable(line, offset, length)
78
+                writeByte(CARRIAGE_RETURN)
79
+                writeByte(LINE_FEED)
80
+                flush()
81
+            }
82
+        } finally {
83
+            writeLock.unlock()
77
         }
84
         }
78
     }
85
     }
79
 
86
 

Načítá se…
Zrušit
Uložit