-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KTOR-6004 Support TCP and Unix socket for wasm-js and js via NodeJS (#…
…4411) * Drop `jvmAndNix` shared source set * Commonize `ktor-network` and `ktor-network-tls` * Support TCP and Unix sockets for wasm-js and js on Node * Move `supportsUnixDomainSockets` to posix and use Platform instead of expect/actual
- Loading branch information
Showing
63 changed files
with
788 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...x/src/io/ktor/network/sockets/Datagram.kt → ...n/src/io/ktor/network/sockets/Datagram.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../io/ktor/network/sockets/SocketAddress.kt → .../io/ktor/network/sockets/SocketAddress.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
ktor-network/common/src/io/ktor/network/sockets/SocketEngine.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package io.ktor.network.sockets | ||
|
||
import io.ktor.network.selector.* | ||
|
||
internal expect suspend fun tcpConnect( | ||
selector: SelectorManager, | ||
remoteAddress: SocketAddress, | ||
socketOptions: SocketOptions.TCPClientSocketOptions | ||
): Socket | ||
|
||
internal expect suspend fun tcpBind( | ||
selector: SelectorManager, | ||
localAddress: SocketAddress?, | ||
socketOptions: SocketOptions.AcceptorOptions | ||
): ServerSocket | ||
|
||
internal expect suspend fun udpConnect( | ||
selector: SelectorManager, | ||
remoteAddress: SocketAddress, | ||
localAddress: SocketAddress?, | ||
options: SocketOptions.UDPSocketOptions | ||
): ConnectedDatagramSocket | ||
|
||
internal expect suspend fun udpBind( | ||
selector: SelectorManager, | ||
localAddress: SocketAddress?, | ||
options: SocketOptions.UDPSocketOptions | ||
): BoundDatagramSocket |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ix/src/io/ktor/network/sockets/Sockets.kt → ...on/src/io/ktor/network/sockets/Sockets.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
.../io/ktor/network/sockets/TypeOfService.kt → .../io/ktor/network/sockets/TypeOfService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
ktor-network/common/test/io/ktor/network/sockets/tests/TestUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package io.ktor.network.sockets.tests | ||
|
||
import io.ktor.network.selector.* | ||
import io.ktor.test.dispatcher.* | ||
import io.ktor.utils.io.core.* | ||
import kotlinx.coroutines.* | ||
import kotlinx.coroutines.test.* | ||
import kotlinx.io.files.* | ||
import kotlin.time.* | ||
import kotlin.time.Duration.Companion.minutes | ||
import kotlin.uuid.* | ||
|
||
internal fun testSockets( | ||
timeout: Duration = 1.minutes, | ||
block: suspend CoroutineScope.(SelectorManager) -> Unit | ||
): TestResult = runTestWithRealTime(timeout = timeout) { | ||
SelectorManager().use { selector -> | ||
block(selector) | ||
} | ||
} | ||
|
||
internal expect fun Any.supportsUnixDomainSockets(): Boolean | ||
|
||
@OptIn(ExperimentalUuidApi::class) | ||
internal fun createTempFilePath(basename: String): String { | ||
return Path(SystemTemporaryDirectory, "$basename-${Uuid.random()}").toString() | ||
} | ||
|
||
internal fun removeFile(path: String) { | ||
SystemFileSystem.delete(Path(path), mustExist = false) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# | ||
# Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
# | ||
target.js.browser=false | ||
target.wasmJs.browser=false |
7 changes: 0 additions & 7 deletions
7
ktor-network/ios/test/io/ktor/network/sockets/tests/TestUtilsIos.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.