diff --git a/ext/mysql2/client.c b/ext/mysql2/client.c index 5bb0fee..68c3efc 100644 --- a/ext/mysql2/client.c +++ b/ext/mysql2/client.c @@ -140,6 +140,7 @@ static VALUE nogvl_close(void * ptr) { mysql_client_wrapper *wrapper = ptr; if (!wrapper->closed) { mysql_close(wrapper->client); + wrapper->client->net.fd = -1; wrapper->closed = 1; } return Qnil; diff --git a/lib/mysql2/em.rb b/lib/mysql2/em.rb index 6d95549..98da1e6 100644 --- a/lib/mysql2/em.rb +++ b/lib/mysql2/em.rb @@ -13,12 +13,12 @@ module Mysql2 end def notify_readable + detach begin @deferable.succeed(@client.async_result) rescue Exception => e @deferable.fail(e) end - detach end end diff --git a/spec/em/em_spec.rb b/spec/em/em_spec.rb index ac4f65b..1254c4c 100644 --- a/spec/em/em_spec.rb +++ b/spec/em/em_spec.rb @@ -7,7 +7,7 @@ describe Mysql2::EM::Client do results = [] EM.run do client1 = Mysql2::EM::Client.new - defer1 = client1.query "SELECT sleep(0.05) as first_query" + defer1 = client1.query "SELECT sleep(0.1) as first_query" defer1.callback do |result| results << result.first EM.stop_event_loop @@ -19,8 +19,27 @@ describe Mysql2::EM::Client do results << result.first end end - + results[0].keys.should include("second_query") results[1].keys.should include("first_query") end + + it "should support queries in callbacks" do + results = [] + EM.run do + client = Mysql2::EM::Client.new + defer1 = client.query "SELECT sleep(0.025) as first_query" + defer1.callback do |result| + results << result.first + defer2 = client.query "SELECT sleep(0.025) as second_query" + defer2.callback do |result| + results << result.first + EM.stop_event_loop + end + end + end + + results[0].keys.should include("first_query") + results[1].keys.should include("second_query") + end end diff --git a/tasks/compile.rake b/tasks/compile.rake index 4dae1b2..d46766c 100644 --- a/tasks/compile.rake +++ b/tasks/compile.rake @@ -1,9 +1,8 @@ gem 'rake-compiler', '~> 0.7.1' require "rake/extensiontask" -MYSQL_VERSION = "5.1.50" -MYSQL_MIRROR = ENV['MYSQL_MIRROR'] || "http://mysql.mirrors.pair.com" - +MYSQL_VERSION = "5.1.51" +MYSQL_MIRROR = ENV['MYSQL_MIRROR'] || "http://mysql.he.net/" def gemspec @clean_gemspec ||= eval(File.read(File.expand_path('../../mysql2.gemspec', __FILE__))) @@ -13,15 +12,24 @@ Rake::ExtensionTask.new("mysql2", gemspec) do |ext| # reference where the vendored MySQL got extracted mysql_lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'vendor', "mysql-#{MYSQL_VERSION}-win32")) + # DRY options feed into compile or cross-compile process + windows_options = [ + "--with-mysql-include=#{mysql_lib}/include", + "--with-mysql-lib=#{mysql_lib}/lib/opt" + ] + # automatically add build options to avoid need of manual input if RUBY_PLATFORM =~ /mswin|mingw/ then - ext.config_options << "--with-mysql-include=#{mysql_lib}/include" - ext.config_options << "--with-mysql-lib=#{mysql_lib}/lib/opt" + ext.config_options = windows_options else ext.cross_compile = true ext.cross_platform = ['x86-mingw32', 'x86-mswin32-60'] - ext.cross_config_options << "--with-mysql-include=#{mysql_lib}/include" - ext.cross_config_options << "--with-mysql-lib=#{mysql_lib}/lib/opt" + ext.cross_config_options = windows_options + + # inject 1.8/1.9 pure-ruby entry point when cross compiling only + ext.cross_compiling do |spec| + spec.files << 'lib/mysql2/mysql2.rb' + end end ext.lib_dir = File.join 'lib', 'mysql2' @@ -31,25 +39,16 @@ Rake::ExtensionTask.new("mysql2", gemspec) do |ext| end Rake::Task[:spec].prerequisites << :compile -namespace :cross do - task :file_list do - gemspec.extensions = [] - gemspec.files += Dir["lib/#{gemspec.name}/#{gemspec.name}.rb"] - gemspec.files += Dir["lib/#{gemspec.name}/1.{8,9}/#{gemspec.name}.so"] - # gemspec.files += Dir["ext/mysql2/*.dll"] - end -end - -file 'lib/mysql2/mysql2.rb' do +file 'lib/mysql2/mysql2.rb' do |t| name = gemspec.name - File.open("lib/#{name}/#{name}.rb", 'wb') do |f| + File.open(t.name, 'wb') do |f| f.write <<-eoruby -require "#{name}/\#{RUBY_VERSION.sub(/\\.\\d+$/, '')}/#{name}" +RUBY_VERSION =~ /(\\d+.\\d+)/ +require "#{name}/\#{$1}/#{name}" eoruby end end if Rake::Task.task_defined?(:cross) Rake::Task[:cross].prerequisites << "lib/mysql2/mysql2.rb" - Rake::Task[:cross].prerequisites << "cross:file_list" end