fix: assign one active engine owner
This commit is contained in:
25
srv.c
25
srv.c
@@ -4,6 +4,13 @@
|
||||
static char adir[40];
|
||||
static Channel *clientc;
|
||||
|
||||
typedef struct Client Client;
|
||||
struct Client
|
||||
{
|
||||
int fd;
|
||||
uvlong owner;
|
||||
};
|
||||
|
||||
int
|
||||
srvreadkey(int fd, Keyreq *kr)
|
||||
{
|
||||
@@ -14,6 +21,7 @@ srvreadkey(int fd, Keyreq *kr)
|
||||
if(ipcreadn(fd, req, sizeof req) < 0)
|
||||
return -1;
|
||||
ipcunpackreq(req, &want, &mod, &ks);
|
||||
kr->op = ipcreqreset(req) ? Keyreset : Keypress;
|
||||
kr->ks = ks;
|
||||
kr->mod = mod;
|
||||
kr->want = want;
|
||||
@@ -23,6 +31,7 @@ srvreadkey(int fd, Keyreq *kr)
|
||||
static void
|
||||
clientthread(void *arg)
|
||||
{
|
||||
Client *client;
|
||||
Channel *reply;
|
||||
int fd;
|
||||
Keyreq kr;
|
||||
@@ -32,10 +41,12 @@ clientthread(void *arg)
|
||||
int n, ncommit, npreedit;
|
||||
uchar token;
|
||||
|
||||
fd = (int)(uintptr)arg;
|
||||
client = arg;
|
||||
fd = client->fd;
|
||||
threadsetname("client %d", fd);
|
||||
reply = chancreate(sizeof(Keyres), 0);
|
||||
kr.reply = reply;
|
||||
kr.owner = client->owner;
|
||||
while(srvreadkey(fd, &kr) == 0){
|
||||
chansend(keyc, &kr);
|
||||
chanrecv(reply, &res);
|
||||
@@ -46,8 +57,13 @@ clientthread(void *arg)
|
||||
if(n < 0 || ipcsend(fd, out, n) < 0)
|
||||
break;
|
||||
}
|
||||
kr.op = Keyrelease;
|
||||
kr.want = 0;
|
||||
chansend(keyc, &kr);
|
||||
chanrecv(reply, &res);
|
||||
chanfree(reply);
|
||||
close(fd);
|
||||
free(client);
|
||||
chanrecv(clientc, &token);
|
||||
}
|
||||
|
||||
@@ -65,6 +81,7 @@ srvinit(void)
|
||||
void
|
||||
srvthread(void*)
|
||||
{
|
||||
Client *client;
|
||||
char ldir[40];
|
||||
int fd;
|
||||
uchar token;
|
||||
@@ -81,9 +98,13 @@ srvthread(void*)
|
||||
close(fd);
|
||||
continue;
|
||||
}
|
||||
if(proccreate(clientthread, (void*)(uintptr)fd, 8192) < 0){
|
||||
client = emalloc(sizeof *client);
|
||||
client->fd = fd;
|
||||
client->owner = ownernew();
|
||||
if(proccreate(clientthread, client, 8192) < 0){
|
||||
chanrecv(clientc, &token);
|
||||
close(fd);
|
||||
free(client);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user