Skip to content

Commit

Permalink
require 'em/pure_ruby' explicitly to use the pure ruby reactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm1 committed Apr 13, 2010
1 parent 17569fb commit 6e36359
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 107 deletions.
7 changes: 1 addition & 6 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ require 'rake' unless defined?(Rake)
Package = false # Build zips and tarballs?
Dir.glob('tasks/*.rake').each { |r| Rake.application.add_import r }

# e.g. rake EVENTMACHINE_LIBRARY=java for forcing java build tasks as defaults!
$eventmachine_library = :java if RUBY_PLATFORM =~ /java/ || ENV['EVENTMACHINE_LIBRARY'] == 'java'
$eventmachine_library = :pure_ruby if ENV['EVENTMACHINE_LIBRARY'] == 'pure_ruby'

MAKE = ENV['MAKE'] || if RUBY_PLATFORM =~ /mswin/ # mingw uses make.
'nmake'
else
Expand All @@ -48,8 +44,7 @@ task :default => [:build, :test]

desc "Build extension (or EVENTMACHINE_LIBRARY) and place in lib"
build_task = 'ext:build'
build_task = 'java:build' if $eventmachine_library == :java
build_task = :dummy_build if $eventmachine_library == :pure_ruby
build_task = 'java:build' if RUBY_PLATFORM =~ /java/
task :build => build_task do |t|
Dir.glob('{ext,java/src,ext/fastfilereader}/*.{so,bundle,dll,jar}').each do |f|
mv f, "lib"
Expand Down
3 changes: 0 additions & 3 deletions lib/pr_eventmachine.rb → lib/em/pure_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@
require 'fcntl'
require 'set'


module EventMachine


class << self
# This is mostly useful for automated tests.
# Return a distinctive symbol so the caller knows whether he's dealing
Expand Down
75 changes: 6 additions & 69 deletions lib/eventmachine.rb
Original file line number Diff line number Diff line change
@@ -1,75 +1,12 @@
#--
#
# Author:: Francis Cianfrocca (gmail: blackhedd)
# Homepage:: http://rubyeventmachine.com
# Date:: 8 Apr 2006
#
# See EventMachine and EventMachine::Connection for documentation and
# usage examples.
#
#----------------------------------------------------------------------------
#
# Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
# Gmail: blackhedd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of either: 1) the GNU General Public License
# as published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version; or 2) Ruby's License.
#
# See the file COPYING for complete licensing information.
#
#---------------------------------------------------------------------------
#
#


#-- Select in a library based on a global variable.
# PROVISIONALLY commented out this whole mechanism which selects
# a pure-Ruby EM implementation if the extension is not available.
# I expect this will cause a lot of people's code to break, as it
# exposes misconfigurations and path problems that were masked up
# till now. The reason I'm disabling it is because the pure-Ruby
# code will have problems of its own, and it's not nearly as fast
# anyway. Suggested by a problem report from Moshe Litvin. 05Jun07.
#
# 05Dec07: Re-enabled the pure-ruby mechanism, but without the automatic
# fallback feature that tripped up Moshe Litvin. We shouldn't fail over to
# the pure Ruby version because it's possible that the user intended to
# run the extension but failed to do so because of a compilation or
# similar error. So we require either a global variable or an environment
# string be set in order to select the pure-Ruby version.
#


unless defined?($eventmachine_library)
$eventmachine_library = ENV['EVENTMACHINE_LIBRARY'] || :cascade
end
$eventmachine_library = $eventmachine_library.to_sym

case $eventmachine_library
when :pure_ruby
require 'pr_eventmachine'
when :extension
require 'rubyeventmachine'
when :java
if RUBY_PLATFORM =~ /java/
require 'java'
require 'jeventmachine'
else # :cascade
# This is the case that most user code will take.
# Prefer the extension if available.
else
begin
if RUBY_PLATFORM =~ /java/
require 'java'
require 'jeventmachine'
$eventmachine_library = :java
else
require 'rubyeventmachine'
$eventmachine_library = :extension
end
require 'rubyeventmachine'
rescue LoadError
warn "# EventMachine fell back to pure ruby mode" if $DEBUG
require 'pr_eventmachine'
$eventmachine_library = :pure_ruby
warn "Unable to load the EventMachine C extension; To use the pure-ruby reactor, require 'em/pure_ruby'"
raise
end
end

Expand Down
29 changes: 0 additions & 29 deletions tests/test_basic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,6 @@ def test_connection_class_cache
assert_kind_of EM::Connection, a
end

def test_libtype
lt = EventMachine.library_type
em_lib = (ENV["EVENTMACHINE_LIBRARY"] || $eventmachine_library || :xxx).to_sym

# Running from test runner, under jruby.
if RUBY_PLATFORM == 'java'
unless em_lib == :pure_ruby
assert_equal( :java, lt )
return
end
end

case em_lib
when :pure_ruby
assert_equal( :pure_ruby, lt )
when :extension
assert_equal( :extension, lt )
when :java
assert_equal( :java, lt )
else
# Running from jruby as a standalone test.
if RUBY_PLATFORM == 'java'
assert_equal( :java, lt )
else
assert_equal( :extension, lt )
end
end
end

#-------------------------------------


Expand Down

0 comments on commit 6e36359

Please sign in to comment.