Skip to content

Instantly share code, notes, and snippets.

@dimavs
Created September 16, 2010 13:42
Show Gist options
  • Save dimavs/582442 to your computer and use it in GitHub Desktop.
Save dimavs/582442 to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <stdio.h>
#include <event.h>
#include <evhttp.h>
static void getindex(struct evhttp_request *req, void *arg)
{
struct evbuffer *buf = evbuffer_new();
size_t len;
evbuffer_add_printf(buf, "hello, world\n");
evhttp_send_reply(req, 200, "OK", buf);
evbuffer_free(buf);
}
int main(int argc, char **argv)
{
struct event_base *evbase;
struct evhttp *evhttp;
int rc;
evbase = event_init();
evhttp = evhttp_new(evbase);
evhttp_bind_socket(evhttp, NULL, 8081);
evhttp_set_cb(evhttp, "/", getindex, NULL);
evhttp_set_cb(evhttp, "/index.html", getindex, NULL);
rc = event_base_loop(evbase, 0);
if (rc) fprintf(stderr, "event_loop returned %d\n", rc);
evhttp_free(evhttp);
event_base_free(evbase);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment