evdispatch 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
    
        data/Manifest.txt
    CHANGED
    
    | 
         @@ -93,3 +93,5 @@ ext/revdispatch/libdispatch-0.1/test/Makefile.am 
     | 
|
| 
       93 
93 
     | 
    
         
             
            ext/revdispatch/libdispatch-0.1/test/Makefile.in
         
     | 
| 
       94 
94 
     | 
    
         
             
            ext/revdispatch/libdispatch-0.1/test/key_test.cc
         
     | 
| 
       95 
95 
     | 
    
         
             
            ext/revdispatch/libdispatch-0.1/test/next_test.cc
         
     | 
| 
      
 96 
     | 
    
         
            +
            ext/revdispatch/libdispatch-0.1/test/pipe_test.cc
         
     | 
| 
      
 97 
     | 
    
         
            +
            ext/revdispatch/libdispatch-0.1/test/opt_test.cc
         
     | 
| 
         @@ -0,0 +1,64 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #include "ev_dispatch.h"
         
     | 
| 
      
 2 
     | 
    
         
            +
            #include "ev_http.h"
         
     | 
| 
      
 3 
     | 
    
         
            +
            #include <sys/select.h>
         
     | 
| 
      
 4 
     | 
    
         
            +
            #include <errno.h>
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            using namespace EVD;
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            // catch SIGINT to kill process 
         
     | 
| 
      
 10 
     | 
    
         
            +
            static void  SIGINT_handler(int sig)
         
     | 
| 
      
 11 
     | 
    
         
            +
            {
         
     | 
| 
      
 12 
     | 
    
         
            +
              exit(sig);
         
     | 
| 
      
 13 
     | 
    
         
            +
            }
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            static void run_tests( Dispatch &dispatcher, int count )
         
     | 
| 
      
 16 
     | 
    
         
            +
            {
         
     | 
| 
      
 17 
     | 
    
         
            +
              time_t start_time = time(NULL);
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
              // tell the request to stream the response over this file descriptor
         
     | 
| 
      
 20 
     | 
    
         
            +
              HttpRequest *req = new HttpRequest( dispatcher, "http://127.0.0.1:4044/redir/2" );
         
     | 
| 
      
 21 
     | 
    
         
            +
              req->set_opt("port", "4044");
         
     | 
| 
      
 22 
     | 
    
         
            +
              req->set_opt("followlocation", "1");
         
     | 
| 
      
 23 
     | 
    
         
            +
              //req->set_opt("maxredirs", "1");
         
     | 
| 
      
 24 
     | 
    
         
            +
              req->set_opt("referer", "/delay/10");
         
     | 
| 
      
 25 
     | 
    
         
            +
              req->set_opt("useragent", "users are us");
         
     | 
| 
      
 26 
     | 
    
         
            +
              req->set_opt("cookie", "name1=content1; name2=content2;");
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
              request_t id = dispatcher.request( req );
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
              while( dispatcher.wait_for_response_by_id( id, Timer(1,5) ) ) {
         
     | 
| 
      
 31 
     | 
    
         
            +
                printf("waiting...\n");
         
     | 
| 
      
 32 
     | 
    
         
            +
              }
         
     | 
| 
      
 33 
     | 
    
         
            +
              HttpResponse *res = (HttpResponse *)dispatcher.response_for( id );
         
     | 
| 
      
 34 
     | 
    
         
            +
              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() );
         
     | 
| 
      
 35 
     | 
    
         
            +
              delete res;
         
     | 
| 
      
 36 
     | 
    
         
            +
            }
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
            int main(int argc, char **argv)
         
     | 
| 
      
 39 
     | 
    
         
            +
            {
         
     | 
| 
      
 40 
     | 
    
         
            +
              Dispatch dispatcher;
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
              if (signal(SIGINT, SIGINT_handler) == SIG_ERR) {
         
     | 
| 
      
 43 
     | 
    
         
            +
                printf("SIGINT install error\n");
         
     | 
| 
      
 44 
     | 
    
         
            +
                exit(1);
         
     | 
| 
      
 45 
     | 
    
         
            +
              }
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
              if( !dispatcher.start() ){
         
     | 
| 
      
 48 
     | 
    
         
            +
                fprintf( stderr, "Failed to start up dispatcher\n" );
         
     | 
| 
      
 49 
     | 
    
         
            +
                return 1;
         
     | 
| 
      
 50 
     | 
    
         
            +
              }
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
              printf( "dispatcher thread running...\n" );
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
              struct timeval start_time;
         
     | 
| 
      
 55 
     | 
    
         
            +
              Timer::current_time(&start_time);
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
              run_tests( dispatcher, 10 );
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
              printf( "total time: %.5f seconds\n", Timer::elapsed_time( &start_time ) );
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
              dispatcher.stop();
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
              return 0;
         
     | 
| 
      
 64 
     | 
    
         
            +
            }
         
     | 
| 
         @@ -0,0 +1,98 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #include "ev_dispatch.h"
         
     | 
| 
      
 2 
     | 
    
         
            +
            #include "ev_http.h"
         
     | 
| 
      
 3 
     | 
    
         
            +
            #include <sys/select.h>
         
     | 
| 
      
 4 
     | 
    
         
            +
            #include <errno.h>
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            using namespace EVD;
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            // catch SIGINT to kill process 
         
     | 
| 
      
 10 
     | 
    
         
            +
            static void  SIGINT_handler(int sig)
         
     | 
| 
      
 11 
     | 
    
         
            +
            {
         
     | 
| 
      
 12 
     | 
    
         
            +
              exit(sig);
         
     | 
| 
      
 13 
     | 
    
         
            +
            }
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            static void run_tests( Dispatch &dispatcher, int count )
         
     | 
| 
      
 16 
     | 
    
         
            +
            {
         
     | 
| 
      
 17 
     | 
    
         
            +
              time_t start_time = time(NULL);
         
     | 
| 
      
 18 
     | 
    
         
            +
              int response_count = 0;
         
     | 
| 
      
 19 
     | 
    
         
            +
              int pfd[2];
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              if( pipe( pfd ) ) {
         
     | 
| 
      
 22 
     | 
    
         
            +
                perror("pipe");
         
     | 
| 
      
 23 
     | 
    
         
            +
                return;
         
     | 
| 
      
 24 
     | 
    
         
            +
              }
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
              // tell the request to stream the response over this file descriptor
         
     | 
| 
      
 27 
     | 
    
         
            +
              HttpRequest *req = new HttpRequest( dispatcher, "http://www.google.com/", pfd[1] );
         
     | 
| 
      
 28 
     | 
    
         
            +
              HttpResponse *res = req->m_response;
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
              dispatcher.request( req );
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
              // select the response on this thread
         
     | 
| 
      
 33 
     | 
    
         
            +
              int retval;
         
     | 
| 
      
 34 
     | 
    
         
            +
              fd_set rd, wr, er;
         
     | 
| 
      
 35 
     | 
    
         
            +
              struct timeval tv;
         
     | 
| 
      
 36 
     | 
    
         
            +
              const int read_size = 1024;
         
     | 
| 
      
 37 
     | 
    
         
            +
              char READ_BUFFER[read_size];
         
     | 
| 
      
 38 
     | 
    
         
            +
              std::string result_buffer;
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
              FD_ZERO(&rd);
         
     | 
| 
      
 41 
     | 
    
         
            +
              FD_ZERO(&wr);
         
     | 
| 
      
 42 
     | 
    
         
            +
              FD_ZERO(&er);
         
     | 
| 
      
 43 
     | 
    
         
            +
              FD_SET(pfd[0], &rd);
         
     | 
| 
      
 44 
     | 
    
         
            +
              tv.tv_sec = 0;
         
     | 
| 
      
 45 
     | 
    
         
            +
              tv.tv_usec = 0;
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
              try {
         
     | 
| 
      
 48 
     | 
    
         
            +
                while( (retval = select( pfd[0]+1, &rd, &wr, &er, NULL )) ) {
         
     | 
| 
      
 49 
     | 
    
         
            +
                  if( retval == -1 && errno == EINTR ) { continue; }
         
     | 
| 
      
 50 
     | 
    
         
            +
                  if( retval < 0 ){ perror("select"); break; }
         
     | 
| 
      
 51 
     | 
    
         
            +
                  if( FD_ISSET(pfd[0],&rd) ){
         
     | 
| 
      
 52 
     | 
    
         
            +
                    retval = read(pfd[0],READ_BUFFER,read_size);
         
     | 
| 
      
 53 
     | 
    
         
            +
                    if( retval >= 0 ) {
         
     | 
| 
      
 54 
     | 
    
         
            +
                      result_buffer.append(READ_BUFFER,retval);
         
     | 
| 
      
 55 
     | 
    
         
            +
                      if( retval == 0 ){ break; }
         
     | 
| 
      
 56 
     | 
    
         
            +
                    }
         
     | 
| 
      
 57 
     | 
    
         
            +
                    else {
         
     | 
| 
      
 58 
     | 
    
         
            +
                      perror("read");
         
     | 
| 
      
 59 
     | 
    
         
            +
                      break;
         
     | 
| 
      
 60 
     | 
    
         
            +
                    }
         
     | 
| 
      
 61 
     | 
    
         
            +
                  }
         
     | 
| 
      
 62 
     | 
    
         
            +
                }
         
     | 
| 
      
 63 
     | 
    
         
            +
                fprintf( stderr, "loop returnd\n" );
         
     | 
| 
      
 64 
     | 
    
         
            +
                printf("response: %s, in %.5lf seconds of Content-Length: %d bytes\n%s", res->name.c_str(), res->response_time, result_buffer.length(), res->m_header.c_str() );
         
     | 
| 
      
 65 
     | 
    
         
            +
                delete res;
         
     | 
| 
      
 66 
     | 
    
         
            +
              }catch(const std::exception &exp){
         
     | 
| 
      
 67 
     | 
    
         
            +
                perror("select");
         
     | 
| 
      
 68 
     | 
    
         
            +
              }
         
     | 
| 
      
 69 
     | 
    
         
            +
              fprintf( stderr, "loop returnd\n" );
         
     | 
| 
      
 70 
     | 
    
         
            +
            }
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
            int main(int argc, char **argv)
         
     | 
