Coder Social home page Coder Social logo

ffi-rzmq's Introduction

ffi-rzmq

by Chuck Remes www.zeromq.org/bindings:ruby-ffi

FUTURE SUPPORT

Most people writing Zeromq applications in Ruby should be using the rbczmq project. It wraps the CZMQ binding which is a much higher-level library for writing Zeromq code. Find the Ruby gem here:

http://github.com/methodmissing/rbczmq

Few projects need to write the low-level zeromq code that this gem allows. With the release of ffi-rzmq 2.0.3, this library is going into permanent maintenance mode. As new versions of libzmq are released, interested parties should send pull requests to this project or its related project ffi-rzmq-core to support new features.

The original README text follows…

DESCRIPTION:

This gem wraps the ZeroMQ networking library using the ruby FFI (foreign function interface). It’s a pure ruby wrapper so this gem can be loaded and run by any ruby runtime that supports FFI. That’s all of them: MRI 1.9.x, Rubinius and JRuby.

The Ruby API provided by this gem is NOT very Ruby-like. It very closely tracks the libzmq C API. However, the contributors to this project have done all of the hard work to wrap up all of libzmq and make it accessible from Ruby. If you want it to be more Ruby-like (e.g. raise Exceptions instead of returning integer codes) then *wrap this library* with your own and release it as a gem. We will all be grateful!

This single gem supports 0mq 3.2.x and 4.x APIs. The 0mq project started making backward-incompatible changes to the API with the 3.1.x release. The gem auto-configures itself to expose the API conforming to the loaded C library. 0mq 2.x is no longer supported. 0mq API 3.0 is not supported; the 0mq community voted to abandon it.

The impetus behind this library was to provide support for ZeroMQ in JRuby which has native threads. Unlike MRI, which has a GIL, JRuby and Rubinius allow for threaded access to Ruby code from outside extensions. ZeroMQ is heavily threaded, so until the MRI runtime removes its GIL, JRuby and Rubinius will likely be the best environments to run this library.

Please read the History.txt file for a description of all changes, including API changes, since the last release!

PERFORMANCE:

Check out the latest performance results:

http://www.zeromq.org/bindings:ruby-ffi

The short version is that the FFI bindings are a few microseconds slower than using a C extension.

FEATURES/PROBLEMS:

This gem needs more tests. This gem has been battle tested by myself and others for years, so I am fairly confident that it is solid. However, it is inevitable that there will be bugs, so please open issues for them here or fork this project, fix them, and send me a pull request.

The ‘ffi’ gem has dropped support for MRI 1.8.x. Since this project relies on that gem to load and run this code, then this project also no longer supports MRI 1.8.x. I recommend JRuby for the best performance and stability.

The ‘Socket` and `Context` classes have finalizers which will be called by the garbage collector when there are no more references. However, these finalizers should not be relied upon to orderly close your sockets and then the context. Finalizers run in a non-determinant order, so the `Context` finalizer may run first which will hang the program. To avoid this, make sure to close all sockets before the program exits.

All features are implemented.

BUILD STATUS:

<img src=“https://secure.travis-ci.org/chuckremes/ffi-rzmq.png?branch=master” alt=“Build Status” />

<img src=“https://codeclimate.com/badge.png” />

SYNOPSIS:

0mq API v3.2-4 client code:

require 'rubygems'
require 'ffi-rzmq'

if ARGV.length < 3
  puts "usage: ruby local_lat.rb <connect-to> <message-size> <roundtrip-count>"
  exit
end

bind_to = ARGV[0]
message_size = ARGV[1].to_i
roundtrip_count = ARGV[2].to_i

ctx = ZMQ::Context.new
s   = ctx.socket ZMQ::REP
rc  = s.setsockopt(ZMQ::SNDHWM, 100)
rc  = s.setsockopt(ZMQ::RCVHWM, 100)
rc  = s.bind(bind_to)

roundtrip_count.times do
  msg = ""
  rc  = s.recv_string msg
  raise "Message size doesn't match, expected [#{message_size}] but received [#{msg.size}]" if message_size != msg.size
  rc  = s.send_string msg, 0
end

0mq API v3.2-4 server code:

require 'rubygems'
require 'ffi-rzmq'

if ARGV.length < 3
  puts "usage: ruby remote_lat.rb <connect-to> <message-size> <roundtrip-count>"
  exit
end

def assert(rc)
  raise "Last API call failed at #{caller(1)}" unless rc >= 0
end

connect_to = ARGV[0]
message_size = ARGV[1].to_i
roundtrip_count = ARGV[2].to_i

ctx = ZMQ::Context.new
s   = ctx.socket ZMQ::REQ
rc  = s.connect(connect_to)

msg = "#{ '3' * message_size }"

time_start = Time.now

roundtrip_count.times do
  assert(s.send_string(msg, 0))

  msg = ''
  assert(s.recv_string(msg, 0))

  raise "Message size doesn't match, expected [#{message_size}] but received [#{msg.size}]" if message_size != msg.size
end

time_end = Time.now
puts "Time #{( time_end - time_start )}"

Better Examples

I highly recommend visiting the Learn Ruby 0mq project for a bunch of good code examples.

http://github.com/andrewvc/learn-ruby-zeromq

REQUIREMENTS:

* 0mq 3.2.x, 4.x or later; 2.x, 3.0.x and 3.1.x are no longer supported

The ZeroMQ library must be installed on your system in a well-known location like /usr/local/lib. This is the default for new ZeroMQ installs.

If you have installed ZeroMQ using brew, you need to ‘brew link zeromq` before installing this gem.

