-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsrv.c
More file actions
55 lines (46 loc) · 792 Bytes
/
srv.c
File metadata and controls
55 lines (46 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "dat.h"
#include "fn.h"
static char adir[40];
static void
sendkey(int fd, u32int ks, u32int mod)
{
Keyreq kr;
kr.fd = fd;
kr.ks = ks;
kr.mod = mod;
chansend(keyc, &kr);
}
static void
clientthread(void *arg)
{
int fd;
uchar req[4];
fd = (int)(uintptr)arg;
threadsetname("client %d", fd);
while(read(fd, req, 4) == 4)
sendkey(fd, req[2] | (req[3] << 8), req[1]);
close(fd);
}
static void
srvinit(void)
{
char addr[64];
snprint(addr, sizeof(addr), "unix!/tmp/strans.%d", getuid());
remove(addr + 5);
if(announce(addr, adir) < 0)
die("announce: %r");
}
void
srvthread(void*)
{
char ldir[40];
int fd;
threadsetname("srv");
srvinit();
for(;;){
fd = listen(adir, ldir);
if(fd < 0)
continue;
proccreate(clientthread, (void*)(uintptr)fd, 8192);
}
}