lib/miu/socket.rb in miu-0.0.5 vs lib/miu/socket.rb in miu-0.0.6

- old
+ new

@@ -20,15 +20,19 @@ @socket = @context.socket socket_type end def bind - @socket.bind "tcp://#{@host}:#{@port}" + rc = @socket.bind "tcp://#{@host}:#{@port}" + error_check rc + self end def connect - @socket.connect "tcp://#{@host}:#{@port}" + rc = @socket.connect "tcp://#{@host}:#{@port}" + error_check rc + self end def forward(forwarder) loop do message = ZMQ::Message.new @@ -40,8 +44,17 @@ end def close @socket.close @context.terminate if @terminate_context + end + + protected + + def error_check(rc, source = nil) + unless ZMQ::Util.resultcode_ok? rc + raise ZMQ::ZeroMQError.new source, rc, ZMQ::Util.errno, ZMQ::Util.error_string + end + true end end end