aboutsummaryrefslogtreecommitdiff
path: root/server.c
blob: 852568958147fa081e3f76dc05d1b0232fef57d4 (plain)
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
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <strings.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/epoll.h>
#include <errno.h>

#include "evloop.h"
#include "tsocket.h"
#include "util.h"
#include "acceptor.h"
#include "tpool.h"

int main()
{
    evloop_t *el = evloop_create();
    if (el == NULL)
        panic("eventloop creation");

    struct tsocket *sock = tsocket_create();
    if (sock == NULL
            || tsocket_bind(sock, "127.0.0.1", 8888) == -1
            || tsocket_listen(sock) == -1)
        panic("socket creation");

    tpool = tpool_create(0);
    if (!tpool)
        panic("tpool_create");

    event_t *acceptEvent = conn_acceptor_create_event(sock, el);
    if (evloop_add(el, acceptEvent, EPOLLIN) == -1)
        panic("eventloop add fd");

    evloop_loop(el);
}