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;
|
||||
char connection;
|
||||
char query_with_result;
|
||||
char blocking;
|
||||
};
|
||||
|
||||
struct mysql_res {
|
||||
@ -268,6 +269,11 @@ static VALUE real_connect(int argc, VALUE* argv, VALUE klass)
|
||||
|
||||
myp->handler.reconnect = 0;
|
||||
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;
|
||||
rb_obj_call_init(obj, argc, argv);
|
||||
|
||||
@ -756,6 +762,11 @@ static VALUE socket(VALUE obj)
|
||||
return INT2NUM(m->net.fd);
|
||||
}
|
||||
|
||||
/* blocking */
|
||||
static VALUE blocking(VALUE obj){
|
||||
return ( GetMysqlStruct(obj)->blocking ? Qtrue : Qfalse );
|
||||
}
|
||||
|
||||
/* readable(timeout=nil) */
|
||||
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, "get_result", get_result, 0);
|
||||
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, "refresh", refresh, 1);
|
||||
rb_define_method(cMysql, "reload", reload, 0);
|
||||
|
@ -1,10 +1,12 @@
|
||||
require 'mysql'
|
||||
|
||||
class Mysql
|
||||
|
||||
alias_method :c_async_query, :async_query
|
||||
|
||||
def async_query(sql, timeout = nil)
|
||||
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)
|
||||
select [ (@sockets ||= {})[socket] ||= IO.new(socket) ], nil, nil, nil
|
||||
get_result
|
||||
|
@ -2,6 +2,7 @@ require File.dirname(__FILE__) + '/test_helper'
|
||||
|
||||
EventedMysqlTest.new( 10 ) do |test|
|
||||
test.setup{ Mysql.real_connect('localhost','root') }
|
||||
test.log_blocking_status = true
|
||||
test.run!
|
||||
end
|
||||
|
||||
|
@ -11,7 +11,8 @@ class MysqlTest
|
||||
:connection_signature,
|
||||
:start,
|
||||
:done,
|
||||
:c_async_query
|
||||
:c_async_query,
|
||||
:log_blocking_status
|
||||
|
||||
def initialize( queries )
|
||||
@queries = queries
|
||||
@ -27,10 +28,12 @@ class MysqlTest
|
||||
|
||||
def run!
|
||||
c_or_native_ruby_async_query do
|
||||
with_blocking_status do
|
||||
prepare
|
||||
yield
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def prepare
|
||||
raise NotImplemented
|
||||
@ -67,6 +70,15 @@ class MysqlTest
|
||||
yield
|
||||
end
|
||||
|
||||
def with_blocking_status
|
||||
if @log_blocking_status
|
||||
ENV['MYSQL_BLOCKING_STATUS'] = '1'
|
||||
else
|
||||
ENV['MYSQL_BLOCKING_STATUS'] = '0'
|
||||
end
|
||||
yield
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class EventedMysqlTest < MysqlTest
|
||||
|
@ -2,6 +2,7 @@ require File.dirname(__FILE__) + '/test_helper'
|
||||
|
||||
ThreadedMysqlTest.new( 10 ) do |test|
|
||||
test.setup{ Mysql.real_connect('localhost','root') }
|
||||
test.log_blocking_status = true
|
||||
test.run!
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user