Sha256: c430e6eab4ee3ec7d91fc9dd6b244d85440ed6093fd9a984ff8b211e8f15a162

Contents?: true

Size: 1.61 KB

Versions: 6

Compression:

Stored size: 1.61 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;");

  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

6 entries across 6 versions & 1 rubygems

Version Path
evdispatch-0.2.1 ext/revdispatch/libdispatch-0.1/test/opt_test.cc
evdispatch-0.2.2 ext/revdispatch/libdispatch-0.1/test/opt_test.cc
evdispatch-0.2.4 ext/revdispatch/libdispatch-0.1/test/opt_test.cc
evdispatch-0.2.5 ext/revdispatch/libdispatch-0.1/test/opt_test.cc
evdispatch-0.3.0 ext/revdispatch/libdispatch-0.1/test/opt_test.cc
evdispatch-0.2.6 ext/revdispatch/libdispatch-0.1/test/opt_test.cc