Skip to content

Commit

Permalink
handle EM_CONNECTION_COMPLETED in C so we dont go to ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
jakedouglas committed Oct 31, 2009
1 parent e50ea52 commit fc79ff8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions ext/rubymain.cpp
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions lib/eventmachine.rb
Expand Up @@ -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
Expand Down

0 comments on commit fc79ff8

Please sign in to comment.