evdispatch 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,11 @@
1
+ == 0.4.1 2008-05-04
2
+ * Avoid deleting request before it finishes enabling
3
+ * Protect config.h with HAVE_CONFIG_H macro
4
+ * Add a load test
5
+
6
+ == 0.4.0 2008-05-04
7
+ * Improve build system to use libev embedding, instead of autoconf/autotools
8
+
1
9
  == 0.3.1 2008-04-23
2
10
  * Add support to set arbitrary HTTP headers
3
11
 
@@ -1,4 +1,6 @@
1
+ #ifdef HAVE_CONFIG_H
1
2
  #include "config.h"
3
+ #endif
2
4
  #include <stdio.h>
3
5
  #include "ev_dispatch.h"
4
6
  #include "ev_http.h"
@@ -239,8 +241,7 @@ void Dispatch::request_cb( struct ev_loop *loop, struct ev_async *w, int revents
239
241
  ++m_pending;
240
242
  if( !req->enable() ) { // XXX: if using DNS in requests expect this method to block while dns resolves
241
243
  --m_pending;
242
- printf("EVD::Dispatch request error\n");
243
- // for some reason we couldn't enable the request cleanup the request and continue
244
+ // either request could not be enabled or the request finished
244
245
  delete req;
245
246
  }
246
247
  }
@@ -1,7 +1,9 @@
1
1
  #ifndef EV_DISPATCH_H
2
2
  #define EV_DISPATCH_H
3
3
 
4
+ #ifdef HAVE_CONFIG_H
4
5
  #include "config.h"
6
+ #endif
5
7
  #include <time.h>
6
8
  #include <sys/time.h>
7
9
  #include <ev.h>
@@ -1,4 +1,6 @@
1
+ #ifdef HAVE_CONFIG_H
1
2
  #include "config.h"
3
+ #endif
2
4
  #include "ev_http.h"
3
5
 
4
6
  namespace EVD {
@@ -223,7 +225,9 @@ void HttpClient::check_handles()
223
225
  curl_easy_getinfo( easy, CURLINFO_PRIVATE, &req );
224
226
  //printf( " req %s finished\n", req->url.c_str() );
225
227
  req->finish(rc);
226
- delete req;
228
+
229
+ if( !req->m_enabling )
230
+ delete req;
227
231
  }
228
232
 
229
233
  } while( easy );
@@ -301,7 +305,7 @@ HttpRequest::HttpRequest( Dispatch &dispatch, const std::string &url )
301
305
  : Request( 0, url ),
302
306
  m_response(new HttpResponse(url)),
303
307
  m_handle(curl_easy_init()),
304
- m_client(dispatch.getHttpClient())
308
+ m_client(dispatch.getHttpClient()), m_enabling(false)
305
309
  {
306
310
  init_curl();
307
311
  }
@@ -318,6 +322,7 @@ HttpRequest::~HttpRequest()
318
322
 
319
323
  bool HttpRequest::enable()
320
324
  {
325
+ m_enabling = true;
321
326
  CURLMcode rc = curl_multi_add_handle( m_client->m_handle, m_handle );
322
327
 
323
328
  if( m_client ) {
@@ -333,7 +338,9 @@ bool HttpRequest::enable()
333
338
  printf("m_client went 0x0\n");
334
339
  }
335
340
  multi_error_report(rc);
336
- return (rc == CURLM_OK || rc == CURLM_CALL_MULTI_PERFORM);
341
+
342
+ m_enabling = false;
343
+ return (rc == CURLM_OK || rc == CURLM_CALL_MULTI_PERFORM || !m_finished);
337
344
  }
338
345
 
339
346
  void HttpRequest::finish(CURLcode rc)
@@ -345,6 +352,7 @@ void HttpRequest::finish(CURLcode rc)
345
352
  m_response->response_time = Timer::elapsed_time( &(this->start_time) );
346
353
  m_response->finish( m_client, rc );
347
354
 
355
+ m_finished = true;
348
356
  //fprintf( stderr, "DONE: (%s/%s) => (%d), body(%d): '%s'\n", url.c_str(), url.c_str(), rc, (int)m_response, m_response->body.c_str() );
