forked from beanstalkd/beanstalkd
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsrv.c
69 lines (55 loc) · 965 Bytes
/
srv.c
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdint.h>
#include <stdlib.h>
#include <sys/socket.h>
#include "dat.h"
struct Server srv = {
Portdef,
NULL,
NULL,
{
Filesizedef,
},
};
void
srvserve(Server *s)
{
int r;
sockinit((Handle)srvtick, s, 10*1000000); // 10ms
s->sock.x = s;
s->sock.f = (Handle)srvaccept;
s->conns.less = (Less)connless;
s->conns.rec = (Record)connrec;
r = listen(s->sock.fd, 1024);
if (r == -1) {
twarn("listen");
return;
}
r = sockwant(&s->sock, 'r');
if (r == -1) {
twarn("sockwant");
exit(2);
}
sockmain();
twarnx("sockmain");
exit(1);
}
void
srvschedconn(Server *s, Conn *c)
{
if (c->tickpos > -1) {
heapremove(&s->conns, c->tickpos);
}
if (c->tickat) {
heapinsert(&s->conns, c);
}
}
void
srvaccept(Server *s, int ev)
{
h_accept(s->sock.fd, ev, s);
}
void
srvtick(Server *s, int ev)
{
prottick(s);
}