server: remove client ownership wrapper
This commit is contained in:
19
srv.c
19
srv.c
@@ -7,12 +7,6 @@
|
|||||||
static char adir[256];
|
static char adir[256];
|
||||||
static Channel *clientc;
|
static Channel *clientc;
|
||||||
|
|
||||||
typedef struct Client Client;
|
|
||||||
struct Client
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
};
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
srvreadkey(int fd, Keyreq *kr)
|
srvreadkey(int fd, Keyreq *kr)
|
||||||
{
|
{
|
||||||
@@ -33,7 +27,6 @@ srvreadkey(int fd, Keyreq *kr)
|
|||||||
static void
|
static void
|
||||||
clientthread(void *arg)
|
clientthread(void *arg)
|
||||||
{
|
{
|
||||||
Client *client;
|
|
||||||
Channel *reply;
|
Channel *reply;
|
||||||
int fd;
|
int fd;
|
||||||
Keyreq kr;
|
Keyreq kr;
|
||||||
@@ -43,12 +36,11 @@ clientthread(void *arg)
|
|||||||
int n, ncommit, npreedit, want;
|
int n, ncommit, npreedit, want;
|
||||||
uchar token;
|
uchar token;
|
||||||
|
|
||||||
client = arg;
|
fd = (int)(uintptr)arg;
|
||||||
fd = client->fd;
|
|
||||||
threadsetname("client %d", fd);
|
threadsetname("client %d", fd);
|
||||||
reply = chancreate(sizeof(Keyres), 0);
|
reply = chancreate(sizeof(Keyres), 0);
|
||||||
kr.reply = reply;
|
kr.reply = reply;
|
||||||
kr.owner = client;
|
kr.owner = &fd;
|
||||||
while((want = srvreadkey(fd, &kr)) >= 0){
|
while((want = srvreadkey(fd, &kr)) >= 0){
|
||||||
chansend(keyc, &kr);
|
chansend(keyc, &kr);
|
||||||
chanrecv(reply, &res);
|
chanrecv(reply, &res);
|
||||||
@@ -64,7 +56,6 @@ clientthread(void *arg)
|
|||||||
chanrecv(reply, &res);
|
chanrecv(reply, &res);
|
||||||
chanfree(reply);
|
chanfree(reply);
|
||||||
close(fd);
|
close(fd);
|
||||||
free(client);
|
|
||||||
chanrecv(clientc, &token);
|
chanrecv(clientc, &token);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +79,6 @@ srvinit(void)
|
|||||||
void
|
void
|
||||||
srvthread(void*)
|
srvthread(void*)
|
||||||
{
|
{
|
||||||
Client *client;
|
|
||||||
char ldir[40];
|
char ldir[40];
|
||||||
int fd;
|
int fd;
|
||||||
uchar token;
|
uchar token;
|
||||||
@@ -105,12 +95,9 @@ srvthread(void*)
|
|||||||
close(fd);
|
close(fd);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
client = emalloc(sizeof *client);
|
if(proccreate(clientthread, (void*)(uintptr)fd, 8192) < 0){
|
||||||
client->fd = fd;
|
|
||||||
if(proccreate(clientthread, client, 8192) < 0){
|
|
||||||
chanrecv(clientc, &token);
|
chanrecv(clientc, &token);
|
||||||
close(fd);
|
close(fd);
|
||||||
free(client);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user