Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH 2/3: Add zsocket -s to shutdown() a socket fd
- X-seq: zsh-workers 54495
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: PATCH 2/3: Add zsocket -s to shutdown() a socket fd
- Date: Thu, 7 May 2026 11:04:57 +0200
- Archived-at: <https://zsh.org/workers/54495>
- List-id: <zsh-workers.zsh.org>
---
Doc/Zsh/mod_socket.yo | 7 ++++++-
Src/Modules/socket.c | 13 ++++++++++++-
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/Doc/Zsh/mod_socket.yo b/Doc/Zsh/mod_socket.yo
index 78d9254e8d..2c699b1d12 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 4f2a6ecbfa..2c8a48c286 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 = {
--
2.38.1
Messages sorted by:
Reverse Date,
Date,
Thread,
Author