From ac3fa5df1d309e903d66739abd95b0bcbe8e537d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Caro?= Date: Wed, 14 Aug 2013 19:13:20 +0200 Subject: [PATCH 1/3] Make socket classes configurable --- lib/mysql.rb | 14 ++++++++++++++ lib/mysql/protocol.rb | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/mysql.rb b/lib/mysql.rb index 4aa788c..8d80283 100644 --- a/lib/mysql.rb +++ b/lib/mysql.rb @@ -21,6 +21,20 @@ class Mysql rescue LoadError end + ## + # Make socket classes configurable, so we can be compatible + # with amazing Celluloid::IO (https://github.com/celluloid/celluloid-io) + # + @@tcpsocket_class = TCPSocket + def tcpsocket_class; @@tcpsocket_class end + def tcpsocket_class=(value); @@tcpsocket_class = value end + + @@unixsocket_class = UNIXSocket + def unixsocket_class; @@unixsocket_class end + def unixsocket_class=(value); @@unixsocket_class = value end + # + ## + VERSION = 20911 # Version number of this library MYSQL_UNIX_PORT = "/tmp/mysql.sock" # UNIX domain socket filename MYSQL_TCP_PORT = 3306 # TCP socket port number diff --git a/lib/mysql/protocol.rb b/lib/mysql/protocol.rb index 2db1011..ffce035 100644 --- a/lib/mysql/protocol.rb +++ b/lib/mysql/protocol.rb @@ -168,10 +168,10 @@ def initialize(host, port, socket, conn_timeout, read_timeout, write_timeout) Timeout.timeout conn_timeout do if host.nil? or host.empty? or host == "localhost" socket ||= ENV["MYSQL_UNIX_PORT"] || MYSQL_UNIX_PORT - @sock = UNIXSocket.new socket + @sock = Mysql.unixsocket_class.new socket else port ||= ENV["MYSQL_TCP_PORT"] || (Socket.getservbyname("mysql","tcp") rescue MYSQL_TCP_PORT) - @sock = TCPSocket.new host, port + @sock = Mysql.tcpsocket_class.new host, port end end rescue Timeout::Error From 2fec6d560c03a18ccce12dccd25ec73559282dd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Caro?= Date: Wed, 14 Aug 2013 19:27:30 +0200 Subject: [PATCH 2/3] Add celluloid docs to readme --- README.rdoc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.rdoc b/README.rdoc index d571a9d..0c3ca12 100644 --- a/README.rdoc +++ b/README.rdoc @@ -31,6 +31,14 @@ MySQL connector for Ruby. stmt = my.prepare('insert into tblname (col1,col2) values (?,?)') stmt.execute 123, 'abc' +== Use with {Celluloid::IO}[https://github.com/celluloid/celluloid-io] + +You just need to override Mysql default socket classes with +Celluloid's ones. Then use it as you normally do. + + Mysql.unixsocket_class = Celluloid::IO::UNIXSocket + Mysql.tcpsocket_class = Celluloid::IO::TCPSocket + == Incompatible with MySQL/Ruby 2.8.x * Ruby 1.8.x ではシフトJISのような安全でないマルチバイト文字セットに対して Mysql#escape_string を使用すると例外が発生します。 From bd910c3312d9c26820ef1104e2a04508f8ea0e88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Caro?= Date: Wed, 14 Aug 2013 19:38:37 +0200 Subject: [PATCH 3/3] Fix accessors for socket classes --- lib/mysql.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/mysql.rb b/lib/mysql.rb index 8d80283..ad268d5 100644 --- a/lib/mysql.rb +++ b/lib/mysql.rb @@ -26,12 +26,12 @@ class Mysql # with amazing Celluloid::IO (https://github.com/celluloid/celluloid-io) # @@tcpsocket_class = TCPSocket - def tcpsocket_class; @@tcpsocket_class end - def tcpsocket_class=(value); @@tcpsocket_class = value end + def self.tcpsocket_class; @@tcpsocket_class end + def self.tcpsocket_class=(value); @@tcpsocket_class = value end @@unixsocket_class = UNIXSocket - def unixsocket_class; @@unixsocket_class end - def unixsocket_class=(value); @@unixsocket_class = value end + def self.unixsocket_class; @@unixsocket_class end + def self.unixsocket_class=(value); @@unixsocket_class = value end # ##