* ffi (>= 1.0.0)

* ffi-rzmq-core

This is a requirement for MRI and Rubinius. JRuby has FFI support built in as a standard component. Do not run this gem under MRI with an old ‘ffi’ gem. It will crash randomly and you will be sad.

INSTALL:

Make sure the ZeroMQ library is already installed on your system. We recommend ‘brew’ or ‘macports’ to get it.

% gem install ffi-rzmq # should grab the latest release

To build from git master:

% git clone git://github.com/chuckremes/ffi-rzmq
% cd ffi-rzmq
% gem build ffi-rzmq.gemspec
% gem install ffi-rzmq-*.gem

NOTE for Windows users! In order for this gem to find the libzmq.dll, it must be on the Windows PATH. Google for “modify windows path” for instructions on how to do that if you are unfamiliar with that activity. That DLL also requires that you copy libstdc++-6.dll and libgcc_s_sjlj-1.dll from DevKit MinGW into the same folder that you copied libzmq.dll.

LICENSE:

(The MIT License)

Copyright © 2013-2017 Chuck Remes

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

ffi-rzmq's People

Contributors

andrewvc avatar arvicco avatar bantic avatar bmabey avatar celldee avatar chuckremes avatar deployable avatar dustalov avatar flavio avatar grantr avatar jasonroelofs avatar jonochang avatar jordansissel avatar kojix2 avatar minrk avatar mjio avatar mostlyobvious avatar paddor avatar pbrit avatar quixoten avatar schmurfy avatar soulim avatar stakach avatar sundbp avatar zaccari avatar zbelzer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ffi-rzmq's Issues

Problem using ffi-rzmq under Windows XP

So far I had no success setting up environment for ffi-rzmq under Windows XPSP3 (32bit). I have successfully built zeromq-2.0.10 - with Visual Studio from Windows package and from sources under Cygwin. So, I have zeromq library working and in path.

Here are the Rubies that I tried (since it is indicated that either JRuby or 1.9.2 are adequate, I only tried those):
Ruby 1.9.2-p0 (Rubyinstaller)
JRuby 1.5.2
Ruby 1.9.2-p0 (built from source under Cygwin)

Unfortunately, trying to run example from https://github.com/andrewvc/learn-ruby-zeromq/ fails with a following trace:

Y:\Dev\apps\win\learn-ruby-zeromq\001_Socket_Types>jruby -v
jruby 1.5.2 (ruby 1.8.7 patchlevel 249) (2010-08-20 1c5e29d) (Java HotSpot(TM) Client VM 1.6.0_20) [x86-java]

Y:\Dev\apps\win\learn-ruby-zeromq\001_Socket_Types>gem list

columnize (0.3.1)
ffi (0.6.3)
ffi-rzmq (0.6.0)
rake (0.8.7)
rspec (1.3.0)
ruby-debug (0.10.3)
ruby-debug-base (0.10.3.2)
sources (0.0.1)
zmqmachine (0.3.2)

Y:\Dev\apps\win\learn-ruby-zeromq\001_Socket_Types>jruby 001_push_pull.rb
C:/Documents and Settings/bezrodnykh/.pik/rubies/JRuby-152/lib/ruby/site_ruby/shared/ffi/ffi.rb:112:in create_invoker': Function 'valloc' not found in [msvcrt] (FFI::NotFoundError) from C:/Documents and Settings/bezrodnykh/.pik/rubies/JRuby-152/lib/ruby/site_ruby/shared/ffi/library.rb:98:inattach_function'
from C:/Documents and Settings/bezrodnykh/.pik/rubies/JRuby-152/lib/ruby/site_ruby/shared/ffi/library.rb:96:in each' from C:/Documents and Settings/bezrodnykh/.pik/rubies/JRuby-152/lib/ruby/site_ruby/shared/ffi/library.rb:96:inattach_function'
from C:/Documents and Settings/bezrodnykh/.pik/rubies/JRuby-152/lib/ruby/gems/1.8/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq/wrapper.rb:11
from C:/Documents and Settings/bezrodnykh/.pik/rubies/JRuby-152/lib/ruby/gems/1.8/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq/wrapper.rb:31:in require' from C:/Documents and Settings/bezrodnykh/.pik/rubies/JRuby-152/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:inrequire'
from C:/Documents and Settings/bezrodnykh/.pik/rubies/JRuby-152/lib/ruby/gems/1.8/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq.rb:71
from C:/Documents and Settings/bezrodnykh/.pik/rubies/JRuby-152/lib/ruby/gems/1.8/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq.rb:70:in each' from C:/Documents and Settings/bezrodnykh/.pik/rubies/JRuby-152/lib/ruby/gems/1.8/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq.rb:70 from C:/Documents and Settings/bezrodnykh/.pik/rubies/JRuby-152/lib/ruby/gems/1.8/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq.rb:36:inrequire'
from C:/Documents and Settings/bezrodnykh/.pik/rubies/JRuby-152/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from 001_push_pull.rb:2


