summaryrefslogtreecommitdiff
path: root/Functions/TCP/tcp_fd_handler
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2003-02-06 12:21:49 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2003-02-06 12:21:49 +0000
commit5c1f3b65a6f5abeae8459f41adb8fd2316971515 (patch)
tree21a82daa1abab96c967d731c7afe2a3a2bd07fff /Functions/TCP/tcp_fd_handler
parent809ab19dff75185a805b4cbb31a6b89f225167f4 (diff)
downloadzsh-5c1f3b65a6f5abeae8459f41adb8fd2316971515.tar.gz
zsh-5c1f3b65a6f5abeae8459f41adb8fd2316971515.zip
18202: New TCP function system plus small error message change in ztcp.
Diffstat (limited to 'Functions/TCP/tcp_fd_handler')
-rw-r--r--Functions/TCP/tcp_fd_handler35
1 files changed, 35 insertions, 0 deletions
diff --git a/Functions/TCP/tcp_fd_handler b/Functions/TCP/tcp_fd_handler
new file mode 100644
index 000000000..012fd4d87
--- /dev/null
+++ b/Functions/TCP/tcp_fd_handler
@@ -0,0 +1,35 @@
+local line name=${tcp_by_fd[$1]}
+if [[ -n $name ]]
+then
+ local TCP_INVALIDATE_ZLE
+ if (( $# > 2 )); then
+ zle -I
+ ## debugging only
+ # print "Flags on the play:" ${argv[3,-1]}
+ else
+ TCP_INVALIDATE_ZLE=1
+ fi
+ if ! tcp_read -d -u $1; then
+ [[ -n $TCP_INVALIDATE_ZLE ]] && zle -I
+ print "[TCP fd $1 (session $name) gone awol; removing from poll list]" >& 2
+ zle -F $1
+ return 1
+ fi
+ return 0
+else
+ zle -I
+ # Handle fds not in the TCP set similarly.
+ # This does the drain thing, to try and get as much data out as possible.
+ if ! read line <&$1; then
+ print "[Reading on $1 failed; removing from poll list]" >& 2
+ zle -F $1
+ return 1
+ fi
+ line="fd$1:$line"
+ local newline
+ while read -t newline <&$1; do
+ line="${line}
+fd$1:$newline"
+ done
+fi
+print -r - $line