Refactored client to use persistent connections

and server to use zselect for handling concurrency
This commit is contained in:
Thiago de Arruda
2013-10-29 12:01:18 -03:00
parent 2d67624963
commit 911730c1e4
2 changed files with 94 additions and 54 deletions

View File

@@ -17,24 +17,29 @@ autosuggest-ensure-server() {
fi
fi
autosuggest-server-connect
}
autosuggest-server-connect() {
unset ZLE_AUTOSUGGEST_CONNECTION
integer remaining_tries=10
# wait until the process is listening
while ! [[ -d $server_dir && -r $pid_file ]] ||\
! kill -0 $(<$pid_file) &> /dev/null && (( --remaining_tries )); do
while (( --remaining_tries )) && ! zsocket $socket_path &>/dev/null; do
sleep 0.3
done
ZLE_AUTOSUGGEST_SOCKET=$socket_path
[[ -z $REPLY ]] && return 1
ZLE_AUTOSUGGEST_CONNECTION=$REPLY
}
autosuggest-first-completion() {
zsocket $ZLE_AUTOSUGGEST_SOCKET &>/dev/null || return 1
local connection=$REPLY
local completion
print -u $connection - $1
while IFS= read -r -u $connection completion; do
print - ${completion}
setopt local_options noglob
local response
print -u $ZLE_AUTOSUGGEST_CONNECTION - $1 &> /dev/null || return 1
while IFS= read -r -u $ZLE_AUTOSUGGEST_CONNECTION response; do
[[ $response == '' ]] && break
print - ${response}
done
# close fd
exec {connection}>&-
}