rbzmq 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e6bbeba6732872df1e235bc96fa18b734b514bb8
4
+ data.tar.gz: c8d8dfe8cb6b08f9e5ff55a26d95dd3aad3f4b9d
5
+ SHA512:
6
+ metadata.gz: c71ab0628d1d397c44dbe1d4727622baf0ccdb1a4feb3ea8f1464a625fb5e1853fcbf1d895a8672975b31f69ab1a106ce822db0a0976f1ecafa28075991cd19c
7
+ data.tar.gz: 68085788dfb47aa179cf7154feb4c7004c6b44f432ea4f34c48e4c46ed4a951cab1da246bc7807de4edb4208df3144981fda08b253541ca01e986753c14d4ef5
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
@@ -0,0 +1,70 @@
1
+ # RbZMQ
2
+
3
+ An opinionated ruby library wrapping [ffi-rzmq](https://github.com/chuckremes/ffi-rzmq) for more rubish flair.
4
+
5
+ *Library is still pre-release `0.x`. Everything may change anytime.*
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'rbzmq', '~> 0.1'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rbzmq
20
+
21
+ ## Usage
22
+
23
+ You can use RbZMQ's sockets just like in the [zguide](http://zguide.zeromq.org/) but without the need to handle a context. A global context will be used automagically.
24
+
25
+ ```ruby
26
+ require 'rbzmq'
27
+
28
+ writer = RbZMQ::Socket.new ZMQ::PUSH
29
+ writer.connect 'tcp://127.0.0.1:4237'
30
+
31
+ writer.send 'My Message!'
32
+ writer.send 'My Second Message!'
33
+
34
+ reader = RbZMQ::Socket.new ZMQ::PULL
35
+ reader.bind 'tcp://127.0.0.1:4237'
36
+
37
+ p reader.recv.to_s
38
+ p reader.recv.to_s
39
+
40
+ writer.close
41
+ reader.close
42
+ ```
43
+
44
+ See `examples/` for a growing number of translated examples from the zguide.
45
+
46
+ ## TODO
47
+
48
+ * RbZMQ::Reactor
49
+ * Pimp RbZMQ::Message
50
+ * Socket option accessors
51
+ * Class documentation w/ examples
52
+ * Translate zguide examples (and try to use them for auto testing)
53
+
54
+ ## Contributing
55
+
56
+ 1. Fork it (http://github.com/jgraichen/rbzmq/fork)
57
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
58
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
59
+ 4. Push to the branch (`git push origin my-new-feature`)
60
+ 5. Create new Pull Request
61
+
62
+ ## License
63
+
64
+ Copyright (C) 2014 Jan Graichen
65
+
66
+ This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
67
+
68
+ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
69
+
70
+ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -0,0 +1,125 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
+ <title>
7
+ File: README
8
+
9
+ &mdash; Documentation by YARD 0.8.7.3
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ hasFrames = window.top.frames.main ? true : false;
19
+ relpath = '';
20
+ framesUrl = "frames.html#!" + escape(window.location.href);
21
+ </script>
22
+
23
+
24
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
25
+
26
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
27
+
28
+
29
+ </head>
30
+ <body>
31
+ <div id="header">
32
+ <div id="menu">
33
+
34
+ <a href="_index.html">Index</a> &raquo;
35
+ <span class="title">File: README</span>
36
+
37
+
38
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
39
+ </div>
40
+
41
+ <div id="search">
42
+
43
+ <a class="full_list_link" id="class_list_link"
44
+ href="class_list.html">
45
+ Class List
46
+ </a>
47
+
48
+ <a class="full_list_link" id="method_list_link"
49
+ href="method_list.html">
50
+ Method List
51
+ </a>
52
+
53
+ <a class="full_list_link" id="file_list_link"
54
+ href="file_list.html">
55
+ File List
56
+ </a>
57
+
58
+ </div>
59
+ <div class="clear"></div>
60
+ </div>
61
+
62
+ <iframe id="search_frame"></iframe>
63
+
64
+ <div id="content"><div id='filecontents'><h1>RbZMQ</h1>
65
+
66
+ <p>TODO: Write a gem description</p>
67
+
68
+ <h2>Installation</h2>
69
+
70
+ <p>Add this line to your application&#39;s Gemfile:</p>
71
+
72
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>rbzmq</span><span class='tstring_end'>&#39;</span></span>
73
+ </code></pre>
74
+
75
+ <p>And then execute:</p>
76
+
77
+ <pre class="code ruby"><code class="ruby">$ bundle
78
+ </code></pre>
79
+
80
+ <p>Or install it yourself as:</p>
81
+
82
+ <pre class="code ruby"><code class="ruby">$ gem install rbzmq
83
+ </code></pre>
84
+
85
+ <h2>Usage</h2>
86
+
87
+ <p>You can use <span class='object_link'><a href="RbZMQ/Socket.html" title="RbZMQ::Socket (class)">RbZMQ::Socket</a></span>s just like in the Guide but without the need to handle a context. A global context will be used automagically.</p>
88
+
89
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>rbzmq</span><span class='tstring_end'>&#39;</span></span>
90
+
91
+ <span class='id identifier rubyid_writer'>writer</span> <span class='op'>=</span> <span class='const'>RbZMQ</span><span class='op'>::</span><span class='const'>Socket</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='const'>ZMQ</span><span class='op'>::</span><span class='const'>PUSH</span>
92
+ <span class='id identifier rubyid_writer'>writer</span><span class='period'>.</span><span class='id identifier rubyid_connect'>connect</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>tcp://127.0.0.1:4237</span><span class='tstring_end'>&#39;</span></span>
93
+
94
+ <span class='id identifier rubyid_writer'>writer</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>My Message!</span><span class='tstring_end'>&#39;</span></span>
95
+ <span class='id identifier rubyid_writer'>writer</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>My Second Message!</span><span class='tstring_end'>&#39;</span></span>
96
+
97
+ <span class='id identifier rubyid_reader'>reader</span> <span class='op'>=</span> <span class='const'>RbZMQ</span><span class='op'>::</span><span class='const'>Socket</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='const'>ZMQ</span><span class='op'>::</span><span class='const'>PULL</span>
98
+ <span class='id identifier rubyid_reader'>reader</span><span class='period'>.</span><span class='id identifier rubyid_bind'>bind</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>tcp://127.0.0.1:4237</span><span class='tstring_end'>&#39;</span></span>
99
+
100
+ <span class='id identifier rubyid_p'>p</span> <span class='id identifier rubyid_reader'>reader</span><span class='period'>.</span><span class='id identifier rubyid_recv'>recv</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span>
101
+ <span class='id identifier rubyid_p'>p</span> <span class='id identifier rubyid_reader'>reader</span><span class='period'>.</span><span class='id identifier rubyid_recv'>recv</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span>
102
+
103
+ <span class='id identifier rubyid_writer'>writer</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span>
104
+ <span class='id identifier rubyid_reader'>reader</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span>
105
+ </code></pre>
106
+
107
+ <h2>Contributing</h2>
108
+
109
+ <ol>
110
+ <li>Fork it ( <a href="http://github.com/jgraichen/rbzmq/fork">http://github.com/jgraichen/rbzmq/fork</a> )</li>
111
+ <li>Create your feature branch (<code>git checkout -b my-new-feature</code>)</li>
112
+ <li>Commit your changes (<code>git commit -am &#39;Add some feature&#39;</code>)</li>
113
+ <li>Push to the branch (<code>git push origin my-new-feature</code>)</li>
114
+ <li>Create new Pull Request</li>
115
+ </ol>
116
+ </div></div>
117
+
118
+ <div id="footer">
119
+ Generated on Sat Apr 5 12:32:58 2014 by
120
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
121
+ 0.8.7.3 (ruby-2.1.1).
122
+ </div>
123
+
124
+ </body>
125
+ </html>
@@ -0,0 +1,11 @@
1
+ require 'ffi-rzmq'
2
+ require 'rbzmq/version'
3
+
4
+ #
5
+ module RbZMQ
6
+ require 'rbzmq/context'
7
+ require 'rbzmq/errors'
8
+ require 'rbzmq/message'
9
+ require 'rbzmq/poller'
10
+ require 'rbzmq/socket'
11
+ end
@@ -0,0 +1,40 @@
1
+ module RbZMQ
2
+
3
+ class Context
4
+ # @!visibility private
5
+ #
6
+ # Internal `ZMQ::Context` reference.
7
+ #
8
+ attr_reader :zmq_ctx
9
+
10
+ # Create new context.
11
+ #
12
+ def initialize(opts = {})
13
+ @zmq_ctx = opts.delete(:context) { self.class.global }
14
+ end
15
+
16
+ # Return `FFI::Pointer` from `ZMQ::Context`.
17
+ #
18
+ # @return [FFI::Pointer] return
19
+ def pointer
20
+ zmq_ctx.pointer
21
+ end
22
+
23
+ class << self
24
+
25
+ # Return a process global ZMQ context that will be
26
+ # lazy initialized on first request.
27
+ #
28
+ # @return [ZMQ::Context]
29
+ #
30
+ def global
31
+ unless @zmq_ctx && @ctx_pid == Process.pid
32
+ @zmq_ctx = ZMQ::Context.new
33
+ @ctx_pid = Process.pid
34
+ end
35
+
36
+ @zmq_ctx
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,45 @@
1
+ module RbZMQ
2
+
3
+ class Error < StandardError
4
+ # noop
5
+ end
6
+
7
+ class ZMQError < Error
8
+ attr_reader :rc, :errno, :message
9
+
10
+ def initialize(rc, errno = nil, message = nil)
11
+ if ZMQ::ZeroMQError === rc
12
+ @rc = rc.result_code
13
+ @errno = rc.error_code
14
+ @message = rc.message =~ /msg\s+\[(.*?)\]/ ? $1 : 'Unknown'
15
+ else
16
+ @rc = rc
17
+ @errno = errno || ZMQ::Util.errno
18
+ @message = message || ZMQ::Util.error_string
19
+ end
20
+
21
+ super "[ERRNO #{@errno}, RC #{@rc}] #{@message}"
22
+ end
23
+
24
+ alias_method :error_code, :errno
25
+ alias_method :result_code, :rc
26
+
27
+ class << self
28
+ def error!(rc)
29
+ if error?(rc)
30
+ raise new(rc)
31
+ else
32
+ rc
33
+ end
34
+ end
35
+
36
+ def error?(rc)
37
+ -1 == rc
38
+ end
39
+
40
+ def ok?(rc)
41
+ !error? rc
42
+ end
43
+ end
44
+ end
45
+ end