eventmachine-le 1.1.0.beta.1 → 1.1.0.beta.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -61,6 +61,11 @@ Install the Ruby Gem:
61
61
  gem install eventmachine-le
62
62
  </pre>
63
63
 
64
+ If you want the beta version (not fully tested) install it by using `--pre` option:
65
+ <pre>
66
+ gem install eventmachine-le --pre
67
+ </pre>
68
+
64
69
 
65
70
  ## Usage ##
66
71
 
@@ -1,16 +1,16 @@
1
1
  # -*- encoding: utf-8 -*-
2
- if RUBY_VERSION == '1.8.7'
2
+ if RUBY_VERSION == "1.8.7"
3
3
  $:.unshift File.expand_path("../lib", __FILE__)
4
4
  require "em/version"
5
5
  else
6
6
  # Ruby 1.9.
7
- require File.expand_path('../lib/em/version', __FILE__)
7
+ require File.expand_path("../lib/em/version", __FILE__)
8
8
  end
9
9
 
10
10
  Gem::Specification.new do |s|
11
- s.name = 'eventmachine-le'
11
+ s.name = "eventmachine-le"
12
12
  s.version = EventMachine::VERSION
13
- s.homepage = 'https://github.com/ibc/EventMachine-LE/'
13
+ s.homepage = "https://github.com/ibc/EventMachine-LE/"
14
14
 
15
15
  s.authors = ["Francis Cianfrocca", "Aman Gupta", "hacked by Carsten Bormann and Inaki Baz Castillo"]
16
16
  s.email = ["garbagecat10@gmail.com", "aman@tmm1.net", "cabo@tzi.org", "ibc@aliax.net"]
@@ -19,11 +19,11 @@ Gem::Specification.new do |s|
19
19
  s.extensions = ["ext/extconf.rb", "ext/fastfilereader/extconf.rb"]
20
20
 
21
21
  s.required_ruby_version = ">= 1.8.7"
22
- s.add_development_dependency 'rake-compiler', '0.7.9'
23
- s.add_development_dependency 'yard', ">= 0.7.2"
24
- s.add_development_dependency 'bluecloth'
22
+ s.add_development_dependency "rake-compiler", ">= 0.7.9"
23
+ s.add_development_dependency "yard", ">= 0.7.2"
24
+ s.add_development_dependency "bluecloth"
25
25
 
26
- s.summary = 'EventMachine LE (Live Edition)'
26
+ s.summary = "EventMachine LE (Live Edition)"
27
27
  s.description = "EventMachine-LE (Live Edition) is a branch of EventMachine (https://github.com/eventmachine/eventmachine).
28
28
 
29
29
  This branch incorporates interesting pull requests that are not yet included in the mainline EventMachine repository. The maintainers of that version prefer to minimize change in order to keep the stability with already existing EventMachine deployments, which provides an impressive multi-platform base for IPv4 TCP servers (e.g., Web servers) that don't need good UDP or IPv6 support.
data/ext/cmain.cpp CHANGED
@@ -807,6 +807,35 @@ extern "C" void evma_stop_proxy (const unsigned long from)
807
807
  ed->StopProxy();
808
808
  }
809
809
 
810
+ /******************
811
+ evma_proxied_bytes
812
+ *******************/
813
+
814
+ extern "C" unsigned long evma_proxied_bytes (const unsigned long from)
815
+ {
816
+ ensure_eventmachine("evma_proxied_bytes");
817
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (from));
818
+ if (ed)
819
+ return ed->GetProxiedBytes();
820
+ else
821
+ return 0;
822
+ }
823
+
824
+
825
+ /***************************
826
+ evma_get_last_activity_time
827
+ ****************************/
828
+
829
+ extern "C" uint64_t evma_get_last_activity_time(const unsigned long from)
830
+ {
831
+ ensure_eventmachine("evma_get_last_activity_time");
832
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (from));
833
+ if (ed)
834
+ return ed->GetLastActivity();
835
+ else
836
+ return 0;
837
+ }
838
+
810
839
 
811
840
  /***************************
812
841
  evma_get_heartbeat_interval
data/ext/ed.cpp CHANGED
@@ -62,6 +62,7 @@ EventableDescriptor::EventableDescriptor (int sd, EventMachine_t *em, bool autoc
62
62
  UnbindReasonCode (0),
63
63
  ProxyTarget(NULL),
64
64
  ProxiedFrom(NULL),
65
+ ProxiedBytes(0),
65
66
  MaxOutboundBufSize(0),
66
67
  MyEventMachine (em),
67
68
  PendingConnectTimeout(20000000),
@@ -250,6 +251,7 @@ void EventableDescriptor::StartProxy(const unsigned long to, const unsigned long
250
251
  StopProxy();
251
252
  ProxyTarget = ed;
252
253
  BytesToProxy = length;
254
+ ProxiedBytes = 0;
253
255
  ed->SetProxiedFrom(this, bufsize);
254
256
  return;
255
257
  }
@@ -296,6 +298,7 @@ void EventableDescriptor::_GenericInboundDispatch(const char *buf, int size)
296
298
  if (BytesToProxy > 0) {
297
299
  unsigned long proxied = min(BytesToProxy, (unsigned long) size);
298
300
  ProxyTarget->SendOutboundData(buf, proxied);
301
+ ProxiedBytes += (unsigned long) proxied;
299
302
  BytesToProxy -= proxied;
300
303
  if (BytesToProxy == 0) {
301
304
  StopProxy();
@@ -306,6 +309,7 @@ void EventableDescriptor::_GenericInboundDispatch(const char *buf, int size)
306
309
  }
307
310
  } else {
308
311
  ProxyTarget->SendOutboundData(buf, size);
312
+ ProxiedBytes += (unsigned long) size;
309
313
  }
310
314
  } else {
311
315
  (*EventCallback)(GetBinding(), EM_CONNECTION_READ, buf, size);
data/ext/ed.h CHANGED
@@ -80,6 +80,7 @@ class EventableDescriptor: public Bindable_t
80
80
  virtual int SetCommInactivityTimeout (uint64_t value) {return 0;}
81
81
  uint64_t GetPendingConnectTimeout();
82
82
  int SetPendingConnectTimeout (uint64_t value);
83
+ uint64_t GetLastActivity() { return LastActivity; }
83
84
 
84
85
  #ifdef HAVE_EPOLL
85
86
  struct epoll_event *GetEpollEvent() { return &EpollEvent; }
@@ -87,6 +88,7 @@ class EventableDescriptor: public Bindable_t
87
88
 
88
89
  virtual void StartProxy(const unsigned long, const unsigned long, const unsigned long);
89
90
  virtual void StopProxy();
91
+ virtual unsigned long GetProxiedBytes(){ return ProxiedBytes; };
90
92
  virtual void SetProxiedFrom(EventableDescriptor*, const unsigned long);
91
93
  virtual int SendOutboundData(const char*,int){ return -1; }
92
94
  virtual bool IsPaused(){ return bPaused; }
@@ -118,6 +120,7 @@ class EventableDescriptor: public Bindable_t
118
120
  unsigned long BytesToProxy;
119
121
  EventableDescriptor *ProxyTarget;
120
122
  EventableDescriptor *ProxiedFrom;
123
+ unsigned long ProxiedBytes;
121
124
 
122
125
  unsigned long MaxOutboundBufSize;
123
126
 
data/ext/eventmachine.h CHANGED
@@ -89,6 +89,7 @@ extern "C" {
89
89
  float evma_get_pending_connect_timeout (const unsigned long binding);
90
90
  int evma_set_pending_connect_timeout (const unsigned long binding, float value);
91
91
  int evma_get_outbound_data_size (const unsigned long binding);
92
+ uint64_t evma_get_last_activity_time (const unsigned long);
92
93
  int evma_send_file_data_to_connection (const unsigned long binding, const char *filename);
93
94
 
94
95
  void evma_close_connection (const unsigned long binding, int after_writing);
@@ -110,6 +111,7 @@ extern "C" {
110
111
 
111
112
  void evma_start_proxy(const unsigned long, const unsigned long, const unsigned long, const unsigned long);
112
113
  void evma_stop_proxy(const unsigned long);
114
+ unsigned long evma_proxied_bytes(const unsigned long);
113
115
 
114
116
  int evma_set_rlimit_nofile (int n_files);
115
117
 
data/ext/rubymain.cpp CHANGED
@@ -613,7 +613,7 @@ static VALUE t_set_sock_opt (VALUE self, VALUE signature, VALUE lev, VALUE optna
613
613
  int fd = evma_get_file_descriptor (NUM2ULONG (signature));
614
614
  int level = NUM2INT(lev), option = NUM2INT(optname);
615
615
  int i;
616
- void *v;
616
+ const void *v;
617
617
  socklen_t len;
618
618
 
619
619
  switch (TYPE(optval)) {
@@ -1105,6 +1105,44 @@ static VALUE t_stop_proxy (VALUE self, VALUE from)
1105
1105
  return Qnil;
1106
1106
  }
1107
1107
 
1108
+ /***************
1109
+ t_proxied_bytes
1110
+ ****************/
1111
+
1112
+ static VALUE t_proxied_bytes (VALUE self, VALUE from)
1113
+ {
1114
+ try{
1115
+ return ULONG2NUM(evma_proxied_bytes(NUM2ULONG (from)));
1116
+ } catch (std::runtime_error e) {
1117
+ rb_raise (EM_eConnectionError, e.what());
1118
+ }
1119
+ return Qnil;
1120
+ }
1121
+
1122
+ /***************
1123
+ t_get_idle_time
1124
+ ****************/
1125
+
1126
+ static VALUE t_get_idle_time (VALUE self, VALUE from)
1127
+ {
1128
+ try{
1129
+ uint64_t current_time = evma_get_current_loop_time();
1130
+ uint64_t time = evma_get_last_activity_time(NUM2ULONG (from));
1131
+ if (current_time != 0 && time != 0) {
1132
+ if (time >= current_time)
1133
+ return ULONG2NUM(0);
1134
+ else {
1135
+ uint64_t diff = current_time - time;
1136
+ float seconds = diff / (1000.0*1000.0);
1137
+ return rb_float_new(seconds);
1138
+ }
1139
+ return Qnil;
1140
+ }
1141
+ } catch (std::runtime_error e) {
1142
+ rb_raise (EM_eConnectionError, e.what());
1143
+ }
1144
+ return Qnil;
1145
+ }
1108
1146
 
