Skip to content

Instantly share code, notes, and snippets.

@irr
Forked from krikulis/evserver.c
Created September 24, 2012 12:49
Show Gist options
  • Save irr/3775791 to your computer and use it in GitHub Desktop.
Save irr/3775791 to your computer and use it in GitHub Desktop.
Simple evhttp example
#include <evhttp.h>
void process_request(struct evhttp_request *req, void *arg){
struct evbuffer *buf = evbuffer_new();
if (buf == NULL) return;
evbuffer_add_printf(buf, "Requested: %s\n", evhttp_request_uri(req));
evhttp_send_reply(req, HTTP_OK, "OK", buf);
}
int main () {
struct event_base *base = NULL;
struct evhttp *httpd = NULL;
base = event_init();
if (base == NULL) return -1;
httpd = evhttp_new(base);
if (httpd == NULL) return -1;
if (evhttp_bind_socket(httpd, "0.0.0.0", 12345) != 0) return -1;
evhttp_set_gencb(httpd, process_request, NULL);
event_base_dispatch(base);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment