File: example_basic.c

package info (click to toggle)
libevhtp 1.2.18-2.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,024 kB
  • sloc: ansic: 10,208; sh: 118; makefile: 19
file content (48 lines) | stat: -rw-r--r-- 1,099 bytes parent folder | download | duplicates (3)
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <errno.h>
#include <evhtp.h>
#include <unistd.h>

#include "./eutils.h"
#include "internal.h"
#include "evhtp/evhtp.h"
#include "evhtp/log.h"

static void
process_request_(evhtp_request_t * req, void * arg)
{
    (void)arg;

    evhtp_log_request_f(arg, req, stderr);
    evhtp_send_reply(req, EVHTP_RES_OK);
}

int
main(int argc, char ** argv)
{
    (void)argc;
    (void)argv;
    struct event_base * evbase;
    struct evhtp      * htp;
    void              * log;

    evbase = event_base_new();
    htp    = evhtp_new(evbase, NULL);
    log    = evhtp_log_new("$rhost $host '$ua' [$ts] '$meth $path HTTP/$proto' $status");

    evhtp_set_cb(htp, "/", process_request_, log);
    evhtp_enable_flag(htp, EVHTP_FLAG_ENABLE_ALL);

#ifndef EVHTP_DISABLE_EVTHR
    /* create 1 listener, 4 acceptors */
    evhtp_use_threads_wexit(htp, NULL, NULL, 4, NULL);
#endif

    log_info("Basic server, run: curl http://127.0.0.1:%d/",
            bind__sock_port0_(htp));
    event_base_loop(evbase, 0);
    return 0;
}