Created
January 24, 2011 13:13
-
-
Save krikulis/793194 to your computer and use it in GitHub Desktop.
Simple evhttp example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
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
simple evhttp usage sample (libevent)