cleanup: simplify frontend request ownership
This commit is contained in:
14
srv.c
14
srv.c
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user