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