Skip to content

Instantly share code, notes, and snippets.

@krikulis
Created January 24, 2011 13:13
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save krikulis/793194 to your computer and use it in GitHub Desktop.
Save krikulis/793194 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;
}
@krikulis
Copy link
Author

simple evhttp usage sample (libevent)

@wdalmut
Copy link

wdalmut commented Apr 2, 2012

Interesting GIST but you miss completely memory management that's right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment