Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'close_schedule_fix'

* close_schedule_fix:
  Expose EM.num_close_scheduled, and utilise in TimeTilNextEvent to avoid long waits for unbinds.
  • Loading branch information...
commit 8cd81fb384e46cbe8521e82f10ce3bda01405998 2 parents 86bb981 + 2cd0c19
@raggi raggi authored
View
9 ext/cmain.cpp
@@ -253,6 +253,15 @@ extern "C" int evma_is_paused (const unsigned long binding)
return 0;
}
+/************************
+evma_num_close_scheduled
+************************/
+
+extern "C" int evma_num_close_scheduled ()
+{
+ return EventMachine->NumCloseScheduled;
+}
+
/**********************
evma_create_tcp_server
**********************/
View
2  ext/ed.cpp
@@ -115,6 +115,7 @@ EventableDescriptor::~EventableDescriptor()
(*EventCallback)(ProxiedFrom->GetBinding(), EM_PROXY_TARGET_UNBOUND, NULL, 0);
ProxiedFrom->StopProxy();
}
+ MyEventMachine->NumCloseScheduled--;
StopProxy();
Close();
}
@@ -214,6 +215,7 @@ EventableDescriptor::ScheduleClose
void EventableDescriptor::ScheduleClose (bool after_writing)
{
+ MyEventMachine->NumCloseScheduled++;
// KEEP THIS SYNCHRONIZED WITH ::IsCloseScheduled.
if (after_writing)
bCloseAfterWriting = true;
View
5 ext/em.cpp
@@ -73,6 +73,7 @@ EventMachine_t::EventMachine_t (EMCallback event_callback):
NextHeartbeatTime (0),
LoopBreakerReader (-1),
LoopBreakerWriter (-1),
+ NumCloseScheduled (0),
bTerminateSignalReceived (false),
bEpoll (false),
epfd (-1),
@@ -689,10 +690,10 @@ timeval EventMachine_t::_TimeTilNextEvent()
if (!NewDescriptors.empty() || !ModifiedDescriptors.empty()) {
next_event = MyCurrentLoopTime;
}
-
+
timeval tv;
- if (next_event == 0) {
+ if (next_event == 0 || NumCloseScheduled > 0) {
tv = Quantum;
} else {
if (next_event > MyCurrentLoopTime) {
View
1  ext/em.h
@@ -161,6 +161,7 @@ class EventMachine_t
public:
void _ReadLoopBreaker();
void _ReadInotifyEvents();
+ int NumCloseScheduled;
private:
enum {
View
2  ext/eventmachine.h
@@ -59,6 +59,8 @@ extern "C" {
int evma_is_paused(const unsigned long binding);
int evma_resume(const unsigned long binding);
+ int evma_num_close_scheduled();
+
void evma_stop_tcp_server (const unsigned long signature);
const unsigned long evma_create_tcp_server (const char *address, int port);
const unsigned long evma_create_unix_domain_server (const char *filename);
View
10 ext/rubymain.cpp
@@ -686,6 +686,15 @@ static VALUE t_paused_p (VALUE self, VALUE signature)
return evma_is_paused(NUM2ULONG (signature)) ? Qtrue : Qfalse;
}
+/*********************
+t_num_close_scheduled
+*********************/
+
+static VALUE t_num_close_scheduled (VALUE self)
+{
+ return INT2FIX(evma_num_close_scheduled());
+}
+
/*****************
t_open_udp_socket
*****************/
@@ -1180,6 +1189,7 @@ extern "C" void Init_rubyeventmachine()
rb_define_module_function (EmModule, "pause_connection", (VALUE (*)(...))t_pause, 1);
rb_define_module_function (EmModule, "resume_connection", (VALUE (*)(...))t_resume, 1);
rb_define_module_function (EmModule, "connection_paused?", (VALUE (*)(...))t_paused_p, 1);
+ rb_define_module_function (EmModule, "num_close_scheduled", (VALUE (*)(...))t_num_close_scheduled, 0);
rb_define_module_function (EmModule, "start_proxy", (VALUE (*)(...))t_start_proxy, 4);
rb_define_module_function (EmModule, "stop_proxy", (VALUE (*)(...))t_stop_proxy, 1);
View
21 tests/test_basic.rb
@@ -224,4 +224,25 @@ def test_bubble_errors_from_initialize
end
end
end
+
+ def test_schedule_close
+ localhost, port = '127.0.0.1', 9000
+ timer_ran = false
+ num_close_scheduled = nil
+ EM.run do
+ assert_equal 0, EM.num_close_scheduled
+ EM.add_timer(1) { timer_ran = true; EM.stop }
+ EM.start_server localhost, port do |s|
+ s.close_connection
+ num_close_scheduled = EM.num_close_scheduled
+ end
+ EM.connect localhost, port do |c|
+ def c.unbind
+ EM.stop
+ end
+ end
+ end
+ assert !timer_ran
+ assert_equal 1, num_close_scheduled
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.