$ ruby -v
ruby 1.9.2dev (2009-07-18 trunk 24186) [i386-cygwin]

$ gem list

ffi (0.6.3)
ffi-rzmq (0.6.0)
rake (0.8.7)
rubygems-update (1.3.7)
zmqmachine (0.3.2)

vb@vb-mac /y/dev/apps/win/learn-ruby-zeromq/001_Socket_Types
$ ruby 001_push_pull.rb
/home/bezrodnykh/.rvm/gems/ruby-1.9.2-preview1/gems/ffi-0.6.3/lib/ffi/library.rb:129:in attach_function': Function 'valloc' not found in [msvcrt.dll] (FFI::NotFoundError) from /home/bezrodnykh/.rvm/gems/ruby-1.9.2-preview1/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq/wrapper.rb:11:inmodule:LibC'
from /home/bezrodnykh/.rvm/gems/ruby-1.9.2-preview1/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq/wrapper.rb:3:in <top (required)>' from /home/bezrodnykh/.rvm/gems/ruby-1.9.2-preview1/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq.rb:71:inrequire'
from /home/bezrodnykh/.rvm/gems/ruby-1.9.2-preview1/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq.rb:71:in block in <top (required)>' from /home/bezrodnykh/.rvm/gems/ruby-1.9.2-preview1/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq.rb:70:ineach'
from /home/bezrodnykh/.rvm/gems/ruby-1.9.2-preview1/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq.rb:70:in <top (required)>' from 001_push_pull.rb:2:inrequire'
from 001_push_pull.rb:2:in `

'


Any advice/suggestion/hint to help me moving forward?

Not compatible with 3.2.1

Unfortunately, as per the 3.2.1 changelog, ffi-rzmq isn't compatible anymore:

  • zmq_ctx_set_monitor () replaced by zmq_socket_monitor ().

This, of course, results in an error during runtime: in `attach_function': Function 'zmq_ctx_set_monitor' not found in /usr/local/lib/libzmq.so

Bad file descriptor

This might be an issue with the ZMQ library itself, but I wanted to post it here first.

Running the following code produces a "Bad file descriptor" error on my linux machine running ZMQ version 3.2.3. It also happens on OSX running ZMQ version 3.2.2. It appears to be caused by creating/destroying many contexts and sockets in rapid succession in different threads.

Using a single context for all the requests removes the error. Creating/destroying the contexts and sockets synchronously removes the error as well.

require 'ffi-rzmq'

server = Thread.new do
  zmq_context = ZMQ::Context.new
  socket = zmq_context.socket(ZMQ::REP)
  rc = socket.bind("tcp://127.0.0.1:55020")
  poller = ZMQ::Poller.new
  poller.register_readable(socket)

  begin
    while poller.poll == 1
      socket.recv_string(message = "")
      print "server rcvd: #{message}\n"
      socket.send_string(message)
    end
  ensure
    socket.close
    zmq_context.terminate
  end
end

100.times do |x|
  100.times.map do |y|
    Thread.new do
      zmq_context = ZMQ::Context.new
      socket = zmq_context.socket(ZMQ::REQ)
      rc = socket.connect("tcp://127.0.0.1:55020")

      socket.send_string("#{x}, #{y}")
      socket.recv_string(reply = "")
      socket.close
      zmq_context.terminate
    end
  end.each(&:join)
end

server.kill

device_spec.rb does not exit cleanly

(running on OSX)

device_spec.rb doesn't exit cleanly - I'm assuming because the termination of context for sockets of device doesn't happen properly but not sure exactly how. trying to figure it out.

The libzmq version 2.0.7 is incompatible with ffi-rzmq

getting runtime error:

.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/ffi-rzmq-0.9.6/lib/ffi-rzmq/libzmq.rb:273:in `module:ZMQ': The libzmq version 2.0.7 is incompatible with ffi-rzmq. (LoadError)

using rbenv with 1.9.3-p194 and gems :
$ gem list

*** LOCAL GEMS ***

addressable (2.3.2)
bigdecimal (1.1.0)
builder (3.0.0)
celluloid (0.12.1.pre)
celluloid-io (0.12.1)
celluloid-zmq (0.12.1)
certified (0.1.1)
cucumber (0.10.0)
dcell (0.11.0, 0.10.0)
diff-lcs (1.1.2)
dynect_rest (0.4.3)
expectations (2.0.0)
facter (1.6.13)
ffi (1.1.5)
ffi-rzmq (0.9.6)
gherkin (2.3.3)
hiredis (0.4.5)
http (0.3.0)
http_parser.rb (0.5.3)
io-console (0.3)
json (1.5.4, 1.4.6)
mime-types (1.19)
minitest (2.5.1)
mocha (0.9.11)
moneta (0.6.0)
netrc (0.7.7)
nio4r (0.4.0)
parallel (0.5.18)
rack (1.4.1)
rake (0.9.2.2, 0.8.7)
rdoc (3.9.4)
redis (3.0.1)
redis-namespace (1.2.1)
reel (0.0.2)
rest-client (1.6.7)
rspec (2.4.0)
rspec-core (2.4.0)
rspec-expectations (2.4.0)
rspec-mocks (2.4.0)
term-ansicolor (1.0.5)
timers (1.0.1)
websocket_parser (0.1.0)

tried standard gems as well as rebuilding all celluloid celluloid-io celluloid-zmq dcell ffi ffi-rzmq with same result.

running Ubuntu 10.04.4 LTS on x86_64

i tried with the standard ubuntu packages and without :
$ dpkg -l | egrep -i "zmq|zeromq|0mq"
rc libzmq0 2.0.10-1build1 The ZeroMQ messaging library
rc libzmq1 2.2.0-1chl1~lucid1 ZeroMQ lightweight messaging kernel (shared

Can't locate libzmq.so

On CentOS 6.3 as well as Ubuntu 12.10, the default packages creates a libzmq.so.1.

On CentOS, I can easily create a symlink, but on Ubuntu, the location is not in the default array, i.e: /usr/lib/x86_64-linux-gnu.

I can of course just add to the array, and, also append a .1 to the map that searches for the file. But it's not as elegant as I'd like it to be (read: not really something I'd want to do a pull request with).

Any ideas?

ZMQ 2.1 Term Semantics

Sustrik Mentioned this in IRC, thought I'd put it here so it's not forgotten. I'm not sure if we support this as is yet.

in 2.1, zmq_term() should not invalidate the socekts
what it does
it causes the socket to return ETERM on any subsequent call
and wait for the user to close the socket
so you should not see EBADF in such case
if you do, it's a bug

Removing from poller fails

Hi chuckremes,

I'm having issues deregistering sockets.
I've created a gist to show a minimalistic reproduce case: https://gist.github.com/2895395

It seems the socket I want to deregister doesn't go away. Am I doing something wrong or is it a bug?

Kind regards,
Tom

socket monitor events need a container

monitor sockets send zmq_event_t structs which are an event id and a union of event data. Would be awesome if there was an Event class that could handle them!

fix Poller#poll so that it behaves better with no sockets defined

When no sockets are registered for polling, a call to Poller#poll returns immediately regardless of the poll_interval defined. This causes client programs like zmqmachine to busy-wait when they haven't registered any sockets yet and burn up the CPU.

The question now is should #poll sleep for the poll interval or push this responsibility back up the stack?

It seems most reasonable to me for it to push off the responsibility. The caller should note that a call to #poll may block for as long as the poll_interval defines but the time could be shorter. Then it is up to the caller to make sure it doesn't call too often.

Thoughts?

Doesn't find libzmq.so.1

The gem searches for libzmq.so in various places, however in Ubuntu natty(-backports), there only exist files named /usr/lib64/libzmq.so.1 and /usr/lib64/libzmq.so.1.0.0. I had to manually symlink them to libzmq.so for the gem to work.

Running ldconfig didn't help.

I guess that might be because there are two versions of libzmq in natty - libzmq0 is in normal natty and libzmq1 is in natty backports.

Don't know of a good way to fix it, and I'm not sure which version of libzmq the gem is actually "linked" (?) against.

Ruby 1.9.2 + Mac OS X 10.6.8 with connect + backticks = block

This simple script will block in Ruby 1.9.2 on Mac OS X 10.6.8 (Snow Leopard). I can reliably reproduce the bug by using this script, on three different macs, and reliably fix it by including a tiny time-delay.

The bug is that following a ffi-rzmq socket connect too closely by a subprocess creation will cause the process to hang.

Best with code:

require 'ffi-rzmq'
begin
  context = ZMQ::Context.new
  socket = context.socket ZMQ::DEALER  # or router...
  socket.connect "tcp://localhost:5562"
  sleep 0.01  # this alleviates any problems.
  `date`  # busts and causes 100% processor core busy-wait and process hang. Never executes date.
ensure
  socket.close if socket
  context.terminate if context
end

This is reproducible with: ffi 1.0.0 and 1.0.9; reproducible with ffi-rzmq 0.8.0 and 0.8.2; reproducible with ruby 1.9.2p136 and 1.9.2p290, all on mac 10.6.8. Three different macs. You can replace the use of backticks with any other kind of process / subprocess creation and you will get similar errors.

I cannot produce the error using FreeBSD even with identical versions of everything. I cannot produce the error using Ruby 1.8.

You can also fix the problem by including the delay in the subprocess. For example:

require 'ffi-rzmq'
begin
  context = ZMQ::Context.new
  socket = context.socket ZMQ::DEALER  # or router...
  socket.connect "tcp://localhost:5562"
  `date; sleep 0.01`  # no problem.
ensure
  socket.close if socket
  context.terminate if context
end

I'm happy to provide any further help / debug info etc. We've successfully used a lot of ZeroMQ in Ruby with ffi-rzmq and written some C extensions, but have now run into a timing problem like this twice. The process does not respond to a TERM but does respond to a KILL (unsurprisingly).

poll_spec.rb test failure

Running the poll spec test suite results in a failure:

rspec spec/poll_spec.rb
.....F..

Failures:

  1) ZMQ::Context#register should access the raw 0mq socket
     Failure/Error: poller.register(socket)
     ArgumentError:
       value is not a pointer
     # ./lib/ffi-rzmq/poll.rb:77:in `[]='
     # ./lib/ffi-rzmq/poll.rb:77:in `register'
     # ./spec/poll_spec.rb:48:in `block (3 levels) in <module:ZMQ>'

Finished in 0.00335 seconds
8 examples, 1 failure

Anyone else having this issue?

sock.recv_string returning empty strings

I've been trying to use sock.recv_string inside of a class that handles all of the zmq connections and message parsing. When a lot of connections stream in, sock.recv_string returns nil or empty strings in quick succession. It basically locks up everything and will not accept any more messages. The following code will accept about 19-25 connections then just get stuck in a loop, printing @conn.receive then @conn.reply_http over and over again.

lood do
  puts "@conn.receive"
  msg = ""
  @conn.request_sock.recv_string msg
  puts "@conn.reply_http"
  @conn.reply_http(msg, "hello world")
end

I can't get it to work

I can't get zmq to work. I'm following examples found in another git repository to show me the basics. The sources are:
Source files:
https://github.com/imatix/zguide/blob/master/examples/Ruby/hwclient.rb
https://github.com/imatix/zguide/blob/master/examples/Ruby/hwserver.rb

It's just a basic "Hello world" app.
When I run the apps I get the following output from the server

$ ruby hwserver.rb 
Starting Hello World server...
Received request. Data: 0
Received request. Data: 0
Received request. Data: 0
Received request. Data: 0
Received request. Data: 0
Received request. Data: 0
Received request. Data: 0
Received request. Data: 0
Received request. Data: 0
Received request. Data: 0

And the following output from the client:

$ ruby hwclient.rb 
Connecting to hello world server...
Sending request 0...
Received reply 0: [0]
Sending request 1...
Received reply 1: [0]
Sending request 2...
Received reply 2: [0]
Sending request 3...
Received reply 3: [0]
Sending request 4...
Received reply 4: [0]
Sending request 5...
Received reply 5: [0]
Sending request 6...
Received reply 6: [0]
Sending request 7...
Received reply 7: [0]
Sending request 8...
Received reply 8: [0]
Sending request 9...
Received reply 9: [0]

Dependencies:

$ dpkg --list | grep zmq
ii  libzmq-dev                             2.1.9-1                                 ZeroMQ lightweight messaging kernel (development libraries and header files)
ii  libzmq1                                2.1.9-1                                 ZeroMQ lightweight messaging kernel (shared library)
$ gem list | grep zmq
celluloid-zmq (0.10.0)
ffi-rzmq (0.9.3)

I'm running Linux Mint Lisa 12 64 bit with ruby-1.9.3-p125.
Can you please tell me what I'm doing wrong?

Memory access offset=0?

Hi,

Trying to run some zmq code on an Ubuntu Jaunty server running on Amazon EC2. I've got zeromq-2.0.10 installed along with ruby 1.9.2p0. After a while, 2-3 minutes I get

/home/daniel/.rvm/gems/ruby-1.9.2-p0@apache_tailer/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq/poll_items.rb:26:in +': Memory access offset=0 size=1 is out of bounds (IndexError) from /home/daniel/.rvm/gems/ruby-1.9.2-p0@apache_tailer/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq/poll_items.rb:26:inget'
from /home/daniel/.rvm/gems/ruby-1.9.2-p0@apache_tailer/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq/poll.rb:65:in register' from /home/daniel/.rvm/gems/ruby-1.9.2-p0@apache_tailer/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq/poll.rb:113:inregister_writable'
from /home/daniel/.rvm/gems/ruby-1.9.2-p0@apache_tailer/gems/zmqmachine-0.3.2/lib/zm/reactor.rb:281:in register_writable' from /home/daniel/.rvm/gems/ruby-1.9.2-p0@apache_tailer/gems/dripdrop-0.5.0/lib/dripdrop/handlers/zeromq.rb:84:insend_message'
from /home/daniel/.rvm/gems/ruby-1.9.2-p0@apache_tailer/gems/dripdrop-0.5.0/lib/dripdrop/handlers/zeromq.rb:153:in send_message' from tail_apache_zmq.rb:19:inblock in receive_data'
from tail_apache_zmq.rb:17:in each' from tail_apache_zmq.rb:17:inreceive_data'
from /home/daniel/.rvm/gems/ruby-1.9.2-p0@apache_tailer/gems/eventmachine-tail-0.5.20101204110840/lib/em/filetail.rb:256:in read' from /home/daniel/.rvm/gems/ruby-1.9.2-p0@apache_tailer/gems/eventmachine-tail-0.5.20101204110840/lib/em/filetail.rb:238:inblock in schedule_next_read'
from /home/daniel/.rvm/gems/ruby-1.9.2-p0@apache_tailer/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in call' from /home/daniel/.rvm/gems/ruby-1.9.2-p0@apache_tailer/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:inrun_machine'
from /home/daniel/.rvm/gems/ruby-1.9.2-p0@apache_tailer/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in run' from /home/daniel/.rvm/gems/ruby-1.9.2-p0@apache_tailer/gems/dripdrop-0.5.0/lib/dripdrop/node.rb:33:inblock in start'

