Skip to content
Browse files

Use EM.watch in favor of IO/blocking hacks

  • Loading branch information...
1 parent cdd1648 commit 6f63519d75fddd109261a65a2d75bb0cad2a60bd @tmm1 committed Aug 24, 2009
Showing with 9 additions and 21 deletions.
  1. +2 −2 em-mysql.gemspec
  2. +7 −19 lib/em/mysql.rb
View
4 em-mysql.gemspec
@@ -1,14 +1,14 @@
spec = Gem::Specification.new do |s|
s.name = 'em-mysql'
- s.version = '0.3.0'
+ s.version = '0.4.0'
s.date = '2009-06-23'
s.summary = 'Async MySQL client API for Ruby/EventMachine'
s.email = "em-mysql@tmm1.net"
s.homepage = "http://github.com/tmm1/em-mysql"
s.description = 'Async MySQL client API for Ruby/EventMachine'
s.has_rdoc = false
s.authors = ["Aman Gupta"]
- s.add_dependency('eventmachine', '>= 0.12.8')
+ s.add_dependency('eventmachine', '>= 0.12.9')
# git ls-files
s.files = %w[
View
26 lib/em/mysql.rb
@@ -20,7 +20,8 @@ def initialize mysql, opts
@connected = true
log 'mysql connected'
- make_socket_blocking
+
+ self.notify_readable = true
EM.add_timer(0){ next_query }
end
attr_reader :processing, :connected, :opts
@@ -109,7 +110,8 @@ def unbind
@mysql = EventedMysql._connect @opts
@fd = @mysql.socket
- @signature = EM.attach_fd @mysql.socket, true, false
+ @signature = EM.attach_fd @mysql.socket, true
+ EM.set_notify_readable @signature, true
log 'mysql connected'
EM.instance_variable_get('@conns')[@signature] = self
@connected = true
@@ -157,25 +159,11 @@ def execute sql, response = nil, cblk = nil, eblk = nil, &blk
def close
@connected = false
- # @mysql.close
- # IO.pipe
- # EM.add_timer(0){ close_connection }
- # close_connection
fd = detach
- @io.close if @io
- @io = nil
log 'detached fd', fd
end
private
-
- def make_socket_blocking
- if defined?(Fcntl::F_GETFL)
- @io = IO.for_fd(@mysql.socket)
- m = @io.fcntl(Fcntl::F_GETFL, 0)
- @io.fcntl(Fcntl::F_SETFL, ~Fcntl::O_NONBLOCK & m)
- end
- end
def next_query
if @connected and !@processing and pending = @@queue.shift
@@ -192,12 +180,12 @@ def log *args
public
def self.connect opts
- unless EM.respond_to?(:attach) and Mysql.method_defined?(:socket)
- raise RuntimeError, 'mysqlplus and EM.attach are required for EventedMysql'
+ unless EM.respond_to?(:watch) and Mysql.method_defined?(:socket)
+ raise RuntimeError, 'mysqlplus and EM.watch are required for EventedMysql'
end
if conn = _connect(opts)
- EM.attach conn.socket, self, conn, opts
+ EM.watch conn.socket, self, conn, opts
else
EM.add_timer(5){ connect opts }
end

0 comments on commit 6f63519

Please sign in to comment.
Something went wrong with that request. Please try again.