Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Ruby FFI bindings for Crossroads I/O messaging library
Ruby
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples
ext
lib
spec
.gitignore
.travis.yml
.yardopts
AUTHORS.txt
CHANGELOG
Gemfile
LICENSE
README.textile
Rakefile
ffi-rxs.gemspec

README.textile

About ffi-rxs

This gem wraps the Crossroads I/O messaging library (libxs) 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.

Crossroads I/O is a fork of ZeroMQ. This gem is a re-working of the ffi-rzmq gem created by Chuck Remes to provide bindings for the libxs library instead of the ZeroMQ libzmq library.

Features/Problems

This gem needs to be tested in the wild. Please kick its tyres and give it a good thrashing. It is inevitable that bugs will be discovered, 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.×. Since this project relies on that gem to load and run this code, then this project does not support MRI 1.8.×. I recommend JRuby for the best performance and stability.

Requirements

  • Crossroads I/O version 1.0.0 or later.
  • ffi (>= 1.0.0)

The libxs library must be installed on your system in a well-known location like ‘/usr/local/lib’.

Do not run this gem under MRI with an old ‘ffi’ gem. It will not work as expected.

NOTE
The master GitHub repository contains a copy of the libxs library in the ‘ext’ directory. This is so that the Travis CI continuous integration build platform can be used. The .gemspec file excludes the ‘ext’ directory from the gem build.

If you want to build a gem using a version of libxs other than your current system version, then you can include the library in the ‘ext’ directory. Do not forget to change the .gemspec file so that it does not exclude the library from the gem build.

Installation

A full gem has been released to Rubygems.org as of release 1.0.0. Make sure the Crossroads I/O library is already installed on your system.

  • gem install ffi-rxs # should grab the latest release

To build from git master:

  • git clone git://github.com/celldee/ffi-rxs
  • cd ffi-rxs
  • gem build ffi-rxs.gemspec
  • gem install ffi-rxs-*.gem

NOTE for Windows users!
In order for this gem to find the libxs.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.

Examples

Using Request (REQ) socket -

require 'ffi-rxs'

ctx = XS::Context.create()
socket = ctx.socket(XS::REQ)
socket.connect("tcp://127.0.0.1:5000")
 
(1..10).each do |i|
  msg = "msg #{i.to_s}"
  socket.send_string(msg)
  puts "Sending: " + msg
  socket.recv_string(msg_in = '')
  puts "Received: " + msg_in
end

Using Reply (REP) socket -

require 'ffi-rxs'

ctx = XS::Context.create()
socket = ctx.socket(XS::REP)
socket.bind("tcp://127.0.0.1:5000")
 
while true do
  socket.recv_string(msg = '')
  puts "Got: " + msg
  socket.send_string(msg)
end

The above examples and additional ones are available in the repository examples folder.

Links

License

This project is licensed under the MIT license. Please see the LICENSE file in the repository.

Something went wrong with that request. Please try again.