From fc79ff81894f9602d0ce20789c91b721cb832e10 Mon Sep 17 00:00:00 2001 From: Jake Douglas Date: Fri, 30 Oct 2009 21:32:30 -0700 Subject: [PATCH] handle EM_CONNECTION_COMPLETED in C so we dont go to ruby --- ext/rubymain.cpp | 8 ++++++++ lib/eventmachine.rb | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ext/rubymain.cpp b/ext/rubymain.cpp index c2360860f..320514621 100644 --- a/ext/rubymain.cpp +++ b/ext/rubymain.cpp @@ -53,6 +53,7 @@ static VALUE Intern_ssl_verify_peer; static VALUE Intern_notify_readable; static VALUE Intern_notify_writable; static VALUE Intern_proxy_target_unbound; +static VALUE Intern_connection_completed; static VALUE rb_cProcStatus; @@ -105,6 +106,12 @@ static void event_callback (struct em_event* e) rb_funcall (timer, Intern_call, 0); } } + else if (event == EM_CONNECTION_COMPLETED) { + VALUE conn = rb_hash_aref (EmConnsHash, ULONG2NUM (signature)); + if (conn == Qnil) + rb_raise (EM_eConnectionNotBound, "unknown connection: %lu", signature); + rb_funcall (conn, Intern_connection_completed, 0); + } #ifdef WITH_SSL else if (event == EM_SSL_HANDSHAKE_COMPLETED) { VALUE conn = rb_hash_aref (EmConnsHash, ULONG2NUM (signature)); @@ -1053,6 +1060,7 @@ extern "C" void Init_rubyeventmachine() Intern_notify_readable = rb_intern ("notify_readable"); Intern_notify_writable = rb_intern ("notify_writable"); Intern_proxy_target_unbound = rb_intern ("proxy_target_unbound"); + Intern_connection_completed = rb_intern ("connection_completed"); // INCOMPLETE, we need to define class Connections inside module EventMachine // run_machine and run_machine_without_threads are now identical. diff --git a/lib/eventmachine.rb b/lib/eventmachine.rb index 410609671..cb3b14c9e 100644 --- a/lib/eventmachine.rb +++ b/lib/eventmachine.rb @@ -1431,12 +1431,12 @@ def self.event_callback conn_binding, opcode, data # :nodoc: @conns[data] = c blk and blk.call(c) c # (needed?) - elsif opcode == ConnectionCompleted - c = @conns[conn_binding] or raise ConnectionNotBound, "received ConnectionCompleted for unknown signature: #{conn_binding}" - c.connection_completed ## # The remaining code is a fallback for the pure ruby and java reactors. # In the C++ reactor, these events are handled in the C event_callback() in rubymain.cpp + elsif opcode == ConnectionCompleted + c = @conns[conn_binding] or raise ConnectionNotBound, "received ConnectionCompleted for unknown signature: #{conn_binding}" + c.connection_completed elsif opcode == TimerFired t = @timers.delete( data ) return if t == false # timer cancelled