-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from paddor/master
This ports Celluloid::ZMQ to CZTop
- Loading branch information
Showing
13 changed files
with
165 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ require File.expand_path("../culture/sync", __FILE__) | |
Gem::Specification.new do |gem| | ||
gem.authors = ["Tony Arcieri"] | ||
gem.email = ["[email protected]"] | ||
gem.description = "Celluloid bindings to the ffi-rzmq library" | ||
gem.description = "Celluloid bindings to the CZMQ library" | ||
gem.summary = "Celluloid::ZMQ provides concurrent Celluloid actors that can listen for 0MQ events" | ||
gem.homepage = "http://github.com/celluloid/celluloid-zmq" | ||
gem.license = "MIT" | ||
|
@@ -13,8 +13,7 @@ Gem::Specification.new do |gem| | |
gem.version = Celluloid::ZMQ::VERSION | ||
|
||
Celluloid::Sync::Gemspec[gem] | ||
gem.add_dependency "ffi" | ||
gem.add_dependency "ffi-rzmq" | ||
gem.add_dependency "cztop" | ||
|
||
# Files | ||
ignores = File.read(".gitignore").split(/\r?\n/).reject { |f| f =~ /^(#.+|\s*)$/ }.map { |f| Dir[f] }.flatten | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,82 @@ | ||
module Celluloid | ||
module ZMQ | ||
class Socket | ||
extend Forwardable | ||
def_delegator ZMQ, :result_ok? | ||
|
||
# Create a new socket | ||
def initialize(type) | ||
@socket = Celluloid::ZMQ.context.socket ::ZMQ.const_get(type.to_s.upcase) | ||
type = type.is_a?(Integer) ? type : type.to_s.upcase.to_sym | ||
@socket = CZTop::Socket.new_by_type(type) | ||
@linger = 0 | ||
end | ||
attr_reader :linger | ||
|
||
# Connect to the given 0MQ address | ||
# Address should be in the form: tcp://1.2.3.4:5678/ | ||
def connect(addr) | ||
unless result_ok? @socket.connect addr | ||
fail IOError, "error connecting to #{addr}: #{::ZMQ::Util.error_string}" | ||
end | ||
@socket.connect addr | ||
true | ||
rescue | ||
raise IOError, "error connecting to #{addr}: #{$!.message}" | ||
end | ||
|
||
def linger=(value) | ||
@linger = value || -1 | ||
|
||
unless result_ok? @socket.setsockopt(::ZMQ::LINGER, value) | ||
fail IOError, "couldn't set linger: #{::ZMQ::Util.error_string}" | ||
end | ||
value ||= -1 | ||
@socket.options.linger = value | ||
@linger = value | ||
rescue | ||
raise IOError, "couldn't set linger: #{$!.message}" | ||
end | ||
|
||
def identity=(value) | ||
unless result_ok? @socket.setsockopt(::ZMQ::IDENTITY, "#{value}") | ||
fail IOError, "couldn't set identity: #{::ZMQ::Util.error_string}" | ||
end | ||
# de @socket.identity = value | ||
@socket.options.identity = "#{value}" | ||
rescue | ||
raise IOError, "couldn't set identity: #{$!.message}" | ||
end | ||
|
||
def identity | ||
# de @socket.identity | ||
get(::ZMQ::IDENTITY) | ||
@socket.options.identity | ||
end | ||
|
||
def set(option, value, length = nil) | ||
unless result_ok? @socket.setsockopt(option, value, length) | ||
fail IOError, "couldn't set value for option #{option}: #{::ZMQ::Util.error_string}" | ||
end | ||
def set(option, value, _length = nil) | ||
@socket.options[option] = value | ||
rescue | ||
raise IOError, "couldn't set value for option #{option}: #{$!.message}" | ||
end | ||
|
||
def get(option) | ||
option_value = [] | ||
|
||
unless result_ok? @socket.getsockopt(option, option_value) | ||
fail IOError, "couldn't get value for option #{option}: #{::ZMQ::Util.error_string}" | ||
end | ||
|
||
option_value[0] | ||
@socket.options[option] | ||
rescue | ||
raise IOError, "couldn't get value for option #{option}: #{$!.message}" | ||
end | ||
|
||
# Bind to the given 0MQ address | ||
# Address should be in the form: tcp://1.2.3.4:5678/ | ||
def bind(addr) | ||
unless result_ok? @socket.bind(addr) | ||
fail IOError, "couldn't bind to #{addr}: #{::ZMQ::Util.error_string}" | ||
end | ||
@socket.bind(addr) | ||
rescue | ||
raise IOError, "couldn't bind to #{addr}: #{$!.message}" | ||
end | ||
|
||
# Close the socket | ||
def close | ||
@socket.close | ||
end | ||
end | ||
end | ||
end | ||
|
||
# Hide ffi-rzmq internals | ||
alias_method :inspect, :to_s | ||
unless defined?(::ZMQ) | ||
# Make legacy code like this work: | ||
# | ||
# zmq_socket.set(::ZMQ::IDENTITY, "foo") | ||
# zmq_socket.get(::ZMQ::IDENTITY) | ||
# | ||
# This assumes that the user didn't require 'ffi-rzmq' themselves, but had | ||
# it done by celluloid-zmq. | ||
module ZMQ | ||
def self.const_missing(name) | ||
Celluloid::Internals::Logger.deprecate("Using ZMQ::#{name} as an option name is deprecated. Please report if you need this, so it can be added to Celluloid::ZMQ::Socket.") | ||
return name | ||
end | ||
end | ||
end |
Oops, something went wrong.