ref: 4a0aaf774da4296167bd52a5090034c668cc4f5f
parent: f8fd3d5d28472644f87484c3e7ef921fc31e0af5
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Sun Oct 1 17:21:40 EDT 2023
pipe: bring back wstat, set size (in bytes) of the pipe buffer
--- a/sys/man/2/pipe
+++ b/sys/man/2/pipe
@@ -52,6 +52,12 @@
on a pipe (see
.IR stat (2)).
.PP
+The limit of data bytes in the pipe's buffer can be set by
+.I fwstat
+or
+.I dirfwstat
+on either of the pipe's descriptors.
+.PP
When all the data has been read from a pipe and the writer has closed the pipe or exited,
.IR read (2)
will return 0 bytes. Writes to a pipe with no reader will generate a note
--- a/sys/src/9/port/devpipe.c
+++ b/sys/src/9/port/devpipe.c
@@ -365,6 +365,42 @@
return n;
}
+static int
+pipewstat(Chan *c, uchar *dp, int n)
+{
+ Dir d;
+ Pipe *p;
+
+ if(waserror()){
+ /* avoid notes when pipe is a mounted queue */
+ if((c->flag & CMSG) == 0)
+ postnote(up, 1, "sys: wstat on closed pipe", NUser);
+ nexterror();
+ }
+
+ n = convM2D(dp, n, &d, nil);
+ if(n == 0)
+ error(Eshortstat);
+ if(d.length < 1 || d.length > conf.pipeqsize)
+ error(Ebadarg);
+
+ p = c->aux;
+ switch(NETTYPE(c->qid.path)){
+ case Qdir:
+ error(Eperm);
+ case Qdata0:
+ case Qdata1:
+ qsetlimit(p->q[0], d.length);
+ qsetlimit(p->q[1], d.length);
+ break;
+ default:
+ panic("pipewstat");
+ }
+
+ poperror();
+ return n;
+}
+
Dev pipedevtab = {
'|',
"pipe",
@@ -383,5 +419,5 @@
pipewrite,
pipebwrite,
devremove,
- devwstat,
+ pipewstat,
};