Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

commented Jan 26, 2011

simple evhttp usage sample (libevent)

@wdalmut

This comment has been minimized.

Copy link

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
You can’t perform that action at this time.