mirror of
https://github.com/corda/corda.git
synced 2025-06-23 01:19:00 +00:00
node-driver: Reuse address when polling for port, poll for correct condition\(!\)
This commit is contained in:
@ -95,7 +95,7 @@ sealed class PortAllocation {
|
|||||||
override fun nextPort(): Int {
|
override fun nextPort(): Int {
|
||||||
return ServerSocket().use {
|
return ServerSocket().use {
|
||||||
it.reuseAddress = true
|
it.reuseAddress = true
|
||||||
it.bind(InetSocketAddress.createUnresolved("localhost", 0))
|
it.bind(InetSocketAddress("localhost", 0))
|
||||||
it.localPort
|
it.localPort
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -182,10 +182,13 @@ private fun getTimestampAsDirectoryName(): String {
|
|||||||
fun addressMustBeBound(hostAndPort: HostAndPort) {
|
fun addressMustBeBound(hostAndPort: HostAndPort) {
|
||||||
poll("address $hostAndPort to bind") {
|
poll("address $hostAndPort to bind") {
|
||||||
try {
|
try {
|
||||||
Socket(hostAndPort.hostText, hostAndPort.port).close()
|
ServerSocket().use {
|
||||||
Unit
|
it.reuseAddress = true
|
||||||
} catch (_exception: SocketException) {
|
it.bind(InetSocketAddress(hostAndPort.hostText, hostAndPort.port))
|
||||||
|
}
|
||||||
null
|
null
|
||||||
|
} catch (_exception: SocketException) {
|
||||||
|
Unit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -193,10 +196,13 @@ fun addressMustBeBound(hostAndPort: HostAndPort) {
|
|||||||
fun addressMustNotBeBound(hostAndPort: HostAndPort) {
|
fun addressMustNotBeBound(hostAndPort: HostAndPort) {
|
||||||
poll("address $hostAndPort to unbind") {
|
poll("address $hostAndPort to unbind") {
|
||||||
try {
|
try {
|
||||||
Socket(hostAndPort.hostText, hostAndPort.port).close()
|
ServerSocket().use {
|
||||||
null
|
it.reuseAddress = true
|
||||||
} catch (_exception: SocketException) {
|
it.bind(InetSocketAddress(hostAndPort.hostText, hostAndPort.port))
|
||||||
|
}
|
||||||
Unit
|
Unit
|
||||||
|
} catch (_exception: SocketException) {
|
||||||
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user