evdispatch 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +21 -65
- data/ext/revdispatch/dispatch.cc +3 -0
- data/ext/revdispatch/extconf.rb +50 -32
- data/ext/revdispatch/{libdispatch-0.1 → libdispatch}/libev-3.31/ev++.h +0 -0
- data/ext/revdispatch/{libdispatch-0.1 → libdispatch}/libev-3.31/ev.c +0 -0
- data/ext/revdispatch/{libdispatch-0.1 → libdispatch}/libev-3.31/ev.h +0 -0
- data/ext/revdispatch/{libdispatch-0.1 → libdispatch}/libev-3.31/ev_epoll.c +0 -0
- data/ext/revdispatch/{libdispatch-0.1 → libdispatch}/libev-3.31/ev_kqueue.c +0 -0
- data/ext/revdispatch/{libdispatch-0.1 → libdispatch}/libev-3.31/ev_poll.c +0 -0
- data/ext/revdispatch/{libdispatch-0.1 → libdispatch}/libev-3.31/ev_port.c +0 -0
- data/ext/revdispatch/{libdispatch-0.1 → libdispatch}/libev-3.31/ev_select.c +0 -0
- data/ext/revdispatch/{libdispatch-0.1 → libdispatch}/libev-3.31/ev_vars.h +0 -0
- data/ext/revdispatch/{libdispatch-0.1 → libdispatch}/libev-3.31/ev_win32.c +0 -0
- data/ext/revdispatch/{libdispatch-0.1 → libdispatch}/libev-3.31/ev_wrap.h +0 -0
- data/ext/revdispatch/{libdispatch-0.1 → libdispatch}/libev-3.31/event.c +0 -0
- data/ext/revdispatch/{libdispatch-0.1 → libdispatch}/libev-3.31/event.h +0 -0
- data/ext/revdispatch/{libdispatch-0.1 → libdispatch}/src/ev_dispatch.cc +6 -17
- data/ext/revdispatch/{libdispatch-0.1 → libdispatch}/src/ev_dispatch.h +0 -0
- data/ext/revdispatch/libdispatch/src/ev_embed.c +6 -0
- data/ext/revdispatch/{libdispatch-0.1 → libdispatch}/src/ev_http.cc +11 -8
- data/ext/revdispatch/{libdispatch-0.1 → libdispatch}/src/ev_http.h +0 -0
- data/lib/evdispatch/version.rb +2 -2
- data/website/index.html +7 -1
- data/website/index.txt +6 -0
- metadata +23 -67
- data/ext/revdispatch/libdispatch-0.1/Changelog +0 -12
- data/ext/revdispatch/libdispatch-0.1/LICENSE +0 -0
- data/ext/revdispatch/libdispatch-0.1/Makefile.am +0 -10
- data/ext/revdispatch/libdispatch-0.1/Makefile.in +0 -636
- data/ext/revdispatch/libdispatch-0.1/README +0 -3
- data/ext/revdispatch/libdispatch-0.1/aclocal.m4 +0 -7268
- data/ext/revdispatch/libdispatch-0.1/autogen.sh +0 -11
- data/ext/revdispatch/libdispatch-0.1/config.guess +0 -1516
- data/ext/revdispatch/libdispatch-0.1/config.h.in +0 -112
- data/ext/revdispatch/libdispatch-0.1/config.sub +0 -1626
- data/ext/revdispatch/libdispatch-0.1/configure +0 -21779
- data/ext/revdispatch/libdispatch-0.1/configure.ac +0 -42
- data/ext/revdispatch/libdispatch-0.1/depcomp +0 -584
- data/ext/revdispatch/libdispatch-0.1/install-sh +0 -507
- data/ext/revdispatch/libdispatch-0.1/libev-3.31/Changes +0 -78
- data/ext/revdispatch/libdispatch-0.1/libev-3.31/LICENSE +0 -25
- data/ext/revdispatch/libdispatch-0.1/libev-3.31/Makefile.am +0 -18
- data/ext/revdispatch/libdispatch-0.1/libev-3.31/Makefile.in +0 -677
- data/ext/revdispatch/libdispatch-0.1/libev-3.31/README +0 -130
- data/ext/revdispatch/libdispatch-0.1/libev-3.31/aclocal.m4 +0 -7268
- data/ext/revdispatch/libdispatch-0.1/libev-3.31/autogen.sh +0 -6
- data/ext/revdispatch/libdispatch-0.1/libev-3.31/config.guess +0 -1516
- data/ext/revdispatch/libdispatch-0.1/libev-3.31/config.h.in +0 -112
- data/ext/revdispatch/libdispatch-0.1/libev-3.31/config.sub +0 -1626
- data/ext/revdispatch/libdispatch-0.1/libev-3.31/configure +0 -21500
- data/ext/revdispatch/libdispatch-0.1/libev-3.31/configure.ac +0 -18
- data/ext/revdispatch/libdispatch-0.1/libev-3.31/ev.3 +0 -3344
- data/ext/revdispatch/libdispatch-0.1/libev-3.31/ev.pod +0 -3268
- data/ext/revdispatch/libdispatch-0.1/libev-3.31/install-sh +0 -294
- data/ext/revdispatch/libdispatch-0.1/libev-3.31/libev.m4 +0 -28
- data/ext/revdispatch/libdispatch-0.1/libev-3.31/ltmain.sh +0 -6871
- data/ext/revdispatch/libdispatch-0.1/libev-3.31/missing +0 -336
- data/ext/revdispatch/libdispatch-0.1/libev-3.31/mkinstalldirs +0 -111
- data/ext/revdispatch/libdispatch-0.1/ltmain.sh +0 -6930
- data/ext/revdispatch/libdispatch-0.1/missing +0 -367
- data/ext/revdispatch/libdispatch-0.1/src/Makefile.am +0 -11
- data/ext/revdispatch/libdispatch-0.1/src/Makefile.in +0 -485
- data/ext/revdispatch/libdispatch-0.1/test/Makefile.am +0 -30
- data/ext/revdispatch/libdispatch-0.1/test/Makefile.in +0 -623
- data/ext/revdispatch/libdispatch-0.1/test/key_test.cc +0 -52
- data/ext/revdispatch/libdispatch-0.1/test/next_test.cc +0 -84
- data/ext/revdispatch/libdispatch-0.1/test/opt_test.cc +0 -70
- data/ext/revdispatch/libdispatch-0.1/test/pipe_test.cc +0 -241
- data/ext/revdispatch/libdispatch-0.1/test/post_test.cc +0 -66
- data/ext/revdispatch/libdispatch-0.1/test/stress_test.cc +0 -62
@@ -1,52 +0,0 @@
|
|
1
|
-
#include "ev_dispatch.h"
|
2
|
-
#include "ev_http.h"
|
3
|
-
|
4
|
-
using namespace EVD;
|
5
|
-
|
6
|
-
|
7
|
-
// catch SIGINT to kill process
|
8
|
-
static void SIGINT_handler(int sig)
|
9
|
-
{
|
10
|
-
exit(sig);
|
11
|
-
}
|
12
|
-
|
13
|
-
int main(int argc, char **argv)
|
14
|
-
{
|
15
|
-
Dispatch dispatcher;
|
16
|
-
|
17
|
-
if (signal(SIGINT, SIGINT_handler) == SIG_ERR) {
|
18
|
-
printf("SIGINT install error\n");
|
19
|
-
exit(1);
|
20
|
-
}
|
21
|
-
|
22
|
-
if( !dispatcher.start() ){
|
23
|
-
fprintf( stderr, "Failed to start up dispatcher\n" );
|
24
|
-
return 1;
|
25
|
-
}
|
26
|
-
|
27
|
-
printf( "dispatcher thread running...\n" );
|
28
|
-
|
29
|
-
request_t id1 = dispatcher.request( new HttpRequest( dispatcher, "http://127.0.0.1:4044/bytes/1000" ) );
|
30
|
-
request_t id2 = dispatcher.request(new HttpRequest( dispatcher, "http://127.0.0.1:4044/bytes/10" ) );
|
31
|
-
printf("1: %d\n", id1);
|
32
|
-
printf("2: %d\n", id2);
|
33
|
-
|
34
|
-
Response *res = NULL;
|
35
|
-
|
36
|
-
while( dispatcher.wait_for_response_by_id( id1, Timer(1,5) ) ){
|
37
|
-
printf("waiting for 1...\n");
|
38
|
-
}
|
39
|
-
res = dispatcher.response_for( id1 );
|
40
|
-
printf("Recieved response from 1: %s, Content-Length: %d\n", res->name.c_str(), res->body.length() );
|
41
|
-
delete res;
|
42
|
-
|
43
|
-
while( dispatcher.wait_for_response_by_id( id2, Timer(1,5) ) ){
|
44
|
-
printf("waiting for 2...\n");
|
45
|
-
}
|
46
|
-
|
47
|
-
res = dispatcher.response_for( id2 );
|
48
|
-
printf("Recieved response from 2: %s, Content-Length: %d\n", res->name.c_str(), res->body.length() );
|
49
|
-
delete res;
|
50
|
-
|
51
|
-
return 0;
|
52
|
-
}
|
@@ -1,84 +0,0 @@
|
|
1
|
-
|
2
|
-
#include "ev_dispatch.h"
|
3
|
-
#include "ev_http.h"
|
4
|
-
|
5
|
-
using namespace EVD;
|
6
|
-
|
7
|
-
|
8
|
-
// catch SIGINT to kill process
|
9
|
-
static void SIGINT_handler(int sig)
|
10
|
-
{
|
11
|
-
exit(sig);
|
12
|
-
}
|
13
|
-
|
14
|
-
static void run_tests( Dispatch &dispatcher, int count )
|
15
|
-
{
|
16
|
-
struct timeval start_time;
|
17
|
-
Timer::current_time(&start_time);
|
18
|
-
int response_count = 0;
|
19
|
-
|
20
|
-
dispatcher.request( new HttpRequest( dispatcher, "http://127.0.0.1:4044/bytes/10200/" ) );
|
21
|
-
dispatcher.request( new HttpRequest( dispatcher, "http://127.0.0.1:4044/bytes/10080/" ) );
|
22
|
-
dispatcher.request( new HttpRequest( dispatcher, "http://127.0.0.1:4044/delay/0.2/" ) );
|
23
|
-
dispatcher.request( new HttpRequest( dispatcher, "http://127.0.0.1:4044/bytes/100900/" ) );
|
24
|
-
dispatcher.request( new HttpRequest( dispatcher, "http://127.0.0.1:4044/delay/0.1/" ) );
|
25
|
-
dispatcher.request( new HttpRequest( dispatcher, "http://127.0.0.1:4044/delay/0.1/" ) );
|
26
|
-
dispatcher.request( new HttpRequest( dispatcher, "http://127.0.0.1:4044/delay/0.3/" ) );
|
27
|
-
dispatcher.request( new HttpRequest( dispatcher, "http://127.0.0.1:4044/bytes/1010/" ) );
|
28
|
-
int expected_response_count = 8 ;
|
29
|
-
|
30
|
-
//ev_sleep(0.2);
|
31
|
-
|
32
|
-
Response *rep = NULL;
|
33
|
-
double longest_request = 0.0;
|
34
|
-
|
35
|
-
// timer issues
|
36
|
-
Timer timeout(1,(500*1000*1000));
|
37
|
-
|
38
|
-
while( expected_response_count > 0 && (rep = dispatcher.get_next_response(timeout)) ){
|
39
|
-
if( longest_request < rep->response_time ){
|
40
|
-
longest_request = rep->response_time;
|
41
|
-
}
|
42
|
-
printf( "recieved response(%d): from '%s', Content-Length: %d bytes, within: %.5lf seconds \n", rep->id, rep->name.c_str(), rep->body.length(), rep->response_time );
|
43
|
-
++response_count;
|
44
|
-
delete rep;
|
45
|
-
--expected_response_count;
|
46
|
-
}
|
47
|
-
|
48
|
-
if( expected_response_count != 0 ){
|
49
|
-
printf( "Expected: %d responses but recieved: %d\n", expected_response_count, response_count );
|
50
|
-
}
|
51
|
-
printf( "%d responses completed, within %.5lf seconds\n", response_count, Timer::elapsed_time( &start_time ) );
|
52
|
-
printf( "longest request: %.5lf\n", longest_request );
|
53
|
-
}
|
54
|
-
|
55
|
-
int main(int argc, char **argv)
|
56
|
-
{
|
57
|
-
Dispatch dispatcher;
|
58
|
-
|
59
|
-
if (signal(SIGINT, SIGINT_handler) == SIG_ERR) {
|
60
|
-
printf("SIGINT install error\n");
|
61
|
-
exit(1);
|
62
|
-
}
|
63
|
-
|
64
|
-
if( !dispatcher.start() ){
|
65
|
-
fprintf( stderr, "Failed to start up dispatcher\n" );
|
66
|
-
return 1;
|
67
|
-
}
|
68
|
-
|
69
|
-
printf( "dispatcher thread running...\n" );
|
70
|
-
|
71
|
-
struct timeval start_time;
|
72
|
-
Timer::current_time(&start_time);
|
73
|
-
|
74
|
-
run_tests( dispatcher, 10 );
|
75
|
-
run_tests( dispatcher, 10 );
|
76
|
-
run_tests( dispatcher, 10 );
|
77
|
-
run_tests( dispatcher, 10 );
|
78
|
-
|
79
|
-
printf( "total time: %.5lf seconds\n", Timer::elapsed_time( &start_time ) );
|
80
|
-
|
81
|
-
dispatcher.stop();
|
82
|
-
|
83
|
-
return 0;
|
84
|
-
}
|
@@ -1,70 +0,0 @@
|
|
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
|
-
// set some arbitry headers
|
29
|
-
struct curl_slist *slist = NULL;
|
30
|
-
slist = curl_slist_append(slist, "x-my-header1: hi");
|
31
|
-
slist = curl_slist_append(slist, "x-my-header2: hello");
|
32
|
-
req->set_opt("headers", slist );
|
33
|
-
|
34
|
-
request_t id = dispatcher.request( req );
|
35
|
-
|
36
|
-
while( dispatcher.wait_for_response_by_id( id, Timer(1,5) ) ) {
|
37
|
-
printf("waiting...\n");
|
38
|
-
}
|
39
|
-
HttpResponse *res = (HttpResponse *)dispatcher.response_for( id );
|
40
|
-
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() );
|
41
|
-
delete res;
|
42
|
-
}
|
43
|
-
|
44
|
-
int main(int argc, char **argv)
|
45
|
-
{
|
46
|
-
Dispatch dispatcher;
|
47
|
-
|
48
|
-
if (signal(SIGINT, SIGINT_handler) == SIG_ERR) {
|
49
|
-
printf("SIGINT install error\n");
|
50
|
-
exit(1);
|
51
|
-
}
|
52
|
-
|
53
|
-
if( !dispatcher.start() ){
|
54
|
-
fprintf( stderr, "Failed to start up dispatcher\n" );
|
55
|
-
return 1;
|
56
|
-
}
|
57
|
-
|
58
|
-
printf( "dispatcher thread running...\n" );
|
59
|
-
|
60
|
-
struct timeval start_time;
|
61
|
-
Timer::current_time(&start_time);
|
62
|
-
|
63
|
-
run_tests( dispatcher, 10 );
|
64
|
-
|
65
|
-
printf( "total time: %.5f seconds\n", Timer::elapsed_time( &start_time ) );
|
66
|
-
|
67
|
-
dispatcher.stop();
|
68
|
-
|
69
|
-
return 0;
|
70
|
-
}
|
@@ -1,241 +0,0 @@
|
|
1
|
-
#include <ext/hash_map>
|
2
|
-
#include <algorithm>
|
3
|
-
#include "ev_dispatch.h"
|
4
|
-
#include "ev_http.h"
|
5
|
-
#include <sys/select.h>
|
6
|
-
#include <errno.h>
|
7
|
-
|
8
|
-
// NOTE:
|
9
|
-
// this test could be written to use libev and it's event loop, however because this
|
10
|
-
// library may be used in ruby it might be desireable to have a select example that could
|
11
|
-
// be easy used within ruby language
|
12
|
-
//
|
13
|
-
// NOTE:
|
14
|
-
// because this example uses a pipe there only about 400-500 conncurrent connections can be used.
|
15
|
-
|
16
|
-
typedef __gnu_cxx::hash_map<int, struct ResponseDelegate* > ResponseTable;
|
17
|
-
|
18
|
-
using namespace EVD;
|
19
|
-
|
20
|
-
struct ResponseDelegate {
|
21
|
-
|
22
|
-
ResponseDelegate();
|
23
|
-
~ResponseDelegate();
|
24
|
-
|
25
|
-
void set_response( HttpResponse *ptr );
|
26
|
-
|
27
|
-
bool init();
|
28
|
-
|
29
|
-
void finish();
|
30
|
-
|
31
|
-
HttpResponse *m_response;
|
32
|
-
int m_pfd[2];
|
33
|
-
|
34
|
-
};
|
35
|
-
|
36
|
-
struct ResponseManager {
|
37
|
-
static const int READ_SIZE = 1024;
|
38
|
-
ResponseManager();
|
39
|
-
~ResponseManager();
|
40
|
-
|
41
|
-
void watch_response( ResponseDelegate *rd );
|
42
|
-
|
43
|
-
void reset();
|
44
|
-
|
45
|
-
bool process();
|
46
|
-
private:
|
47
|
-
int retval;
|
48
|
-
fd_set rd, wr, er;
|
49
|
-
struct timeval tv;
|
50
|
-
char READ_BUFFER[READ_SIZE];
|
51
|
-
int max_fd;
|
52
|
-
std::vector<int> set_fds;
|
53
|
-
ResponseTable response_table;
|
54
|
-
};
|
55
|
-
|
56
|
-
|
57
|
-
ResponseManager::ResponseManager()
|
58
|
-
{
|
59
|
-
reset();
|
60
|
-
}
|
61
|
-
ResponseManager::~ResponseManager()
|
62
|
-
{
|
63
|
-
}
|
64
|
-
void ResponseManager::reset()
|
65
|
-
{
|
66
|
-
memset(READ_BUFFER, '\0', READ_SIZE);
|
67
|
-
FD_ZERO(&rd);
|
68
|
-
FD_ZERO(&wr);
|
69
|
-
FD_ZERO(&er);
|
70
|
-
tv.tv_sec = 1;
|
71
|
-
tv.tv_usec = 0;
|
72
|
-
max_fd = 0;
|
73
|
-
}
|
74
|
-
|
75
|
-
void ResponseManager::watch_response( ResponseDelegate *res_del )
|
76
|
-
{
|
77
|
-
int fd = res_del->m_pfd[0];
|
78
|
-
FD_SET(fd, &rd);
|
79
|
-
if( fd > max_fd ){ max_fd = fd; }
|
80
|
-
set_fds.push_back( fd );
|
81
|
-
response_table[ fd ] = res_del;
|
82
|
-
std::sort(set_fds.begin(),set_fds.end());
|
83
|
-
}
|
84
|
-
|
85
|
-
bool ResponseManager::process()
|
86
|
-
{
|
87
|
-
int finished_count = 0;
|
88
|
-
|
89
|
-
while( !set_fds.empty() ) {
|
90
|
-
this->reset();
|
91
|
-
for( std::vector<int>::iterator i = set_fds.begin(); i != set_fds.end(); ++i ) {
|
92
|
-
int fd = *i;
|
93
|
-
FD_SET(fd, &rd);
|
94
|
-
if( fd > max_fd ) { max_fd = fd; }
|
95
|
-
}
|
96
|
-
|
97
|
-
retval = select( max_fd+1, &rd, &wr, &er, &tv );
|
98
|
-
|
99
|
-
tv.tv_sec = 1;
|
100
|
-
tv.tv_usec = 0;
|
101
|
-
|
102
|
-
if( retval == 0 ) { printf("select timedout\n"); continue; }
|
103
|
-
if( retval == -1 && errno == EINTR ) { continue; }
|
104
|
-
if( retval < 0 ){ perror("select"); return false; }
|
105
|
-
|
106
|
-
bool finished_fd = false;
|
107
|
-
do {
|
108
|
-
finished_fd = false;
|
109
|
-
for( std::vector<int>::iterator i = set_fds.begin(); i != set_fds.end(); ++i ) {
|
110
|
-
int fd = *i;
|
111
|
-
|
112
|
-
if( FD_ISSET(fd,&rd) ) {
|
113
|
-
ResponseTable::iterator del_loc = response_table.find(fd);
|
114
|
-
ResponseDelegate *del = del_loc->second;
|
115
|
-
if( del ) {
|
116
|
-
retval = read(fd,READ_BUFFER,READ_SIZE);
|
117
|
-
if( retval >= 0 ) {
|
118
|
-
del->m_response->body.append(READ_BUFFER,retval);
|
119
|
-
if( retval == 0 ){
|
120
|
-
del->finish();
|
121
|
-
response_table.erase(del_loc);
|
122
|
-
set_fds.erase(i);
|
123
|
-
std::sort(set_fds.begin(),set_fds.end());
|
124
|
-
std::vector<int>::iterator max_loc = std::max(set_fds.begin(),set_fds.end());
|
125
|
-
max_fd = *max_loc;
|
126
|
-
FD_CLR(fd,&rd); // remove the file descriptor
|
127
|
-
printf("finished: %d of %d, max_fd: %d\n", ++finished_count, set_fds.size(), max_fd );
|
128
|
-
finished_fd = true;
|
129
|
-
delete del;
|
130
|
-
break;
|
131
|
-
}
|
132
|
-
}
|
133
|
-
else {
|
134
|
-
perror("read");
|
135
|
-
return false;
|
136
|
-
}
|
137
|
-
}
|
138
|
-
}// end if
|
139
|
-
|
140
|
-
} // end for
|
141
|
-
|
142
|
-
}while( finished_fd );
|
143
|
-
}
|
144
|
-
|
145
|
-
return true;
|
146
|
-
}
|
147
|
-
|
148
|
-
ResponseDelegate::ResponseDelegate() :m_response(NULL)
|
149
|
-
{
|
150
|
-
}
|
151
|
-
|
152
|
-
ResponseDelegate::~ResponseDelegate()
|
153
|
-
{
|
154
|
-
close(m_pfd[0]);
|
155
|
-
delete m_response;
|
156
|
-
}
|
157
|
-
|
158
|
-
void ResponseDelegate::set_response( HttpResponse *ptr )
|
159
|
-
{
|
160
|
-
m_response = ptr;
|
161
|
-
}
|
162
|
-
|
163
|
-
bool ResponseDelegate::init()
|
164
|
-
{
|
165
|
-
if( pipe(m_pfd) ) { perror("pipe"); return false; }
|
166
|
-
return true;
|
167
|
-
}
|
168
|
-
|
169
|
-
void ResponseDelegate::finish()
|
170
|
-
{
|
171
|
-
printf("Response: %s, of %d bytes in %5lf seconds\n", m_response->name.c_str(), m_response->body.length(), m_response->response_time );
|
172
|
-
}
|
173
|
-
|
174
|
-
|
175
|
-
// catch SIGINT to kill process
|
176
|
-
static void SIGINT_handler(int sig)
|
177
|
-
{
|
178
|
-
exit(sig);
|
179
|
-
}
|
180
|
-
|
181
|
-
static bool make_request( const std::string &url, Dispatch &dispatcher, ResponseManager &rm )
|
182
|
-
{
|
183
|
-
ResponseDelegate *pres = new ResponseDelegate();
|
184
|
-
|
185
|
-
if( !pres->init() ){ delete pres; return false; }
|
186
|
-
|
187
|
-
// tell the request to stream the response over this file descriptor
|
188
|
-
//HttpRequest *req = new HttpRequest( dispatcher, "http://127.0.0.1:4044/bytes/10/", pfd[1] );
|
189
|
-
HttpRequest *req = new HttpRequest( dispatcher, "http://127.0.0.1:4044/bytes/10/", pres->m_pfd[1] );
|
190
|
-
//HttpResponse *res = req->m_response;
|
191
|
-
pres->set_response( req->m_response );
|
192
|
-
|
193
|
-
// make the request
|
194
|
-
dispatcher.request( req );
|
195
|
-
|
196
|
-
rm.watch_response( pres );
|
197
|
-
|
198
|
-
return true;
|
199
|
-
}
|
200
|
-
|
201
|
-
static void run_tests( Dispatch &dispatcher, int count )
|
202
|
-
{
|
203
|
-
time_t start_time = time(NULL);
|
204
|
-
int response_count = 0;
|
205
|
-
|
206
|
-
ResponseManager rm;
|
207
|
-
|
208
|
-
for( int i = 0; i < 50; ++i ) {
|
209
|
-
make_request( "http://127.0.0.1:4044/bytes/10/", dispatcher, rm );
|
210
|
-
}
|
211
|
-
|
212
|
-
rm.process();
|
213
|
-
}
|
214
|
-
|
215
|
-
int main(int argc, char **argv)
|
216
|
-
{
|
217
|
-
Dispatch dispatcher;
|
218
|
-
|
219
|
-
if (signal(SIGINT, SIGINT_handler) == SIG_ERR) {
|
220
|
-
printf("SIGINT install error\n");
|
221
|
-
exit(1);
|
222
|
-
}
|
223
|
-
|
224
|
-
if( !dispatcher.start() ){
|
225
|
-
fprintf( stderr, "Failed to start up dispatcher\n" );
|
226
|
-
return 1;
|
227
|
-
}
|
228
|
-
|
229
|
-
printf( "dispatcher thread running...\n" );
|
230
|
-
|
231
|
-
struct timeval start_time;
|
232
|
-
Timer::current_time(&start_time);
|
233
|
-
|
234
|
-
run_tests( dispatcher, 10 );
|
235
|
-
|
236
|
-
printf( "total time: %.5f seconds\n", Timer::elapsed_time( &start_time ) );
|
237
|
-
|
238
|
-
dispatcher.stop();
|
239
|
-
|
240
|
-
return 0;
|
241
|
-
}
|