Skip to content

Commit

Permalink
Don't set linger on connecting sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri committed Feb 21, 2012
1 parent e62d0ec commit 94a8946
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/celluloid/zmq/sockets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ class Socket
# Create a new socket
def initialize(type)
@socket = Celluloid::ZMQ.context.socket ::ZMQ.const_get(type.to_s.upcase)

unless ::ZMQ::Util.resultcode_ok? @socket.setsockopt(::ZMQ::LINGER, 0)
@socket.close
raise IOError, "couldn't set ZMQ::LINGER: #{::ZMQ::Util.error_string}"
end
end

# Connect to the given 0MQ address
Expand All @@ -22,6 +17,11 @@ def connect(addr)
# Bind to the given 0MQ address
# Address should be in the form: tcp://1.2.3.4:5678/
def bind(addr)
unless ::ZMQ::Util.resultcode_ok? @socket.setsockopt(::ZMQ::LINGER, 0)
@socket.close
raise IOError, "couldn't set ZMQ::LINGER: #{::ZMQ::Util.error_string}"
end

unless ::ZMQ::Util.resultcode_ok? @socket.bind(addr)
raise IOError, "couldn't bind to #{addr}: #{::ZMQ::Util.error_string}"
end
Expand All @@ -35,7 +35,10 @@ def close
# Does the 0MQ socket support evented operation?
def evented?
actor = Thread.current[:actor]
actor && actor.mailbox.is_a?(Celluloid::IO::Mailbox) && actor.mailbox.reactor.is_a?(Celluloid::ZMQ::Reactor)
return unless actor

mailbox = actor.mailbox
mailbox.is_a?(Celluloid::IO::Mailbox) && mailbox.reactor.is_a?(Celluloid::ZMQ::Reactor)
end

# Hide ffi-rzmq internals
Expand All @@ -61,7 +64,7 @@ module WritableSocket
def send(message)
Celluloid.current_actor.wait_writable(@socket) if evented?

if ::ZMQ::Util.resultcode_ok? socket.send_string message
if ::ZMQ::Util.resultcode_ok? @socket.send_string message
raise IOError, "error sending 0MQ message: #{::ZMQ::Util.error_string}"
end
message
Expand Down

0 comments on commit 94a8946

Please sign in to comment.