aboutsummaryrefslogtreecommitdiff
path: root/server.c
blob: f4ad78dd14f8ef2a8dfc662cca72cadafc8649f3 (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
#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 "eventloop.h"
#include "tsocket.h"
#include "util.h"
#include "connection.h"
#include "acceptor.h"

int main()
{
    struct eventLoop *el = eventLoopNew();
    if (el == NULL)
        panic("eventloop creation");

    struct tsocket *sock = tsocketNew();
    if (sock == NULL
            || tsocketBind(sock, "127.0.0.1", 8888) == -1
            || tsocketListen(sock) == -1)
        panic("socket creation");

    struct event *acceptEvent = connAcceptorNewEvent(sock, el);
    if (eventLoopAdd(el, acceptEvent, EPOLLIN) == -1)
        panic("eventloop add fd");

    eventLoopLoop(el);
}