Skip to content

Instantly share code, notes, and snippets.

@mythosil
Created August 18, 2011 15:16
Show Gist options
  • Save mythosil/1154284 to your computer and use it in GitHub Desktop.
Save mythosil/1154284 to your computer and use it in GitHub Desktop.
evhttp returns notfound only
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <event.h>
#include <evhttp.h>
#define HTTPD_ADDR "0.0.0.0"
#define HTTPD_PORT 8080
void req_handler(struct evhttp_request *r, void *arg)
{
evhttp_send_error(r, HTTP_NOTFOUND, "Not Found");
}
int main(int argc, const char* argv[])
{
struct event_base *ev_base;
struct evhttp *httpd;
ev_base = event_base_new();
httpd = evhttp_new(ev_base);
if (evhttp_bind_socket(httpd, HTTPD_ADDR, HTTPD_PORT) < 0) {
perror("evhttp_bind_socket()");
exit(EXIT_FAILURE);
}
evhttp_set_gencb(httpd, req_handler, NULL);
event_base_dispatch(ev_base);
evhttp_free(httpd);
event_base_free(ev_base);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment