allow access to file descriptor in C, EventMachine anyone? ;)

This commit is contained in:
Brian Lopez 2010-04-04 23:31:32 -07:00
parent c81bc8c6e9
commit 9b59478cf6
3 changed files with 16 additions and 0 deletions

View File

@ -166,6 +166,11 @@ static VALUE rb_mysql_client_server_info(VALUE self) {
return version;
}
static VALUE rb_mysql_client_socket(VALUE self) {
MYSQL * client = GetMysql2Client(self, client);;
return INT2NUM(client->net.fd);
}
/* Mysql2::Result */
static VALUE rb_mysql_result_to_obj(MYSQL_RES * r) {
VALUE obj;
@ -361,6 +366,7 @@ void Init_mysql2_ext() {
rb_define_method(cMysql2Client, "escape", rb_mysql_client_escape, 1);
rb_define_method(cMysql2Client, "info", rb_mysql_client_info, 0);
rb_define_method(cMysql2Client, "server_info", rb_mysql_client_server_info, 0);
rb_define_method(cMysql2Client, "socket", rb_mysql_client_socket, 0);
cMysql2Result = rb_define_class_under(mMysql2, "Result", rb_cObject);
rb_define_method(cMysql2Result, "each", rb_mysql_result_each, -1);

View File

@ -24,6 +24,7 @@ static VALUE rb_mysql_client_query(VALUE self, VALUE query);
static VALUE rb_mysql_client_escape(VALUE self, VALUE str);
static VALUE rb_mysql_client_info(VALUE self);
static VALUE rb_mysql_client_server_info(VALUE self);
static VALUE rb_mysql_client_socket(VALUE self);
void rb_mysql_client_free(void * client);
/* Mysql2::Result */

View File

@ -48,4 +48,13 @@ describe Mysql2::Client do
server_info.should have_key(:version)
server_info[:version].class.should eql(String)
end
it "should respond to #socket" do
@client.should respond_to :socket
end
it "#socket should return a Fixnum (file descriptor from C)" do
@client.socket.class.should eql(Fixnum)
@client.socket.should_not eql(0)
end
end