1109
1147
  /************************
1110
1148
  t_get_heartbeat_interval
@@ -1207,6 +1245,7 @@ extern "C" void Init_rubyeventmachine()
1207
1245
 
1208
1246
  rb_define_module_function (EmModule, "start_proxy", (VALUE (*)(...))t_start_proxy, 4);
1209
1247
  rb_define_module_function (EmModule, "stop_proxy", (VALUE (*)(...))t_stop_proxy, 1);
1248
+ rb_define_module_function (EmModule, "get_proxied_bytes", (VALUE (*)(...))t_proxied_bytes, 1);
1210
1249
 
1211
1250
  rb_define_module_function (EmModule, "watch_filename", (VALUE (*)(...))t_watch_filename, 1);
1212
1251
  rb_define_module_function (EmModule, "unwatch_filename", (VALUE (*)(...))t_unwatch_filename, 1);
@@ -1228,6 +1267,7 @@ extern "C" void Init_rubyeventmachine()
1228
1267
  rb_define_module_function (EmModule, "send_file_data", (VALUE(*)(...))t_send_file_data, 2);
1229
1268
  rb_define_module_function (EmModule, "get_heartbeat_interval", (VALUE(*)(...))t_get_heartbeat_interval, 0);
1230
1269
  rb_define_module_function (EmModule, "set_heartbeat_interval", (VALUE(*)(...))t_set_heartbeat_interval, 1);
1270
+ rb_define_module_function (EmModule, "get_idle_time", (VALUE(*)(...))t_get_idle_time, 1);
1231
1271
 
1232
1272
  rb_define_module_function (EmModule, "get_peername", (VALUE(*)(...))t_get_peername, 1);
1233
1273
  rb_define_module_function (EmModule, "get_sockname", (VALUE(*)(...))t_get_sockname, 1);
data/lib/em/connection.rb CHANGED
@@ -251,6 +251,12 @@ module EventMachine
251
251
  EventMachine::disable_proxy(self)
252
252
  end
253
253
 
254
+ # The number of bytes proxied to another connection. Reset to zero when
255
+ # EventMachine::Connection#proxy_incoming_to is called, and incremented whenever data is proxied.
256
+ def get_proxied_bytes
257
+ EventMachine::get_proxied_bytes(@signature)
258
+ end
259
+
254
260
  # EventMachine::Connection#close_connection is called only by user code, and never
255
261
  # by the event loop. You may call this method against a connection object in any
256
262
  # callback handler, whether or not the callback was made against the connection
@@ -583,6 +589,11 @@ module EventMachine
583
589
  EventMachine::get_subprocess_status @signature
584
590
  end
585
591
 
592
+ # The number of seconds since the last send/receive activity on this connection.
593
+ def get_idle_time
594
+ EventMachine::get_idle_time @signature
595
+ end
596
+
586
597
  # comm_inactivity_timeout returns the current value (float in seconds) of the inactivity-timeout
587
598
  # property of network-connection and datagram-socket objects. A nonzero value
588
599
  # indicates that the connection or socket will automatically be closed if no read or write
data/lib/em/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module EventMachine
2
- VERSION = "1.1.0.beta.1"
2
+ VERSION = "1.1.0.beta.2"
3
3
  end
@@ -0,0 +1,23 @@
1
+ require 'em_test_helper'
2
+
3
+ class TestIdleConnection < Test::Unit::TestCase
4
+ if EM.respond_to?(:get_idle_time)
5
+ def test_idle_time
6
+ EM.run{
7
+ conn = EM.connect 'www.google.com', 80
8
+ EM.add_timer(3){
9
+ $idle_time = conn.get_idle_time
10
+ conn.send_data "GET / HTTP/1.0\r\n\r\n"
11
+ EM.next_tick{
12
+ $idle_time_after_send = conn.get_idle_time
13
+ conn.close_connection
14
+ EM.stop
15
+ }
16
+ }
17
+ }
18
+
19
+ assert_in_delta 3, $idle_time, 0.2
20
+ assert_equal 0, $idle_time_after_send
21
+ end
22
+ end
23
+ end
@@ -24,6 +24,7 @@ class TestProxyConnection < Test::Unit::TestCase
24
24
  end
25
25
 
26
26
  def unbind
27
+ $proxied_bytes = self.get_proxied_bytes
27
28
  @client.close_connection_after_writing
28
29
  end
29
30
  end
@@ -94,7 +95,7 @@ class TestProxyConnection < Test::Unit::TestCase
94
95
  end
95
96
 
96
97
  def receive_data(data)
97
- EM.connect("127.0.0.1", @port, ProxyConnection, self, data)
98
+ @proxy = EM.connect("127.0.0.1", @port, ProxyConnection, self, data)
98
99
  end
99
100
  end
100
101
 
@@ -134,6 +135,17 @@ class TestProxyConnection < Test::Unit::TestCase
134
135
  assert_equal("I know!", $client_data)
135
136
  end
136
137
 
138
+ def test_proxied_bytes
139
+ EM.run {
140
+ EM.start_server("127.0.0.1", @port, Server)
141
+ EM.start_server("127.0.0.1", @proxy_port, ProxyServer, @port)
142
+ EM.connect("127.0.0.1", @proxy_port, Client)
143
+ }
144
+
145
+ assert_equal("I know!", $client_data)
146
+ assert_equal("I know!".bytesize, $proxied_bytes)
147
+ end
148
+
137
149
  def test_partial_proxy_connection
138
150
  EM.run {
139
151
  EM.start_server("127.0.0.1", @port, Server)
metadata CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
7
7
  - 1
8
8
  - 0
9
9
  - beta
10
- - 1
11
- version: 1.1.0.beta.1
10
+ - 2
11
+ version: 1.1.0.beta.2
12
12
  platform: ruby
13
13
  authors:
14
14
  - Francis Cianfrocca
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2012-03-04 00:00:00 +01:00
21
+ date: 2012-03-06 00:00:00 +01:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
@@ -27,7 +27,7 @@ dependencies:
27
27
  requirement: &id001 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
- - - "="
30
+ - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  segments:
33
33
  - 0
@@ -179,6 +179,7 @@ extra_rdoc_files:
179
179
  - tests/test_hc.rb
180
180
  - tests/test_httpclient.rb
181
181
  - tests/test_httpclient2.rb
182
+ - tests/test_idle_connection.rb
182
183
  - tests/test_inactivity_timeout.rb
183
184
  - tests/test_ipv4.rb
184
185
  - tests/test_ipv6.rb
@@ -308,6 +309,7 @@ files:
308
309
  - tests/test_hc.rb
309
310
  - tests/test_httpclient.rb
310
311
  - tests/test_httpclient2.rb
312
+ - tests/test_idle_connection.rb
311
313
  - tests/test_inactivity_timeout.rb
312
314
  - tests/test_ipv4.rb
313
315
  - tests/test_ipv6.rb