Sha256: ba2c8cb4eff4ffc0ec00b0547d8d963ef7c77c89f30307acad509ecaacb5aef8

Contents?: true

Size: 1.29 KB

Versions: 4

Compression:

Stored size: 1.29 KB

Contents

#include "ev_dispatch.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(Request::HTTP, "http://www.yahoo.com/");
  request_t google_id = dispatcher.request(Request::HTTP, "http://www.google.com/");
  printf("yahoo: %d\n", yahoo_id);
  printf("google: %d\n", google_id);

  Response *res = NULL;
  Timer timeout(0,5);

  while( dispatcher.wait_for_response_by_id( yahoo_id, timeout ) ){
    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, timeout ) ){
    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;
}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
evdispatch-0.1.1 ext/revdispatch/libdispatch-0.1/test/key_test.cc
evdispatch-0.1.0 ext/revdispatch/libevdispatch/test/key_test.cc
evdispatch-0.1.2 ext/revdispatch/libdispatch-0.1/test/key_test.cc
evdispatch-0.1.3 ext/revdispatch/libdispatch-0.1/test/key_test.cc