-
-
Save irr/3775791 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment