Merge branch 'master' into stmt

* master:
  Detach before executing callbacks.
  make sure we don't hit a race condition if this EM spec is taking longer to run than normal
  was in a hurry earlier
  whoops, lost this line in a previous patch
  Dry windows configuration options
  Inject 1.8/1.9 pure-ruby entry point during xcompile
  Use MySQL 5.1.51 now from available mirror
This commit is contained in:
Brian Lopez 2010-10-05 17:14:45 -07:00
commit 7b6d210c97
4 changed files with 42 additions and 23 deletions

View File

@ -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;

View File

@ -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

View File

@ -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
@ -23,4 +23,23 @@ describe Mysql2::EM::Client do
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

View File

@ -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