Haven't been able to find any information on how to fix this.

Regards,

  • Daniel

ZMQ::Poller#delete incorrectly returns false

When more than one socket is registered on a ZMQ::Poller and one socket is deleted from the Poller, the return value is incorrectly false.
This is used in ZMQMachine [1]

require 'ffi-rzmq'

context = ZMQ::Context.new
socket1 = con.socket ZMQ::REP
socket2 = con.socket ZMQ::REP

poller = ZMQ::Poller.new
poller.register_readable socket1
poller.register_readable socket2

p poller.delete socket2

The reason this occurs is because one of the success conditions is that the socket was deleted from the @sockets array. [2]
But in the common case, the #deregister method actually calls back into #delete which then deletes the socket from the array. [3]

I am not sure of the best way to resolve this, but it would make sense to only attempt to delete the socket once instead of the 3 times it is occurring now.

[1] https://github.com/chuckremes/zmqmachine/blob/e382367c64bc37c7b82df9b0c440d6b1ddf80d11/lib/zm/reactor.rb#L553
[2] https://github.com/chuckremes/ffi-rzmq/blob/f8e851280e518504cd5c3b7e4bcae9ac8f32d038/lib/ffi-rzmq/poll.rb#L147-148
[3]

delete sock if item[:events].zero?

new getsockopt signature

Hi,
Why did you change the signature of the call in latest version instead of raising an error ?
If you wanted to make your api looks like C I think you succeeded but that's not really the ruby way...

The current code:

array = []
rc = socket.getsockopt(ZMQ::HWM, array)
hwm = array.first if ZMQ::Util.resultcode_ok?(rc)

And what it could be:

begin
  hwm = socket.getsockopt(ZMQ::HWM)
rescue ZMQ::OperationFailed => err
  # do something
end

Since looking at the first really makes me sick I can even provide the pull request, but would you accept it ?

Abort trap on SIGINT while blocked for read.

While doing a @reqs.recv_string(0), I want to shut down the process so I hit Ctrl+C, but then I get:

^CInterrupted system call
nbytes != -1 (signaler.cpp:269)
Abort trap

Any ideas on what I can do here?

0.9.5 release date

0.9.5 was introduced 6 months ago in master branch. Is it going to be released soon ? Any blockers ? There is big warning about incompatible changes and it is hard to code another gems depending on ffi-rzmq. I would like to use the new API but cannot because 0.9.5 is not released so I cannot make it a dependency of my gem.

Segfault with master/1.8.7

I get this guy:

/opt/local/lib/ruby/gems/1.8/gems/ffi-rzmq-0.5.0/lib/ffi-rzmq/message.rb:83: [BUG] unexpected local variable
ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin10]

Abort trap

Trying to write a connection adapter for Mongrel2, like so: http://gist.github.com/476572

And fails when I send a message like this: @resp.send_string("some message", 0)

So, is it 'cause I'm forcing it to use Ruby 1.8.7? Should I be using something more recent?

Thanks.

Failing Poll#register spec

rspec spec/poll_spec.rb -l 35

  1. ZMQ::Context#register should return the registered event value when given a nil socket and a valid non-zero file descriptor
    Failure/Error: poller.register(nil, ZMQ::POLLIN, 1).should == ZMQ::POLLIN

So, a couple weird things here inside Poll#register item[:socket] = 0 should be FFI::Pointer.new(0) no? This causes FFI errors in all rubies as it expects a pointer.

But that doesn't fix the spec, because later on @raw_to_socket[item[:socket].address] = sock is called, and you can't call .address on a socket. I don't see how this ever worked, I'm clearly missing something.

Performance

I'm going through the Code Connected book, writing out the examples in ruby using this gem.

The Weather Update publisher is considerably slower than the C example, by a lot more than I would have expected. The C example takes roughly 4 seconds consistently. The ruby code takes over 2 minutes / about 30x slower.

Is this to be expected?

Deregistering closed ZMQ socket from Poller raises exception

Code:

sub.close
poller.deregister_readable(sub)

Exception:

NoMethodError: undefined method `address' for nil:NilClass
    from /ruby/1.9.1/bundler/gems/ffi-rzmq-7bed37cd35a2/lib/ffi-rzmq/poll.rb:146:in `block in delete'
    from /ruby/1.9.1/bundler/gems/ffi-rzmq-7bed37cd35a2/lib/ffi-rzmq/poll.rb:146:in `delete_if'
    from /ruby/1.9.1/bundler/gems/ffi-rzmq-7bed37cd35a2/lib/ffi-rzmq/poll.rb:146:in `delete'
    from /ruby/1.9.1/bundler/gems/ffi-rzmq-7bed37cd35a2/lib/ffi-rzmq/poll.rb:106:in `deregister'
    from /ruby/1.9.1/bundler/gems/ffi-rzmq-7bed37cd35a2/lib/ffi-rzmq/poll.rb:128:in `deregister_readable'

Note: deregister before closing works fine.

version.txt expected at root of gem dir, but not found error

I get an odd error centering around line 12 of ffi-rzmq.rb where it loads the gem version or some such.

It appears this .rb line expects a version.txt file to be at the root dir of the gem install but it is not included in the installation.

  • Just thought I'd bring it to your attention.

Cheers, and good work on the gem.

Gem update

Hi,

Any change we can get the gem updated? Issue #32 was quite frustrating

send_strings raises if given only one message part

send_multiple assumes that it is given more than one part. If only one part is given, then rc is nil when resultcode_ok? is called.

Either fix send_multiple to work with single element arrays, or add a branch to send_strings that delegates to send_string when necessary.

Version 1.0.0 as released to rubygems is different from git tag

I didn't do a diff, but it looks to me like the gem was built from d69fbfc rather than 775bdd5 as claimed by the tag. Practically this means:

  • Socket#unbind and Socket#disconnect are broken in 1.0.0 (not in agreement with changelog)
  • Confusion!

Any chance of releasing a 1.0.1? Thanks.

BTW I've checked my environment - I verified this claim by downloading the .gem from rubygems and untaring manually.

Can't run specs on Lion? mach-o, but wrong architecture

I initially tried to run the examples from learn-ruby-zeromq which failed so I cloned ffi-rzmq and tried to get the specs running. In both instances I can the following error.

bumblebee:~/Documents/src/ffi-rzmq$ rake spec
rake/rdoctask is deprecated.  Use rdoc/task instead (in RDoc 2.4.2+)
/Users/daniel/.rvm/rubies/jruby-1.6.4/bin/jruby -S rspec ./spec/context_spec.rb ./spec/device_spec.rb ./spec/message_spec.rb ./spec/multipart_spec.rb ./spec/nonblocking_recv_spec.rb ./spec/poll_spec.rb ./spec/pushpull_spec.rb ./spec/reqrep_spec.rb ./spec/socket_spec.rb
LoadError: Could not open library '/Users/daniel/Documents/src/ffi-rzmq/lib/ffi-rzmq/../../ext/libzmq.dylib' : dlopen(/Users/daniel/Documents/src/ffi-rzmq/lib/ffi-rzmq/../../ext/libzmq.dylib, 5): image not found. Could not open library '/usr/local/lib/libzmq.dylib' : dlopen(/usr/local/lib/libzmq.dylib, 5): no suitable image found.  Did find:
    /usr/local/lib/libzmq.dylib: mach-o, but wrong architecture. Could not open library '/opt/local/lib/libzmq.dylib' : dlopen(/opt/local/lib/libzmq.dylib, 5): image not found. Could not open library '/usr/local/homebrew/lib/libzmq.dylib' : dlopen(/usr/local/homebrew/lib/libzmq.dylib, 5): image not found. Could not open library 'libzmq' : dlopen(libzmq, 5): image not found. Could not open library 'libzmq.dylib' : dlopen(libzmq.dylib, 5): no suitable image found.  Did find:
    /usr/local/lib/libzmq.dylib: mach-o, but wrong architecture
          ffi_lib at /Users/daniel/.rvm/rubies/jruby-1.6.4/lib/ruby/site_ruby/shared/ffi/library.rb:82
          collect at org/jruby/RubyArray.java:2344
          ffi_lib at /Users/daniel/.rvm/rubies/jruby-1.6.4/lib/ruby/site_ruby/shared/ffi/library.rb:64
           LibZMQ at /Users/daniel/Documents/src/ffi-rzmq/lib/ffi-rzmq/libzmq.rb:12
           (root) at /Users/daniel/Documents/src/ffi-rzmq/lib/ffi-rzmq/libzmq.rb:5
          require at org/jruby/RubyKernel.java:1047
          require at /Users/daniel/.rvm/rubies/jruby-1.6.4/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29
           (root) at /Users/daniel/Documents/src/ffi-rzmq/lib/ffi-rzmq/libzmq.rb:74
             each at org/jruby/RubyArray.java:1603
           (root) at /Users/daniel/Documents/src/ffi-rzmq/lib/ffi-rzmq.rb:73
          require at org/jruby/RubyKernel.java:1047
          require at /Users/daniel/.rvm/rubies/jruby-1.6.4/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29
           (root) at /Users/daniel/Documents/src/ffi-rzmq/lib/ffi-rzmq.rb:5
          require at org/jruby/RubyKernel.java:1047
          require at /Users/daniel/.rvm/rubies/jruby-1.6.4/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29
           (root) at /Users/daniel/Documents/src/ffi-rzmq/spec/spec_helper.rb:3
             load at org/jruby/RubyKernel.java:1073
  load_spec_files at /Users/daniel/Documents/src/ffi-rzmq/spec/context_spec.rb:419
          collect at org/jruby/RubyArray.java:2344
  load_spec_files at /Users/daniel/.rvm/gems/jruby-1.6.4@zeromq/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:419
              run at /Users/daniel/.rvm/gems/jruby-1.6.4@zeromq/gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:18
   run_in_process at /Users/daniel/.rvm/gems/jruby-1.6.4@zeromq/gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:80
              run at /Users/daniel/.rvm/gems/jruby-1.6.4@zeromq/gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:69
          autorun at /Users/daniel/.rvm/gems/jruby-1.6.4@zeromq/gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:11
