From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED autolearn=no autolearn_force=no version=3.4.4 Received: (qmail 3480 invoked from network); 12 Jun 2021 02:58:13 -0000 Received: from 1ess.inri.net (216.126.196.35) by inbox.vuxu.org with ESMTPUTF8; 12 Jun 2021 02:58:13 -0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by 1ess; Fri Jun 11 22:50:57 -0400 2021 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 467575C00E4; Fri, 11 Jun 2021 16:00:31 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 11 Jun 2021 16:00:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=biobuf.link; h= message-id:to:subject:date:from:mime-version:content-type :content-transfer-encoding; s=fm2; bh=B/wW5uAi+s5JAr/20AqV9FEjLQ VGsHaDu2JCmwNKfFw=; b=IW3o5Li3EOBlY9zA1G4+wonN/Mcy7YurMESHVrd7Wr X27ejSaTm88DgbaO8gpDMeTwSfptedcltJAhi+moWPgI1uAAEYcd9L+jHzxWfJGf uwXAky704FhwDi9fkDInkQytsD5GVXSDa+mA7wDBLx7VZKeY6V2Ik0kOvjDZw/yU jC2OlAI2D2QzdW7sVH3WNqEz+xymWnFtL44jJVsTLlUCVcMUDMMUruvd6G0GE4u3 fgKkdhBnws3GIQmQas3tUD/8wpcB8AOssohKiaybQMDjef0hdoubeHKbI2VOZXmV qQ5V9XAHzJHHdGhDfB8cVEM8piBA6mQlzfKHm6E2dALw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=B/wW5u Ai+s5JAr/20AqV9FEjLQVGsHaDu2JCmwNKfFw=; b=BxBtoybwlgzva5zmG2oCsw cTuJmOphLc8uoR629v2wj4thvrLQ9rdA2pGEzLwZIfrTTLf22lx5M4il24gYcYCJ GlOoXl2x5AESl57dkaUVyzVMK1DuhovmO6k5Fn8stGTArZ6yl+TXOSqeeL7ARh4d a3XlKy6QCTVJ4RoPQ4pVGWbz3A7qYOmDUopyTkaeSZLmEGe7yeFCH2a6KVz7a5bd 7R2dtpA0gbAqLo5QLBw5xymBoBcuKcFZr9nygG7LPOJ0d90jX/LCxXGTEw0c+Y7S vBbCgKTCNcLVQhCfP46GYkmb/BZ9C/xVAh/965e6zdeMrH2R4mSAdmwfytUjiJGA == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfedukedgheduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefkvffufffhgggtgfesthejjedttd dtvdenucfhrhhomhepjhgrmhgvshcuphgrlhhmvghruceojhgrmhgvshessghiohgsuhhf rdhlihhnkheqnecuggftrfgrthhtvghrnhepffelhefhhfefgffftdeiffehueekueelfe fhueetvdfhheevgfekgeehtdehkeejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepjhgrmhgvshessghiohgsuhhfrdhlihhnkh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA for <9front@9front.org>; Fri, 11 Jun 2021 16:00:30 -0400 (EDT) Message-ID: To: 9front@9front.org Date: Fri, 11 Jun 2021 21:00:24 +0100 From: james palmer MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: lifecycle cloud wrapper-oriented interface Subject: [9front] [PATCH] acme: limit reads of the event file to one read. Reply-To: 9front@9front.org Precedence: bulk this patch limits acme to one message per read of the event file. this makes writing clients easier because events can be read into a sufficiently large buffer and parsed instead of read one byte at a time. git/import-able patch follows. - james From 189797ed9098d5f6cc06cda299f1941dc07dee08 From: james palmer Date: Fri, 11 Jun 2021 19:41:38 +0000 Subject: [PATCH] acme: limit reads of the events file to one event for easier parsing. --- diff 3ec67240f59d1e68b8d7fcb30fa17fe87f317bff 189797ed9098d5f6cc06cda299f1941dc07dee08 --- a/sys/src/cmd/acme/dat.h Mon Jun 7 10:13:51 2021 +++ b/sys/src/cmd/acme/dat.h Fri Jun 11 20:41:38 2021 @@ -44,6 +44,7 @@ typedef struct Fid Fid; typedef struct File File; typedef struct Elog Elog; +typedef struct Event Event; typedef struct Mntdir Mntdir; typedef struct Range Range; typedef struct Rangeset Rangeset; @@ -256,8 +257,8 @@ int rdselfd; Column *col; Xfid *eventx; - char *events; - int nevents; + Event *evhead; + Event *evtail; int owner; int maxlines; Dirlist **dlp; @@ -278,6 +279,14 @@ int tagexpand; int taglines; Rectangle tagtop; + int deleted; +}; + +struct Event { + char *buf; + int sz; + int offset; + Event *next; }; void wininit(Window*, Window*, Rectangle); --- a/sys/src/cmd/acme/wind.c Mon Jun 7 10:13:51 2021 +++ b/sys/src/cmd/acme/wind.c Fri Jun 11 20:41:38 2021 @@ -22,6 +22,9 @@ Rune *rp; int nc, i; + w->deleted = 0; + w->evhead = nil; + w->evtail = nil; w->tag.w = w; w->taglines = 1; w->tagexpand = TRUE; @@ -311,6 +314,7 @@ winclose(Window *w) { int i; + Event *cur, *next; if(decref(w) == 0){ xfidlog(w, "del"); @@ -322,7 +326,15 @@ for(i=0; inincl; i++) free(w->incl[i]); free(w->incl); - free(w->events); + + cur = w->evhead; + while(cur) { + next = cur->next; + free(cur); + free(cur->buf); + cur = next; + } + free(w); } } @@ -331,12 +343,21 @@ windelete(Window *w) { Xfid *x; + Event *cur, *next; x = w->eventx; if(x){ - w->nevents = 0; - free(w->events); - w->events = nil; + cur = w->evhead; + while(cur) { + next = cur->next; + free(cur->buf); + free(cur); + cur = next; + } + + w->deleted = 1; + w->evhead = nil; + w->evtail = nil; w->eventx = nil; sendp(x->c, nil); /* wake him up */ } @@ -669,26 +690,42 @@ void winevent(Window *w, char *fmt, ...) { - int n; - char *b; Xfid *x; + char *buf; va_list arg; + Event *ev; if(w->nopen[QWevent] == 0) return; if(w->owner == 0) - error("no window owner"); + error("no window owner"); + + ev = emalloc(sizeof(Event)); + ev->next = nil; + va_start(arg, fmt); - b = vsmprint(fmt, arg); + buf = vsmprint(fmt, arg); va_end(arg); - if(b == nil) + + if(buf == nil) error("vsmprint failed"); - n = strlen(b); - w->events = erealloc(w->events, w->nevents+1+n); - w->events[w->nevents++] = w->owner; - memmove(w->events+w->nevents, b, n); - free(b); - w->nevents += n; + + ev->buf = smprint("%c%s", w->owner, buf); + if(!ev->buf) + error("smprint failed"); + free(buf); + + ev->offset = 0; + ev->sz = strlen(ev->buf); + + if(w->evhead) { + w->evtail->next = ev; + w->evtail = ev; + } else { + w->evhead = ev; + w->evtail = ev; + } + x = w->eventx; if(x){ w->eventx = nil; --- a/sys/src/cmd/acme/xfid.c Mon Jun 7 10:13:51 2021 +++ b/sys/src/cmd/acme/xfid.c Fri Jun 11 20:41:38 2021 @@ -991,34 +991,45 @@ xfideventread(Xfid *x, Window *w) { Fcall fc; - char *b; - int i, n; + Event *ev; + int bufsz; + char *buf; - i = 0; x->flushed = FALSE; - while(w->nevents == 0){ - if(i){ - if(!x->flushed) - respond(x, &fc, "window shut down"); + while(!w->evhead){ + if(w->deleted) { + respond(x, &fc, "window shut down"); return; } + w->eventx = x; winunlock(w); recvp(x->c); winlock(w, 'F'); - i++; } - - n = w->nevents; - if(n > x->count) - n = x->count; - fc.count = n; - fc.data = w->events; + + ev = w->evhead; + bufsz = ev->sz - ev->offset < x->count + ? ev->sz - ev->offset : x->count; + buf = emalloc(bufsz); + + memcpy(buf, ev->buf+ev->offset, bufsz); + ev->offset += bufsz; + + if(ev->offset == bufsz) { + w->evhead = ev->next; + free(ev->buf); + free(ev); + + if(!w->evhead) + w->evtail = nil; + } + + + fc.count = bufsz; + fc.data = buf; respond(x, &fc, nil); - b = w->events; - w->events = estrdup(w->events+n); - free(b); - w->nevents -= n; + free(buf); } void