diff options
| author | Mikael Magnusson <mikachu@gmail.com> | 2026-05-07 10:41:47 +0200 |
|---|---|---|
| committer | Mikael Magnusson <mikachu@gmail.com> | 2026-05-11 21:31:59 +0200 |
| commit | 89e2802ba27e8186c3edc76e85e1f2320e02e0cd (patch) | |
| tree | f280600f4b47f2a7a92ca86af196ad32ac545744 | |
| parent | 54493: socket: fix some issues with socket name (diff) | |
| download | zsh-89e2802ba27e8186c3edc76e85e1f2320e02e0cd.tar zsh-89e2802ba27e8186c3edc76e85e1f2320e02e0cd.tar.gz zsh-89e2802ba27e8186c3edc76e85e1f2320e02e0cd.tar.bz2 zsh-89e2802ba27e8186c3edc76e85e1f2320e02e0cd.tar.lz zsh-89e2802ba27e8186c3edc76e85e1f2320e02e0cd.tar.xz zsh-89e2802ba27e8186c3edc76e85e1f2320e02e0cd.tar.zst zsh-89e2802ba27e8186c3edc76e85e1f2320e02e0cd.zip | |
54494: Add zsocket -s to shutdown() a socket fd
| -rw-r--r-- | ChangeLog | 3 | ||||
| -rw-r--r-- | Doc/Zsh/mod_socket.yo | 7 | ||||
| -rw-r--r-- | Src/Modules/socket.c | 13 |
3 files changed, 21 insertions, 2 deletions
@@ -23,6 +23,9 @@ * 54493: Src/Modules/socket.c: socket: fix some issues with socket name + * 54494: Doc/Zsh/mod_socket.yo, Src/Modules/socket.c: Add zsocket + -s to shutdown() a socket fd + 2026-05-10 Oliver Kiddle <opk@zsh.org> * unposted: Completion/Linux/Command/_selinux: complete files diff --git a/Doc/Zsh/mod_socket.yo b/Doc/Zsh/mod_socket.yo index 78d9254e8..2c699b1d1 100644 --- a/Doc/Zsh/mod_socket.yo +++ b/Doc/Zsh/mod_socket.yo @@ -7,7 +7,7 @@ startitem() findex(zsocket) cindex(sockets) cindex(sockets, Unix domain) -item(tt(zsocket) [ tt(-altv) ] [ tt(-d) var(fd) ] [ var(args) ])( +item(tt(zsocket) [ tt(-alstv) ] [ tt(-d) var(fd) ] [ var(args) ])( tt(zsocket) is implemented as a builtin to allow full use of shell command line editing, file I/O, and job control mechanisms. ) @@ -33,6 +33,11 @@ File descriptors can be closed with normal shell syntax when no longer needed, for example: example(exec {REPLY}>&-) + +The tt(zsocket -s var(fd)) command may also be used to shut down a +socket fd before closing it. This will send an EOF to the other side, +while this side can still read their subsequent response before closing +the connection fully, for example. ) enditem() diff --git a/Src/Modules/socket.c b/Src/Modules/socket.c index 4f2a6ecbf..2c8a48c28 100644 --- a/Src/Modules/socket.c +++ b/Src/Modules/socket.c @@ -229,6 +229,17 @@ bin_zsocket(char *nam, char **args, Options ops, UNUSED(int func)) if (verbose) printf("new connection from %s is on fd %d\n", soun.sun_path, sfd); } + else if (OPT_ISSET(ops,'s')) + { + if (!args[0]) { + zwarnnam(nam, "-s requires an argument"); + return 1; + } + + int err = shutdown(atoi(args[0]), SHUT_WR); + if (err) + zwarn("shutdown failed: %e", errno); + } else { if (!args[0]) { @@ -282,7 +293,7 @@ bin_zsocket(char *nam, char **args, Options ops, UNUSED(int func)) } static struct builtin bintab[] = { - BUILTIN("zsocket", 0, bin_zsocket, 0, 3, 0, "ad:ltv", NULL), + BUILTIN("zsocket", 0, bin_zsocket, 0, 3, 0, "ad:lstv", NULL), }; static struct features module_features = { |
