Sha256: 3e49e8bcb0f61ebc2e5a91ae5c1128cdc3b4a239259e7a1caebc338f64dc9c37

Contents?: true

Size: 1.57 KB

Versions: 5

Compression:

Stored size: 1.57 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/test_post_length" );
  req->set_opt("post", "hello there world");

  request_t id = dispatcher.request( req );

  struct timeval start;
  Timer::current_time(&start);

  while( dispatcher.wait_for_response_by_id( id, Timer(0,500*1000*1000) ) ) {
    if( Timer::elapsed_time( &start ) > 2.0 ){
      printf("exceeded max elasped time...\n");
      break;
    }
  }

  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

5 entries across 5 versions & 1 rubygems

Version Path
evdispatch-0.2.4 ext/revdispatch/libdispatch-0.1/test/post_test.cc
evdispatch-0.2.5 ext/revdispatch/libdispatch-0.1/test/post_test.cc
evdispatch-0.3.0 ext/revdispatch/libdispatch-0.1/test/post_test.cc
evdispatch-0.2.6 ext/revdispatch/libdispatch-0.1/test/post_test.cc
evdispatch-0.3.1 ext/revdispatch/libdispatch-0.1/test/post_test.cc