Travis: stifle progress on git clone
[beanstalkd.git] / serv.c
bloba8ba36302881541c8f252d951fbb34ce68dfa230
1 #include <stdint.h>
2 #include <stdlib.h>
3 #include <sys/socket.h>
4 #include "dat.h"
6 struct Server srv = {
7 Portdef,
8 NULL,
9 NULL,
11 Filesizedef,
16 void
17 srvserve(Server *s)
19 int r;
20 Socket *sock;
21 int64 period;
23 if (sockinit() == -1) {
24 twarnx("sockinit");
25 exit(1);
28 s->sock.x = s;
29 s->sock.f = (Handle)srvaccept;
30 s->conns.less = (Less)connless;
31 s->conns.rec = (Record)connrec;
33 r = listen(s->sock.fd, 1024);
34 if (r == -1) {
35 twarn("listen");
36 return;
39 r = sockwant(&s->sock, 'r');
40 if (r == -1) {
41 twarn("sockwant");
42 exit(2);
46 for (;;) {
47 period = prottick(s);
49 int rw = socknext(&sock, period);
50 if (rw == -1) {
51 twarnx("socknext");
52 exit(1);
55 if (rw) {
56 sock->f(sock->x, rw);
62 void
63 srvaccept(Server *s, int ev)
65 h_accept(s->sock.fd, ev, s);