Skip to content

Commit

Permalink
Introduce a way to fine tune socket options: Bunny::Session#configure…
Browse files Browse the repository at this point in the history
…_socket
  • Loading branch information
Michael Klishin committed Jun 13, 2013
1 parent c63f2df commit aa2642c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/bunny/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,16 @@ def threaded?
@threaded
end

def configure_socket(&block)
raise ArgumentError, "No block provided!" if block.nil?

if @transport
@transport.configure_socket(&block)
else
@socket_configurator = block
end
end

# Starts the connection process.
#
# @see http://rubybunny.info/articles/getting_started.html
Expand All @@ -188,6 +198,10 @@ def start
self.maybe_close_transport
self.initialize_transport

if @socket_configurator
@transport.configure_socket(&@socket_configurator)
end

self.init_connection
self.open_connection

Expand Down
4 changes: 4 additions & 0 deletions lib/bunny/transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ def connect
end
end

def configure_socket(&block)
block.call(@socket)
end


# Writes data to the socket. If read/write timeout was specified, Bunny::ClientTimeout will be raised
# if the operation times out.
Expand Down
11 changes: 11 additions & 0 deletions spec/higher_level_api/integration/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@
Bunny.new
end

it "provides a way to fine tune socket options" do
subject.configure_socket do |sock|
sock.should respond_to(:setsockopt)
end

subject.start
subject.configure_socket do |sock|
sock.should respond_to(:setsockopt)
end
end

it "successfully negotiates the connection" do
subject.start
subject.should be_connected
Expand Down

0 comments on commit aa2642c

Please sign in to comment.