Avoid port conflicts
This commit is contained in:
parent
943ca48aba
commit
abc647cb4d
13
listener.ts
13
listener.ts
|
@ -1,9 +1,18 @@
|
||||||
import { run } from "@ludus/ludus-js-pure"
|
import { run } from "@ludus/ludus-js-pure"
|
||||||
import { unlinkSync, readFileSync } from "node:fs"
|
import { unlinkSync, readFileSync } from "node:fs"
|
||||||
|
|
||||||
|
function random_port () {
|
||||||
|
return Math.floor(Math.random() * 10000)
|
||||||
|
}
|
||||||
|
|
||||||
export async function listen () {
|
export async function listen () {
|
||||||
const id = Math.floor(Math.random() * 1000) + 5000
|
let id = random_port()
|
||||||
const unix_socket = `/tmp/ludus-${id}.sock`
|
let unix_socket = `/tmp/ludus-${id}.sock`
|
||||||
|
// make sure the socket path isn't already taken
|
||||||
|
while (await Bun.file(unix_socket).exists()) {
|
||||||
|
id = random_port()
|
||||||
|
unix_socket = `/tmp/ludus-${id}.sock`
|
||||||
|
}
|
||||||
const repl_file_path = ".lrepl"
|
const repl_file_path = ".lrepl"
|
||||||
const repl_info = { unix_socket }
|
const repl_info = { unix_socket }
|
||||||
const repl_file = Bun.file(repl_file_path)
|
const repl_file = Bun.file(repl_file_path)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user