Skip to content

Commit

Permalink
KTOR-7663 Add bind overload for UDPSocketBuilder (#4456)
Browse files Browse the repository at this point in the history
  • Loading branch information
marychatte authored and osipxd committed Nov 8, 2024
1 parent 0d5f597 commit da4320f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ktor-network/api/ktor-network.api
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,9 @@ public final class io/ktor/network/sockets/TypeOfService$Companion {

public final class io/ktor/network/sockets/UDPSocketBuilder : io/ktor/network/sockets/Configurable {
public final fun bind (Lio/ktor/network/sockets/SocketAddress;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun bind (Ljava/lang/String;ILkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
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;
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;
public synthetic fun configure (Lkotlin/jvm/functions/Function1;)Lio/ktor/network/sockets/Configurable;
public fun configure (Lkotlin/jvm/functions/Function1;)Lio/ktor/network/sockets/UDPSocketBuilder;
public final fun connect (Lio/ktor/network/sockets/SocketAddress;Lio/ktor/network/sockets/SocketAddress;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
Expand Down
1 change: 1 addition & 0 deletions ktor-network/api/ktor-network.klib.api
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ final class io.ktor.network.sockets/UDPSocketBuilder : io.ktor.network.sockets/C
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]

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]
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]
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]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ public class UDPSocketBuilder internal constructor(
configure: SocketOptions.UDPSocketOptions.() -> Unit = {}
): BoundDatagramSocket = udpBind(selector, localAddress, options.udp().apply(configure))

/**
* Bind server socket at [port] to listen to [hostname].
*/
public suspend fun bind(
hostname: String = "0.0.0.0",
port: Int = 0,
configure: SocketOptions.UDPSocketOptions.() -> Unit = {}
): BoundDatagramSocket = bind(InetSocketAddress(hostname, port), configure)

/**
* Create a datagram socket to listen datagrams at [localAddress] and set to [remoteAddress].
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class UDPSocketTest {
fun testSendReceive() = testSockets { selector ->
aSocket(selector)
.udp()
.bind(InetSocketAddress("127.0.0.1", 8000)) {
.bind("127.0.0.1", 8000) {
reuseAddress = true
}
.use { socket ->
Expand Down

0 comments on commit da4320f

Please sign in to comment.