Add some error handling to async response handler

We only want to read data in case of POLLIN or POLLHUP. Not POLLNVAL or
select error.

We always want to remove the handler, so it doesn't get called in an
infinite loop when error is nval or err.

In zsh source, see main zle event loop in zle_main.c raw_getbyte
function.
This commit is contained in:
Eric Freese 2018-07-13 11:26:57 -06:00
parent 93877f6b76
commit 88fe824ddf
2 changed files with 16 additions and 8 deletions

View file

@ -41,10 +41,14 @@ _zsh_autosuggest_async_request() {
# First arg will be fd ready for reading
# Second arg will be passed in case of error
_zsh_autosuggest_async_response() {
if [[ -z "$2" || "$2" == "hup" ]]; then
# Read everything from the fd and give it as a suggestion
zle autosuggest-suggest -- "$(cat <&$1)"
# Remove the handler and close the fd
zle -F "$1"
# Close the fd
exec {1}<&-
fi
# Always remove the handler
zle -F "$1"
}

View file

@ -720,12 +720,16 @@ _zsh_autosuggest_async_request() {
# First arg will be fd ready for reading
# Second arg will be passed in case of error
_zsh_autosuggest_async_response() {
if [[ -z "$2" || "$2" == "hup" ]]; then
# Read everything from the fd and give it as a suggestion
zle autosuggest-suggest -- "$(cat <&$1)"
# Remove the handler and close the fd
zle -F "$1"
# Close the fd
exec {1}<&-
fi
# Always remove the handler
zle -F "$1"
}
#--------------------------------------------------------------------#