Introduce Mysql#blocking?; Set the file drescriptor for all new connections to non blocking; Add tests to the existing evented and threaded runs. ( verified 1.8 && 1.9 )
This commit is contained in:
parent
26202b3ddb
commit
55411cd9d4
12
ext/mysql.c
12
ext/mysql.c
@ -60,6 +60,7 @@ struct mysql {
|
|||||||
MYSQL handler;
|
MYSQL handler;
|
||||||
char connection;
|
char connection;
|
||||||
char query_with_result;
|
char query_with_result;
|
||||||
|
char blocking;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mysql_res {
|
struct mysql_res {
|
||||||
@ -268,6 +269,11 @@ static VALUE real_connect(int argc, VALUE* argv, VALUE klass)
|
|||||||
|
|
||||||
myp->handler.reconnect = 0;
|
myp->handler.reconnect = 0;
|
||||||
myp->connection = Qtrue;
|
myp->connection = Qtrue;
|
||||||
|
|
||||||
|
my_bool was_blocking;
|
||||||
|
vio_blocking(myp->handler.net.vio, 0, &was_blocking);
|
||||||
|
myp->blocking = vio_is_blocking( myp->handler.net.vio );
|
||||||
|
|
||||||
myp->query_with_result = Qtrue;
|
myp->query_with_result = Qtrue;
|
||||||
rb_obj_call_init(obj, argc, argv);
|
rb_obj_call_init(obj, argc, argv);
|
||||||
|
|
||||||
@ -756,6 +762,11 @@ static VALUE socket(VALUE obj)
|
|||||||
return INT2NUM(m->net.fd);
|
return INT2NUM(m->net.fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* blocking */
|
||||||
|
static VALUE blocking(VALUE obj){
|
||||||
|
return ( GetMysqlStruct(obj)->blocking ? Qtrue : Qfalse );
|
||||||
|
}
|
||||||
|
|
||||||
/* readable(timeout=nil) */
|
/* readable(timeout=nil) */
|
||||||
static VALUE readable( int argc, VALUE* argv, VALUE obj )
|
static VALUE readable( int argc, VALUE* argv, VALUE obj )
|
||||||
{
|
{
|
||||||
@ -2113,6 +2124,7 @@ void Init_mysql(void)
|
|||||||
rb_define_method(cMysql, "send_query", send_query, 1);
|
rb_define_method(cMysql, "send_query", send_query, 1);
|
||||||
rb_define_method(cMysql, "get_result", get_result, 0);
|
rb_define_method(cMysql, "get_result", get_result, 0);
|
||||||
rb_define_method(cMysql, "readable?", readable, -1);
|
rb_define_method(cMysql, "readable?", readable, -1);
|
||||||
|
rb_define_method(cMysql, "blocking?", blocking, 0);
|
||||||
rb_define_method(cMysql, "socket", socket, 0);
|
rb_define_method(cMysql, "socket", socket, 0);
|
||||||
rb_define_method(cMysql, "refresh", refresh, 1);
|
rb_define_method(cMysql, "refresh", refresh, 1);
|
||||||
rb_define_method(cMysql, "reload", reload, 0);
|
rb_define_method(cMysql, "reload", reload, 0);
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
require 'mysql'
|
require 'mysql'
|
||||||
|
|
||||||
class Mysql
|
class Mysql
|
||||||
|
|
||||||
alias_method :c_async_query, :async_query
|
alias_method :c_async_query, :async_query
|
||||||
|
|
||||||
def async_query(sql, timeout = nil)
|
def async_query(sql, timeout = nil)
|
||||||
c_async_query(sql, timeout) if ENV['MYSQL_C_ASYNC_QUERY'] == '1'
|
c_async_query(sql, timeout) if ENV['MYSQL_C_ASYNC_QUERY'] == '1'
|
||||||
|
puts "** Blocking ? #{blocking?().inspect}" if ENV['MYSQL_BLOCKING_STATUS'] == '1'
|
||||||
send_query(sql)
|
send_query(sql)
|
||||||
select [ (@sockets ||= {})[socket] ||= IO.new(socket) ], nil, nil, nil
|
select [ (@sockets ||= {})[socket] ||= IO.new(socket) ], nil, nil, nil
|
||||||
get_result
|
get_result
|
||||||
|
@ -2,6 +2,7 @@ require File.dirname(__FILE__) + '/test_helper'
|
|||||||
|
|
||||||
EventedMysqlTest.new( 10 ) do |test|
|
EventedMysqlTest.new( 10 ) do |test|
|
||||||
test.setup{ Mysql.real_connect('localhost','root') }
|
test.setup{ Mysql.real_connect('localhost','root') }
|
||||||
|
test.log_blocking_status = true
|
||||||
test.run!
|
test.run!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -11,7 +11,8 @@ class MysqlTest
|
|||||||
:connection_signature,
|
:connection_signature,
|
||||||
:start,
|
:start,
|
||||||
:done,
|
:done,
|
||||||
:c_async_query
|
:c_async_query,
|
||||||
|
:log_blocking_status
|
||||||
|
|
||||||
def initialize( queries )
|
def initialize( queries )
|
||||||
@queries = queries
|
@queries = queries
|
||||||
@ -27,8 +28,10 @@ class MysqlTest
|
|||||||
|
|
||||||
def run!
|
def run!
|
||||||
c_or_native_ruby_async_query do
|
c_or_native_ruby_async_query do
|
||||||
prepare
|
with_blocking_status do
|
||||||
yield
|
prepare
|
||||||
|
yield
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -67,6 +70,15 @@ class MysqlTest
|
|||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def with_blocking_status
|
||||||
|
if @log_blocking_status
|
||||||
|
ENV['MYSQL_BLOCKING_STATUS'] = '1'
|
||||||
|
else
|
||||||
|
ENV['MYSQL_BLOCKING_STATUS'] = '0'
|
||||||
|
end
|
||||||
|
yield
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class EventedMysqlTest < MysqlTest
|
class EventedMysqlTest < MysqlTest
|
||||||
|
@ -2,6 +2,7 @@ require File.dirname(__FILE__) + '/test_helper'
|
|||||||
|
|
||||||
ThreadedMysqlTest.new( 10 ) do |test|
|
ThreadedMysqlTest.new( 10 ) do |test|
|
||||||
test.setup{ Mysql.real_connect('localhost','root') }
|
test.setup{ Mysql.real_connect('localhost','root') }
|
||||||
|
test.log_blocking_status = true
|
||||||
test.run!
|
test.run!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user