cleanup: simplify frontend request ownership

This commit is contained in:
2026-08-13 21:57:32 +09:00
parent 13f0b436b8
commit b6a9ccd9d9
9 changed files with 74 additions and 79 deletions

14
srv.c
View File

@@ -11,7 +11,6 @@ typedef struct Client Client;
struct Client
{
int fd;
uvlong owner;
};
static int
@@ -27,9 +26,8 @@ srvreadkey(int fd, Keyreq *kr)
kr->op = ipcreqreset(req) ? Keyreset : Keypress;
kr->ks = ks;
kr->mod = mod;
kr->want = want;
memset(&kr->caret, 0, sizeof kr->caret);
return 0;
return want;
}
static void
@@ -42,7 +40,7 @@ clientthread(void *arg)
Keyres res;
uchar out[Ipcmaxresp];
char commit[Maxutf], preedit[Maxutf];
int n, ncommit, npreedit;
int n, ncommit, npreedit, want;
uchar token;
client = arg;
@@ -50,19 +48,18 @@ clientthread(void *arg)
threadsetname("client %d", fd);
reply = chancreate(sizeof(Keyres), 0);
kr.reply = reply;
kr.owner = client->owner;
while(srvreadkey(fd, &kr) == 0){
kr.owner = client;
while((want = srvreadkey(fd, &kr)) >= 0){
chansend(keyc, &kr);
chanrecv(reply, &res);
ncommit = stoutf(&res.commit, commit, sizeof commit);
npreedit = stoutf(&res.preedit, preedit, sizeof preedit);
n = ipcpackresp(out, sizeof out, res.eaten,
commit, ncommit, preedit, npreedit, kr.want);
commit, ncommit, preedit, npreedit, want);
if(n < 0 || ipcsend(fd, out, n) < 0)
break;
}
kr.op = Keyrelease;
kr.want = 0;
chansend(keyc, &kr);
chanrecv(reply, &res);
chanfree(reply);
@@ -110,7 +107,6 @@ srvthread(void*)
}
client = emalloc(sizeof *client);
client->fd = fd;
client->owner = ownernew();
if(proccreate(clientthread, client, 8192) < 0){
chanrecv(clientc, &token);
close(fd);