Skip to content

Instantly share code, notes, and snippets.

Created February 16, 2011 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/829248 to your computer and use it in GitHub Desktop.
Save anonymous/829248 to your computer and use it in GitHub Desktop.
evhttp_connection_set_max_body_size test program
#include <stdio.h>
#include <assert.h>
#include <time.h>
#include <event2/event.h>
#include <event2/http.h>
#include <event2/http_struct.h>
#define TST_TIMEOUT 2
#define TST_MAX_RETRY 1
#define TST_MAX_BODY 25600 // This should be 25kb, right?
#define TST_HOST "www.bbned.nl"
#define TST_PATH "/scripts/speedtest/download/file32mb.bin"
static void request_cb(struct evhttp_request *req, void *ctx);
int start = 0;
int main(int argc, char *argv[])
{
struct event_base *base;
struct evhttp_connection *conn;
struct evhttp_request *req;
base = event_base_new();
assert(base != NULL);
conn = evhttp_connection_base_new(base, NULL, TST_HOST, 80);
assert(conn != NULL);
req = evhttp_request_new(request_cb, NULL);
assert(req != NULL);
// Pretty strange that you have to do this yourself by the way. Seeing as evhttp
// claims to be HTTP/1.1 compliant!
evhttp_add_header(req->output_headers, "Host", TST_HOST);
evhttp_connection_set_timeout(conn, TST_TIMEOUT);
evhttp_connection_set_retries(conn, TST_MAX_RETRY);
evhttp_connection_set_max_body_size(conn, TST_MAX_BODY);
evhttp_make_request(conn, req, EVHTTP_REQ_GET, TST_PATH);
// For a rough estimate on how long the request took.
start = time(NULL);
event_base_loop(base, 0);
event_base_free(base);
return 0;
}
static void request_cb(struct evhttp_request *req, void *ctx)
{
printf("request_cb(): runtime = ~%ld seconds.\n", (time(NULL) - start));
printf("request_cb(): request = %p\n", req);
if (req)
printf("request_cb(): status = %d\n", req->response_code);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment