lib/amq/client/async/adapters/event_machine.rb in amq-client-0.9.6 vs lib/amq/client/async/adapters/event_machine.rb in amq-client-0.9.7
- old
+ new
@@ -3,10 +3,12 @@
require "eventmachine"
require "amq/client"
require "amq/client/async/adapter"
require "amq/client/framing/string/frame"
+require "socket"
+
module AMQ
module Client
module Async
class EventMachineClient < EM::Connection
@@ -137,9 +139,19 @@
def initialize(*args)
super(*args)
+
+ begin
+ # EventMachine 1.0+
+ if self.respond_to?(:set_sock_opt)
+ set_sock_opt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
+ end
+ rescue Errno::EINVAL => e
+ # ignored, when connections fail this exception is raised with very
+ # obscure error messages. Bravo Ruby, bravo EventMachine.
+ end
self.logger = self.class.logger
# channel => collected frames. MK.
@frames = Hash.new { Array.new }