Skip to content

Commit ba1a69b

Browse files
marychattee5l
authored andcommitted
KTOR-7663 Add bind overload for UDPSocketBuilder (#4456)
1 parent bb01dc3 commit ba1a69b

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

ktor-network/api/ktor-network.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,9 @@ public final class io/ktor/network/sockets/TypeOfService$Companion {
341341

342342
public final class io/ktor/network/sockets/UDPSocketBuilder : io/ktor/network/sockets/Configurable {
343343
public final fun bind (Lio/ktor/network/sockets/SocketAddress;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
344+
public final fun bind (Ljava/lang/String;ILkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
344345
public static synthetic fun bind$default (Lio/ktor/network/sockets/UDPSocketBuilder;Lio/ktor/network/sockets/SocketAddress;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
346+
public static synthetic fun bind$default (Lio/ktor/network/sockets/UDPSocketBuilder;Ljava/lang/String;ILkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
345347
public synthetic fun configure (Lkotlin/jvm/functions/Function1;)Lio/ktor/network/sockets/Configurable;
346348
public fun configure (Lkotlin/jvm/functions/Function1;)Lio/ktor/network/sockets/UDPSocketBuilder;
347349
public final fun connect (Lio/ktor/network/sockets/SocketAddress;Lio/ktor/network/sockets/SocketAddress;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;

ktor-network/api/ktor-network.klib.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ final class io.ktor.network.sockets/UDPSocketBuilder : io.ktor.network.sockets/C
166166
final fun <set-options>(io.ktor.network.sockets/SocketOptions.UDPSocketOptions) // io.ktor.network.sockets/UDPSocketBuilder.options.<set-options>|<set-options>(io.ktor.network.sockets.SocketOptions.UDPSocketOptions){}[0]
167167

168168
final suspend fun bind(io.ktor.network.sockets/SocketAddress? = ..., kotlin/Function1<io.ktor.network.sockets/SocketOptions.UDPSocketOptions, kotlin/Unit> = ...): io.ktor.network.sockets/BoundDatagramSocket // io.ktor.network.sockets/UDPSocketBuilder.bind|bind(io.ktor.network.sockets.SocketAddress?;kotlin.Function1<io.ktor.network.sockets.SocketOptions.UDPSocketOptions,kotlin.Unit>){}[0]
169+
final suspend fun bind(kotlin/String = ..., kotlin/Int = ..., kotlin/Function1<io.ktor.network.sockets/SocketOptions.UDPSocketOptions, kotlin/Unit> = ...): io.ktor.network.sockets/BoundDatagramSocket // io.ktor.network.sockets/UDPSocketBuilder.bind|bind(kotlin.String;kotlin.Int;kotlin.Function1<io.ktor.network.sockets.SocketOptions.UDPSocketOptions,kotlin.Unit>){}[0]
169170
final suspend fun connect(io.ktor.network.sockets/SocketAddress, io.ktor.network.sockets/SocketAddress? = ..., kotlin/Function1<io.ktor.network.sockets/SocketOptions.UDPSocketOptions, kotlin/Unit> = ...): io.ktor.network.sockets/ConnectedDatagramSocket // io.ktor.network.sockets/UDPSocketBuilder.connect|connect(io.ktor.network.sockets.SocketAddress;io.ktor.network.sockets.SocketAddress?;kotlin.Function1<io.ktor.network.sockets.SocketOptions.UDPSocketOptions,kotlin.Unit>){}[0]
170171
}
171172

ktor-network/common/src/io/ktor/network/sockets/UDPSocketBuilder.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ public class UDPSocketBuilder internal constructor(
2121
configure: SocketOptions.UDPSocketOptions.() -> Unit = {}
2222
): BoundDatagramSocket = udpBind(selector, localAddress, options.udp().apply(configure))
2323

24+
/**
25+
* Bind server socket at [port] to listen to [hostname].
26+
*/
27+
public suspend fun bind(
28+
hostname: String = "0.0.0.0",
29+
port: Int = 0,
30+
configure: SocketOptions.UDPSocketOptions.() -> Unit = {}
31+
): BoundDatagramSocket = bind(InetSocketAddress(hostname, port), configure)
32+
2433
/**
2534
* Create a datagram socket to listen datagrams at [localAddress] and set to [remoteAddress].
2635
*/

ktor-network/jvmAndPosix/test/io/ktor/network/sockets/tests/UDPSocketTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class UDPSocketTest {
197197
fun testSendReceive() = testSockets { selector ->
198198
aSocket(selector)
199199
.udp()
200-
.bind(InetSocketAddress("127.0.0.1", 8000)) {
200+
.bind("127.0.0.1", 8000) {
201201
reuseAddress = true
202202
}
203203
.use { socket ->

0 commit comments

Comments
 (0)