| 
      
 73 
     | 
    
         
            +
            {
         
     | 
| 
      
 74 
     | 
    
         
            +
              Dispatch dispatcher;
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
              if (signal(SIGINT, SIGINT_handler) == SIG_ERR) {
         
     | 
| 
      
 77 
     | 
    
         
            +
                printf("SIGINT install error\n");
         
     | 
| 
      
 78 
     | 
    
         
            +
                exit(1);
         
     | 
| 
      
 79 
     | 
    
         
            +
              }
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
              if( !dispatcher.start() ){
         
     | 
| 
      
 82 
     | 
    
         
            +
                fprintf( stderr, "Failed to start up dispatcher\n" );
         
     | 
| 
      
 83 
     | 
    
         
            +
                return 1;
         
     | 
| 
      
 84 
     | 
    
         
            +
              }
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
              printf( "dispatcher thread running...\n" );
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
              struct timeval start_time;
         
     | 
| 
      
 89 
     | 
    
         
            +
              Timer::current_time(&start_time);
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
              run_tests( dispatcher, 10 );
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
              printf( "total time: %.5f seconds\n", Timer::elapsed_time( &start_time ) );
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
              dispatcher.stop();
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
              return 0;
         
     | 
| 
      
 98 
     | 
    
         
            +
            }
         
     | 
    
        data/lib/evdispatch/version.rb
    CHANGED
    
    
    
        data/website/index.html
    CHANGED
    
    | 
         @@ -18,7 +18,7 @@ 
     | 
|
| 
       18 
18 
     | 
    
         
             
                <h1>evdispatch</h1>
         
     | 
| 
       19 
19 
     | 
    
         
             
                <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/evdispatch"; return false'>
         
     | 
| 
       20 
20 
     | 
    
         
             
                  <p>Get Version</p>
         
     | 
| 
       21 
     | 
    
         
            -
                  <a href="http://rubyforge.org/projects/evdispatch" class="numbers">0. 
     | 
| 
      
 21 
     | 
    
         
            +
                  <a href="http://rubyforge.org/projects/evdispatch" class="numbers">0.2.0</a>
         
     | 
| 
       22 
22 
     | 
    
         
             
                </div>
         
     | 
| 
       23 
23 
     | 
    
         
             
                <h4 style="float:right;padding-right:10px;">→ ‘evdispatch’</h4>
         
     | 
| 
       24 
24 
     | 
    
         | 
    
        data/website/index.txt
    CHANGED
    
    | 
         @@ -31,9 +31,9 @@ For example in rails this might look like: 
     | 
|
| 
       31 
31 
     | 
    
         | 
| 
       32 
32 
     | 
    
         
             
              class DashController < ApplicationController
         
     | 
| 
       33 
33 
     | 
    
         
             
                def index
         
     | 
| 
       34 
     | 
    
         
            -
                  @blogs_id = $dispatcher. 
     | 
| 
       35 
     | 
    
         
            -
                  @news_id = $dispatcher. 
     | 
| 
       36 
     | 
    
         
            -
                  @messages_id = $dispatcher. 
     | 
| 
      
 34 
     | 
    
         
            +
                  @blogs_id = $dispatcher.request("http://10.0.6.45/service/blogs")
         
     | 
| 
      
 35 
     | 
    
         
            +
                  @news_id = $dispatcher.request("http://10.0.6.45/service/news")
         
     | 
| 
      
 36 
     | 
    
         
            +
                  @messages_id = $dispatcher.request("http://10.0.6.45/service/messages")
         
     | 
| 
       37 
37 
     | 
    
         
             
                end
         
     | 
| 
       38 
38 
     | 
    
         
             
              end
         
     | 
| 
       39 
39 
     | 
    
         | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification 
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: evdispatch
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.2. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors: 
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Todd A. Fisher
         
     | 
| 
         @@ -122,6 +122,8 @@ files: 
     | 
|
| 
       122 
122 
     | 
    
         
             
            - ext/revdispatch/libdispatch-0.1/test/Makefile.in
         
     | 
| 
       123 
123 
     | 
    
         
             
            - ext/revdispatch/libdispatch-0.1/test/key_test.cc
         
     | 
| 
       124 
124 
     | 
    
         
             
            - ext/revdispatch/libdispatch-0.1/test/next_test.cc
         
     | 
| 
      
 125 
     | 
    
         
            +
            - ext/revdispatch/libdispatch-0.1/test/pipe_test.cc
         
     | 
| 
      
 126 
     | 
    
         
            +
            - ext/revdispatch/libdispatch-0.1/test/opt_test.cc
         
     | 
| 
       125 
127 
     | 
    
         
             
            has_rdoc: true
         
     | 
| 
       126 
128 
     | 
    
         
             
            homepage: http://evdispatch.rubyforge.org
         
     | 
| 
       127 
129 
     | 
    
         
             
            post_install_message: 
         
     |