Sha256: df9e620c45d1ae038d33026f7c866cbaffaccfa29b49eeae418f84ae6d784885
Contents?: true
Size: 1.82 KB
Versions: 1
Compression:
Stored size: 1.82 KB
Contents
#include "ev_dispatch.h" #include "ev_http.h" #include <sys/select.h> #include <errno.h> using namespace EVD; // catch SIGINT to kill process static void SIGINT_handler(int sig) { exit(sig); } static void run_tests( Dispatch &dispatcher, int count ) { time_t start_time = time(NULL); // tell the request to stream the response over this file descriptor HttpRequest *req = new HttpRequest( dispatcher, "http://127.0.0.1:4044/redir/2" ); req->set_opt("port", "4044"); req->set_opt("followlocation", "1"); //req->set_opt("maxredirs", "1"); req->set_opt("referer", "/delay/10"); req->set_opt("useragent", "users are us"); req->set_opt("cookie", "name1=content1; name2=content2;"); // set some arbitry headers struct curl_slist *slist = NULL; slist = curl_slist_append(slist, "x-my-header1: hi"); slist = curl_slist_append(slist, "x-my-header2: hello"); req->set_opt("headers", slist ); request_t id = dispatcher.request( req ); while( dispatcher.wait_for_response_by_id( id, Timer(1,5) ) ) { printf("waiting...\n"); } HttpResponse *res = (HttpResponse *)dispatcher.response_for( id ); printf("response: %s, in %.5lf seconds of Content-Length: %d bytes\n%s%s\n", res->name.c_str(), res->response_time, res->body.length(), res->m_header.c_str(), res->body.c_str() ); delete res; } int main(int argc, char **argv) { Dispatch dispatcher; if (signal(SIGINT, SIGINT_handler) == SIG_ERR) { printf("SIGINT install error\n"); exit(1); } if( !dispatcher.start() ){ fprintf( stderr, "Failed to start up dispatcher\n" ); return 1; } printf( "dispatcher thread running...\n" ); struct timeval start_time; Timer::current_time(&start_time); run_tests( dispatcher, 10 ); printf( "total time: %.5f seconds\n", Timer::elapsed_time( &start_time ) ); dispatcher.stop(); return 0; }
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
evdispatch-0.3.1 | ext/revdispatch/libdispatch-0.1/test/opt_test.cc |