mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
KobaltServer now actually uses the port specified in the command line argument
This commit is contained in:
parent
9ecc603c24
commit
9c3e339123
3 changed files with 10 additions and 8 deletions
|
@ -158,7 +158,7 @@ private class Main @Inject constructor(
|
||||||
jc.usage()
|
jc.usage()
|
||||||
} else if (args.serverMode) {
|
} else if (args.serverMode) {
|
||||||
// --server
|
// --server
|
||||||
val port = KobaltServer(args.force,
|
val port = KobaltServer(args.force, args.port,
|
||||||
{ buildFile -> initForBuildFile(BuildFile(Paths.get(buildFile), buildFile), args)},
|
{ buildFile -> initForBuildFile(BuildFile(Paths.get(buildFile), buildFile), args)},
|
||||||
{ cleanUp() })
|
{ cleanUp() })
|
||||||
.call()
|
.call()
|
||||||
|
|
|
@ -25,7 +25,7 @@ import java.util.concurrent.Callable
|
||||||
* The callbacks are used to initialize and clean up the state before and after each command, so that Kobalt's state
|
* The callbacks are used to initialize and clean up the state before and after each command, so that Kobalt's state
|
||||||
* can be properly reset, making the server reentrant.
|
* can be properly reset, making the server reentrant.
|
||||||
*/
|
*/
|
||||||
class KobaltServer(val force: Boolean,
|
class KobaltServer(val force: Boolean, val port: Int = 1234,
|
||||||
val initCallback: (String) -> List<Project>,
|
val initCallback: (String) -> List<Project>,
|
||||||
val cleanUpCallback: () -> Unit) : Callable<Int>, ICommandSender {
|
val cleanUpCallback: () -> Unit) : Callable<Int>, ICommandSender {
|
||||||
// var outgoing: PrintWriter? = null
|
// var outgoing: PrintWriter? = null
|
||||||
|
@ -37,17 +37,17 @@ class KobaltServer(val force: Boolean,
|
||||||
}.toMap()
|
}.toMap()
|
||||||
|
|
||||||
override fun call() : Int {
|
override fun call() : Int {
|
||||||
val port = ProcessUtil.findAvailablePort()
|
val availablePort = ProcessUtil.findAvailablePort(port)
|
||||||
try {
|
try {
|
||||||
if (createServerFile(port, force)) {
|
if (createServerFile(availablePort, force)) {
|
||||||
privateRun(port)
|
privateRun(availablePort)
|
||||||
}
|
}
|
||||||
} catch(ex: Exception) {
|
} catch(ex: Exception) {
|
||||||
ex.printStackTrace()
|
ex.printStackTrace()
|
||||||
} finally {
|
} finally {
|
||||||
deleteServerFile()
|
deleteServerFile()
|
||||||
}
|
}
|
||||||
return port
|
return availablePort
|
||||||
}
|
}
|
||||||
|
|
||||||
val SERVER_FILE = KFiles.joinDir(homeDir(KFiles.KOBALT_DOT_DIR, "kobaltServer.properties"))
|
val SERVER_FILE = KFiles.joinDir(homeDir(KFiles.KOBALT_DOT_DIR, "kobaltServer.properties"))
|
||||||
|
|
|
@ -5,8 +5,10 @@ import java.net.Socket
|
||||||
|
|
||||||
class ProcessUtil {
|
class ProcessUtil {
|
||||||
companion object {
|
companion object {
|
||||||
fun findAvailablePort(): Int {
|
fun findAvailablePort(port: Int = 1234): Int {
|
||||||
for (i in 1234..65000) {
|
if (isPortAvailable(port)) return port
|
||||||
|
|
||||||
|
for (i in 1235..65000) {
|
||||||
if (isPortAvailable(i)) return i
|
if (isPortAvailable(i)) return i
|
||||||
}
|
}
|
||||||
throw IllegalArgumentException("Couldn't find any port available, something is very wrong")
|
throw IllegalArgumentException("Couldn't find any port available, something is very wrong")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue