Skip to content

Commit

Permalink
Improve accept server implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
xwmx committed Jan 22, 2024
1 parent c2c5cf2 commit 412e60e
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions nb
Original file line number Diff line number Diff line change
Expand Up @@ -21691,6 +21691,8 @@ HEREDOC
) &
;;
accept|bash)
# TODO: improve concurrency

local _bash_root_path="${BASH%/bin/bash}"

if [[ -d "${_bash_root_path}/lib/bash" ]]
Expand All @@ -21707,11 +21709,28 @@ HEREDOC
(
while true
do
accept -r "${NB_SERVER_HOST}" "${NB_SERVER_PORT}" 2>/dev/null
local _server_temp_dir=
_server_temp_dir="$(mktemp -d)"

: > "${_server_temp_dir}/spawn_new_process"

(
accept -r "${NB_SERVER_HOST}" "${NB_SERVER_PORT}" 2>/dev/null

printf "1\\n" > "${_server_temp_dir}/spawn_new_process"

nb browse --respond <&"${ACCEPT_FD}" >&"${ACCEPT_FD}"
nb browse --respond <&"${ACCEPT_FD}" >&"${ACCEPT_FD}"

exec {ACCEPT_FD}>&- # close connection
exec {ACCEPT_FD}>&- # close connection

[[ -d "${_server_temp_dir:?}" ]] && rm -rf "${_server_temp_dir:?}"
) &

until [[ -s "${_server_temp_dir}/spawn_new_process" ]] ||
[[ ! -f "${_server_temp_dir}/spawn_new_process" ]]
do
:
done
done
) &
;;
Expand Down

0 comments on commit 412e60e

Please sign in to comment.