#include "ev_dispatch.h" #include "ev_http.h" using namespace EVD; // catch SIGINT to kill process static void SIGINT_handler(int sig) { exit(sig); } 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" ); request_t yahoo_id = dispatcher.request( new HttpRequest( dispatcher, "http://www.yahoo.com/" ) ); request_t google_id = dispatcher.request(new HttpRequest( dispatcher, "http://www.google.com/" ) ); printf("yahoo: %d\n", yahoo_id); printf("google: %d\n", google_id); Response *res = NULL; while( dispatcher.wait_for_response_by_id( yahoo_id, Timer(1,5) ) ){ printf("waiting for yahoo...\n"); } res = dispatcher.response_for( yahoo_id ); printf("Recieved response from yahoo: %s, Content-Length: %d\n", res->name.c_str(), res->body.length() ); delete res; while( dispatcher.wait_for_response_by_id( google_id, Timer(1,5) ) ){ printf("waiting for google...\n"); } res = dispatcher.response_for( google_id ); printf("Recieved response from google: %s, Content-Length: %d\n", res->name.c_str(), res->body.length() ); delete res; return 0; }