Permalink
Browse files

connection pool should proxy "send" calls to objects, closes #110

  • Loading branch information...
1 parent f27df2e commit 0d176e900c589d1a8a04429bc91594cd842c3ec7 @igrigorik committed Feb 18, 2012
Showing with 14 additions and 2 deletions.
  1. +3 −1 lib/em-synchrony/connection_pool.rb
  2. +1 −1 lib/em-synchrony/tcpsocket.rb
  3. +10 −0 spec/tcpsocket_spec.rb
View
4 lib/em-synchrony/connection_pool.rb
@@ -2,6 +2,8 @@ module EventMachine
module Synchrony
class ConnectionPool
+ undef :send
+
def initialize(opts, &block)
@reserved = {} # map of in-progress connections
@available = [] # pool of free connections
@@ -65,7 +67,7 @@ def method_missing(method, *args, &blk)
async = (method[0,1] == "a")
execute(async) do |conn|
- df = conn.send(method, *args, &blk)
+ df = conn.__send__(method, *args, &blk)
if async
fiber = Fiber.current
View
2 lib/em-synchrony/tcpsocket.rb
@@ -34,7 +34,7 @@ def sync(direction)
def setsockopt(level, name, value); end
def send(msg, flags = 0)
- raise "Unknown flags in send(): #{flags}" if flags.nonzero?
+ raise "Unknown flags in send(): #{flags}" if flags.nonzero?
len = msg.bytesize
write_data(msg) or sync(:out) or raise(IOError)
len
View
10 spec/tcpsocket_spec.rb
@@ -17,4 +17,14 @@
EM.stop
end
end
+
+ it 'should accept "send" when wrapped in a connection pool' do
+ EventMachine.synchrony do
+ @socket = EventMachine::Synchrony::ConnectionPool.new(size: 1) do
+ EventMachine::Synchrony::TCPSocket.new 'eventmachine.rubyforge.org', 80
+ end
+ @socket.send("GET / HTTP1.1\r\n\r\n").class.should be(Fixnum)
+ EM.stop
+ end
+ end
end

0 comments on commit 0d176e9

Please sign in to comment.