mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-27 08:38:13 -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 {
|
class ProcessUtil {
|
||||||
companion object {
|
companion object {
|
||||||
fun findAvailablePort(port: Int = 1234): Int {
|
fun findAvailablePort(port: Int = 1234) = (port .. 65000).firstOrNull { isPortAvailable(it) }
|
||||||
if (isPortAvailable(port)) return port
|
?: throw IllegalArgumentException("Couldn't find any port available, something is very wrong")
|
||||||
|
|
||||||
for (i in 1235..65000) {
|
|
||||||
if (isPortAvailable(i)) return i
|
|
||||||
}
|
|
||||||
throw IllegalArgumentException("Couldn't find any port available, something is very wrong")
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun isPortAvailable(port: Int): Boolean {
|
private fun isPortAvailable(port: Int): Boolean {
|
||||||
var s: Socket? = null
|
var s: Socket? = null
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue