ref: 49e08b52aee80d61b1302dcf7fe28e96dd0a3973
parent: 482dce5fd337a05deac98fa492af4ce9193b4040
author: Michael Misch <michaelmisch1985@gmail.com>
date: Sat Jul 6 21:55:52 EDT 2024
Fix blocking reads on client
--- a/TODO
+++ b/TODO
@@ -12,7 +12,6 @@
## Client
- Add in command to toggle markup
-- Blocking reads for feed, potentially a cb to clear out unread counts
## Notifications:
@@ -23,3 +22,4 @@
- list available buffers with unread counts, add notify `!` when applicable
- Install fmt for printing
+- Clearing unreads on the rwakeupall
--- a/buffer.c
+++ b/buffer.c
@@ -68,14 +68,9 @@
bufferSearch(Buffer *base, char *name)
{Buffer *sp;
- qlock(base);
for(sp = base; sp; sp = sp->next)
- if(strcmp(sp->name, name) == 0){- qunlock(base);
- qlock(sp);
+ if(strcmp(sp->name, name) == 0)
return sp;
- }
- qunlock(base);
return nil;
}
--- a/client.c
+++ b/client.c
@@ -54,6 +54,7 @@
static Buffer *root;
static int nclient;
static int time0;
+static Srv *fs;
static Client*
newclient(char *aname)
@@ -73,8 +74,6 @@
cl->current = bufferSearch(root, aname);
cl->showmarkdown = 0;
- if(cl->current)
- qunlock(cl->current);
return cl;
}
@@ -222,7 +221,6 @@
respond(r, nil);
return;
case Qfeed:
-Read:
// Catch EOF
if(!f->cl->fd || !f->cl->current){r->ofcall.data[0] = 0;
@@ -230,19 +228,22 @@
return;
}
b = f->cl->current;
+ srvrelease(fs);
qlock(b);
+Again:
n = pread(f->cl->fd, buf, sizeof(buf), r->ifcall.offset);
if(n){// cut off the EOF
- r->ofcall.count = strlen(buf) - 1;
+ r->ofcall.count = n;
memmove(r->ofcall.data, buf, n);
- } else if(f->cl->current) {+ } else{rsleep(&b->rz);
- qunlock(b);
- goto Read;
+ goto Again;
}
- respond(r, nil);
qunlock(b);
+ memset(buf, 0, sizeof(buf));
+ srvacquire(fs);
+ respond(r, nil);
return;
case Qtitle:
if(f->cl->current && f->cl->current->title){@@ -307,7 +308,6 @@
f->cl->fd = open(path, OREAD);
r->fid->aux = f;
respond(r, nil);
- qunlock(f->cl->current);
} else if(strcmp(t, "markdown")==0){if(f->cl->showmarkdown)
f->cl->showmarkdown = 0;
@@ -365,6 +365,7 @@
root = emalloc(sizeof(*root));
USED(root);
root = (Buffer*)s->aux;
+ fs = s;
time0 = time(0);
}
--- a/service.c
+++ b/service.c
@@ -24,7 +24,7 @@
nil,
};
-Srv clfs =
+Srv clfs =
{.start=clstart,
.attach=clattach,
@@ -45,7 +45,6 @@
struct Svcfid
{ int level;Service *svc;
- // Who knows
};
struct Service
@@ -316,6 +315,7 @@
{// Probably notifications as well?
Buffer *b;
+ Dir *d;
char *cmd, *targ;
cmd = strtok(s, " ");
@@ -322,11 +322,13 @@
targ = strtok(nil, "\n");
if(strcmp(cmd, "feed")==0) { if(b = bufferSearch(svc->base, targ)) {- seek(b->fd, 0, 2);
- write(b->fd, data, strlen(data));
-
+ qlock(b);
+ d = dirfstat(b->fd);
+ data[strlen(data)] = '\n';
+ pwrite(b->fd, data, strlen(data), d->length);
+ free(d);
if(rwakeupall(&b->rz)){- // We have readers, we can update tabs
+ print("Unlocking all threads\n");}
qunlock(b);
return nil;
@@ -335,7 +337,6 @@
} else if(strcmp(cmd, "status")==0){ if(b = bufferSearch(svc->base, targ)) {strcpy(b->status, data);
- qunlock(b);
return nil;
}
return "buffer not found";
@@ -342,7 +343,6 @@
} else if(strcmp(cmd, "title")==0){ if(b = bufferSearch(svc->base, targ)) {strcpy(b->title, data);
- qunlock(b);
return nil;
}
return "buffer not found";
@@ -349,7 +349,6 @@
} else if(strcmp(cmd, "status")==0){ if(b = bufferSearch(svc->base, targ)) {strcpy(b->status, data);
- qunlock(b);
return nil;
}
return "buffer not found";
@@ -356,7 +355,6 @@
} else if(strcmp(cmd, "aside")==0){ if(b = bufferSearch(svc->base, targ)) {strcpy(b->aside, data);
- qunlock(b);
return nil;
}
return "buffer not found";
@@ -397,7 +395,6 @@
t = svcctl(f->svc, s, t);
respond(r, t);
} else {- // Set a short limit on this probably
f->svc->name = estrdup(s);
f->svc->base->name = estrdup(s);
memset(path, 0, sizeof(path));
@@ -407,6 +404,7 @@
f->svc->childpid = threadpostsrv(&clfs, s);
if(f->svc->childpid >= 0){f->svc->isInitialized++;
+ r->fid->aux = f;
respond(r, nil);
} else
respond(r, "Unable to post to srv");
--
⑨