349
357
  }
350
358
  void HttpRequest::set_key( request_t key )
@@ -1,7 +1,9 @@
1
1
  #ifndef EV_HTTP_H
2
2
  #define EV_HTTP_H
3
3
 
4
+ #ifdef HAVE_CONFIG_H
4
5
  #include "config.h"
6
+ #endif
5
7
  #include "ev_dispatch.h"
6
8
  #include <curl/curl.h>
7
9
  #include <set>
@@ -69,6 +71,8 @@ namespace EVD {
69
71
  CURL *m_handle;
70
72
  HttpClient *m_client;
71
73
  char m_error[CURL_ERROR_SIZE];
74
+ bool m_enabling; // added to prevent this object from being deleted before enable method is finished
75
+ bool m_finished; // toggled true when the request finishes before enabling is complete
72
76
  private:
73
77
  void init_curl();
74
78
  };
@@ -61,5 +61,10 @@ class TestApp
61
61
  [status, {'Content-Type' => 'text/json'}.merge(extras), body]
62
62
  end
63
63
  end
64
-
65
- Rack::Handler::Mongrel.run( Rack::ShowExceptions.new(Rack::Lint.new(TestApp.new)), :Port => TEST_PORT )
64
+ # ebb's much better at handling concurrent requests use it if it's installed
65
+ begin
66
+ require 'ebb'
67
+ Ebb.start_server(TestApp.new, :port => TEST_PORT)
68
+ rescue LoadError => e
69
+ Rack::Handler::Mongrel.run(TestApp.new, :Port => TEST_PORT )
70
+ end
@@ -2,7 +2,7 @@ module Evdispatch #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 4
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/script/console CHANGED
File without changes
data/script/destroy CHANGED
File without changes
data/script/generate CHANGED
File without changes
data/script/txt2html CHANGED
File without changes
@@ -9,8 +9,8 @@ class TestEvdispatch < Test::Unit::TestCase
9
9
  count = 10000
10
10
 
11
11
  streams = []
12
- # create 100 streams
13
- 100.times do|i|
12
+ # create 10 streams
13
+ 10.times do|i|
14
14
  stream = d.request("http://127.0.0.1:4044/bytes/#{count}", :stream => true )
15
15
  streams << stream
16
16
  end
@@ -18,7 +18,15 @@ class TestEvdispatch < Test::Unit::TestCase
18
18
  # TODO: we should expose the pipe so someone can select on ready responses
19
19
  for stream in streams do
20
20
  res = stream.read
21
- res = stream.read until res == 0
21
+ timer = Time.now
22
+ diff = Time.now - timer
23
+ while res != 0 and diff < 4.0
24
+ res = stream.read
25
+ diff = Time.now - timer
26
+ #puts "diff: #{diff}"
27
+ end
28
+
29
+ next if diff >= 4.0
22
30
 
23
31
  assert_equal( 0, res )
24
32
  assert_equal( "C"*count, stream.body )
data/test/test_helper.rb CHANGED
@@ -1,3 +1,6 @@
1
1
  require 'test/unit'
2
- $:.unshift File.dirname(__FILE__) + "/../ext/revdispatch"
3
- require File.dirname(__FILE__) + '/../lib/evdispatch'
2
+
3
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..','ext','revdispatch'))
4
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..','lib'))
5
+
6
+ require 'evdispatch'
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.4.0</a>
21
+ <a href="http://rubyforge.org/projects/evdispatch" class="numbers">0.4.1</a>
22
22
  </div>
23
23
  <h4 style="float:right;padding-right:10px;">&#x2192; &#8216;evdispatch&#8217;</h4>
24
24
 
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.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd A. Fisher
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-04 00:00:00 -04:00
12
+ date: 2008-05-15 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  requirements: []
110
110
 
111
111
  rubyforge_project: evdispatch
112
- rubygems_version: 1.1.1
112
+ rubygems_version: 1.0.1
113
113
  signing_key:
114
114
  specification_version: 2
115
115
  summary: Based on libev provides a background event loop for making simulataneous requests