org.jruby.exceptions.RaiseException: (SystemExit) exit
rake aborted!
ruby -S rspec ./spec/context_spec.rb ./spec/device_spec.rb ./spec/message_spec.rb ./spec/multipart_spec.rb ./spec/nonblocking_recv_spec.rb ./spec/poll_spec.rb ./spec/pushpull_spec.rb ./spec/reqrep_spec.rb ./spec/socket_spec.rb failed

Tasks: TOP => spec
(See full trace by running task with --trace)

I've installed ZeroMQ using Homebrew and the version is 2.1.10. As you can see from the trace I'm trying to run it with JRuby 1.6.4 installed with RVM.

The installed lib seems ok?

bumblebee:~/Documents/src/ffi-rzmq$ lipo -info /usr/local/lib/libzmq.dylib
Non-fat file: /usr/local/lib/libzmq.dylib is architecture: x86_64

Appreciate any help to get me up and running. Thanks.

The libzmq library (or DLL) could not be found on os x

Hello, thank you for gem.

I try to use it my os x computer under Ruby 2.0 and Jruby 1.7.4
It's installed fine, but then I try require it i've got message:

jruby-1.7.4 :001 > require 'ffi-rzmq'
Unable to load this gem. The libzmq library (or DLL) could not be found.
If this is a Windows platform, make sure libzmq.dll is on the PATH.
If the DLL was built with mingw, make sure the other two dependent DLLs,
libgcc_s_sjlj-1.dll and libstdc++6.dll, are also on the PATH.
For non-Windows platforms, make sure libzmq is located in this search path:
["/Users/leonko/.rvm/gems/jruby-1.7.4/gems/ffi-rzmq-1.0.1/lib/ffi-rzmq/../../ext/libzmq.dylib", "/usr/local/lib/libzmq.dylib", "/opt/local/lib/libzmq.dylib", "/usr/local/homebrew/lib/libzmq.dylib", "/usr/lib64/libzmq.dylib", "/Users/leonko/.rvm/gems/jruby-1.7.4/bin", "/Users/leonko/.rvm/rubies/jruby-1.7.4/bin", "/Users/leonko/.rvm/bin", "/usr/local/bin", "/usr/bin", "/bin", "/usr/sbin", "/sbin", "/opt/X11/bin", "/usr/local/smlnj-110.75/bin"]
LoadError: The libzmq library (or DLL) could not be loaded
from /Users/leonko/.rvm/gems/jruby-1.7.4/gems/ffi-rzmq-1.0.1/lib/ffi-rzmq/libzmq.rb:37:in LibZMQ' from /Users/leonko/.rvm/gems/jruby-1.7.4/gems/ffi-rzmq-1.0.1/lib/ffi-rzmq/libzmq.rb:6:inZMQ'
from /Users/leonko/.rvm/gems/jruby-1.7.4/gems/ffi-rzmq-1.0.1/lib/ffi-rzmq/libzmq.rb:1:in (root)' from org/jruby/RubyKernel.java:1054:inrequire'
from /Users/leonko/.rvm/rubies/jruby-1.7.4/lib/ruby/shared/rubygems/custom_require.rb:36:in require' from /Users/leonko/.rvm/gems/jruby-1.7.4/gems/ffi-rzmq-1.0.1/lib/ffi-rzmq.rb:1:in(root)'
from org/jruby/RubyArray.java:1617:in each' from /Users/leonko/.rvm/gems/jruby-1.7.4/gems/ffi-rzmq-1.0.1/lib/ffi-rzmq.rb:71:in(root)'
from org/jruby/RubyKernel.java:1054:in require' from /Users/leonko/.rvm/gems/jruby-1.7.4/gems/ffi-rzmq-1.0.1/lib/ffi-rzmq.rb:70:in(root)'
from /Users/leonko/.rvm/rubies/jruby-1.7.4/lib/ruby/shared/rubygems/custom_require.rb:1:in (root)' from org/jruby/RubyKernel.java:1093:ineval'
from /Users/leonko/.rvm/rubies/jruby-1.7.4/lib/ruby/shared/rubygems/custom_require.rb:60:in require' from (irb):1:inevaluate'

travis ci has same issue:
https://travis-ci.org/chuckremes/ffi-rzmq/builds/6446484

Please help me

Socket#send_string does not send any packets with libzmq-2.0.6

I noticed that when calling ZMQ::Socket#send_string with libzmq-2.0.6 does not actually send any data. I wrote up a small client to connect to a ZeroMQ server and send a string, but no actual packets appeared when watching the connection in WireShark. However, I did see the TCP/ZMQ handshake occurr.

Can't find libzmq.so under RHEL

We installed the zmq library via a Redhat gem which installed it as /usr/lib64/libzmq.so.1. It looks like the libzmq.rb file doesn't find it in this directory. Could you add an override so that the path could be specified via a config/initializer or maybe add /usr/lib64 and /usr/lib to the search paths (although I think the .1 suffix will still confuse it).

Our workaround was to ln -s /usr/lib64/libzmq.so.1 /usr/local/lib/libzmq.so

device tests blow up on os x

rspec spec/device_spec.rb -f d

ZMQ::Device
should create a streamer device without error given valid optsAssertion failed: uri_ != NULL (socket_base.cpp:157)
Abort trap

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.