mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-27 00:38:11 -07:00
Better port loop.
This commit is contained in:
parent
f856082478
commit
85db1c767e
1 changed files with 2 additions and 8 deletions
|
@ -5,14 +5,8 @@ import java.net.Socket
|
|||
|
||||
class ProcessUtil {
|
||||
companion object {
|
||||
fun findAvailablePort(port: Int = 1234): Int {
|
||||
if (isPortAvailable(port)) return port
|
||||
|
||||
for (i in 1235..65000) {
|
||||
if (isPortAvailable(i)) return i
|
||||
}
|
||||
throw IllegalArgumentException("Couldn't find any port available, something is very wrong")
|
||||
}
|
||||
fun findAvailablePort(port: Int = 1234) = (port .. 65000).firstOrNull { isPortAvailable(it) }
|
||||
?: throw IllegalArgumentException("Couldn't find any port available, something is very wrong")
|
||||
|
||||
private fun isPortAvailable(port: Int): Boolean {
|
||||
var s: Socket? = null
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue