posix-mqueue 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/posix/mqueue.c +53 -18
- data/lib/posix/mqueue/version.rb +1 -1
- data/test/mqueue_test.rb +5 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5823cff6537672e41ae0166a4107bc262f6f5dc2
|
4
|
+
data.tar.gz: 00686b89630f12eed8b9d701417fda1e43825ea4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f00ad53969f1edd82ffc56275ff7994d55991dfd52fb772f11493861e8d6cac68cfa0b38ce1ccc211464f319283ea75c98db3083baf4a875bfac39b5d6d86a83
|
7
|
+
data.tar.gz: 1eb694b40bc7c4ccd1c82797b59ac1834adcbb923d94bd0dc4592613fb82b7cea962a7f43c81f08c0fa8907dd9ae40d1e9d34132b4f447d9eb1d574843f5cf59
|
data/ext/posix/mqueue.c
CHANGED
@@ -15,6 +15,7 @@ VALUE rb_cQueueEmpty = Qnil;
|
|
15
15
|
|
16
16
|
typedef struct {
|
17
17
|
mqd_t fd;
|
18
|
+
VALUE io;
|
18
19
|
struct mq_attr attr;
|
19
20
|
size_t queue_len;
|
20
21
|
char *queue;
|
@@ -24,6 +25,8 @@ mqueue_t;
|
|
24
25
|
static void
|
25
26
|
mqueue_mark(void* ptr)
|
26
27
|
{
|
28
|
+
mqueue_t* data = ptr;
|
29
|
+
rb_gc_mark(data->io);
|
27
30
|
(void)ptr;
|
28
31
|
}
|
29
32
|
|
@@ -33,6 +36,8 @@ mqueue_free(void* ptr)
|
|
33
36
|
mqueue_t* data = ptr;
|
34
37
|
mq_close(data->fd);
|
35
38
|
xfree(data->queue);
|
39
|
+
// ??
|
40
|
+
// xfree(data->io);
|
36
41
|
xfree(ptr);
|
37
42
|
}
|
38
43
|
|
@@ -86,8 +91,8 @@ VALUE posix_mqueue_send(VALUE self, VALUE message)
|
|
86
91
|
|
87
92
|
TypedData_Get_Struct(self, mqueue_t, &mqueue_type, data);
|
88
93
|
|
89
|
-
if (!RB_TYPE_P(message, T_STRING)) {
|
90
|
-
rb_raise(rb_eTypeError, "Message must be a string");
|
94
|
+
if (!RB_TYPE_P(message, T_STRING)) {
|
95
|
+
rb_raise(rb_eTypeError, "Message must be a string");
|
91
96
|
}
|
92
97
|
|
93
98
|
rb_io_wait_writable(data->fd);
|
@@ -102,7 +107,7 @@ VALUE posix_mqueue_send(VALUE self, VALUE message)
|
|
102
107
|
if (err < 0) {
|
103
108
|
rb_sys_fail("Message sending failed, please consult mq_send(3)");
|
104
109
|
}
|
105
|
-
|
110
|
+
|
106
111
|
return Qtrue;
|
107
112
|
}
|
108
113
|
|
@@ -122,12 +127,12 @@ VALUE posix_mqueue_timedreceive(VALUE self, VALUE args)
|
|
122
127
|
|
123
128
|
TypedData_Get_Struct(self, mqueue_t, &mqueue_type, data);
|
124
129
|
|
125
|
-
if (!RB_TYPE_P(seconds, T_FIXNUM)) {
|
126
|
-
rb_raise(rb_eTypeError, "First argument must be a Fixnum");
|
130
|
+
if (!RB_TYPE_P(seconds, T_FIXNUM)) {
|
131
|
+
rb_raise(rb_eTypeError, "First argument must be a Fixnum");
|
127
132
|
}
|
128
133
|
|
129
|
-
if (!RB_TYPE_P(nanoseconds, T_FIXNUM)) {
|
130
|
-
rb_raise(rb_eTypeError, "Second argument must be a Fixnum");
|
134
|
+
if (!RB_TYPE_P(nanoseconds, T_FIXNUM)) {
|
135
|
+
rb_raise(rb_eTypeError, "Second argument must be a Fixnum");
|
131
136
|
}
|
132
137
|
|
133
138
|
timeout.tv_sec = FIX2ULONG(seconds);
|
@@ -169,16 +174,16 @@ VALUE posix_mqueue_timedsend(VALUE self, VALUE args)
|
|
169
174
|
|
170
175
|
TypedData_Get_Struct(self, mqueue_t, &mqueue_type, data);
|
171
176
|
|
172
|
-
if (!RB_TYPE_P(message, T_STRING)) {
|
173
|
-
rb_raise(rb_eTypeError, "Message must be a string");
|
177
|
+
if (!RB_TYPE_P(message, T_STRING)) {
|
178
|
+
rb_raise(rb_eTypeError, "Message must be a string");
|
174
179
|
}
|
175
180
|
|
176
181
|
if (!RB_TYPE_P(seconds, T_FIXNUM)) {
|
177
|
-
rb_raise(rb_eTypeError, "First argument must be a Fixnum");
|
182
|
+
rb_raise(rb_eTypeError, "First argument must be a Fixnum");
|
178
183
|
}
|
179
184
|
|
180
|
-
if (!RB_TYPE_P(nanoseconds, T_FIXNUM)) {
|
181
|
-
rb_raise(rb_eTypeError, "Second argument must be a Fixnum");
|
185
|
+
if (!RB_TYPE_P(nanoseconds, T_FIXNUM)) {
|
186
|
+
rb_raise(rb_eTypeError, "Second argument must be a Fixnum");
|
182
187
|
}
|
183
188
|
|
184
189
|
timeout.tv_sec = FIX2ULONG(seconds);
|
@@ -193,7 +198,7 @@ VALUE posix_mqueue_timedsend(VALUE self, VALUE args)
|
|
193
198
|
rb_sys_fail("Message sending failed, please consult mq_send(3)");
|
194
199
|
}
|
195
200
|
}
|
196
|
-
|
201
|
+
|
197
202
|
return Qtrue;
|
198
203
|
}
|
199
204
|
|
@@ -211,6 +216,14 @@ VALUE posix_mqueue_size(VALUE self)
|
|
211
216
|
return INT2FIX(queue.mq_curmsgs);
|
212
217
|
}
|
213
218
|
|
219
|
+
VALUE posix_mqueue_to_io(VALUE self)
|
220
|
+
{
|
221
|
+
mqueue_t* data;
|
222
|
+
TypedData_Get_Struct(self, mqueue_t, &mqueue_type, data);
|
223
|
+
|
224
|
+
return data->io;
|
225
|
+
}
|
226
|
+
|
214
227
|
VALUE posix_mqueue_msgsize(VALUE self)
|
215
228
|
{
|
216
229
|
mqueue_t* data;
|
@@ -259,14 +272,30 @@ VALUE posix_mqueue_receive(VALUE self)
|
|
259
272
|
return str;
|
260
273
|
}
|
261
274
|
|
262
|
-
VALUE posix_mqueue_initialize(VALUE
|
275
|
+
VALUE posix_mqueue_initialize(int argc, VALUE* argv, VALUE self)
|
263
276
|
{
|
264
|
-
|
265
|
-
|
277
|
+
if(argc < 1)
|
278
|
+
{
|
279
|
+
rb_raise(rb_eArgError, "initialize requires at least one argument");
|
280
|
+
}
|
281
|
+
|
282
|
+
VALUE queue = argv[0];
|
283
|
+
if (!RB_TYPE_P(queue, T_STRING)) {
|
284
|
+
rb_raise(rb_eTypeError, "Queue name must be a string");
|
285
|
+
}
|
286
|
+
|
287
|
+
VALUE options;
|
288
|
+
if (argc < 2)
|
289
|
+
{
|
290
|
+
options = rb_hash_new();
|
291
|
+
}
|
292
|
+
else
|
293
|
+
{
|
294
|
+
options = argv[1];
|
295
|
+
}
|
266
296
|
|
267
297
|
int msgsize = FIX2INT(rb_hash_lookup2(options, ID2SYM(rb_intern("msgsize")), INT2FIX(4096)));
|
268
298
|
int maxmsg = FIX2INT(rb_hash_lookup2(options, ID2SYM(rb_intern("maxmsg")), INT2FIX(10)));
|
269
|
-
VALUE queue = rb_ary_entry(args, 0);
|
270
299
|
|
271
300
|
struct mq_attr attr = {
|
272
301
|
.mq_flags = 0, // Flags, 0 or O_NONBLOCK
|
@@ -292,6 +321,11 @@ VALUE posix_mqueue_initialize(VALUE self, VALUE args)
|
|
292
321
|
rb_sys_fail("Failed opening the message queue, please consult mq_open(3)");
|
293
322
|
}
|
294
323
|
|
324
|
+
VALUE args[1];
|
325
|
+
args[0] = INT2FIX(data->fd);
|
326
|
+
|
327
|
+
data->io = rb_class_new_instance(1, args, rb_path2class("IO"));
|
328
|
+
|
295
329
|
return self;
|
296
330
|
}
|
297
331
|
|
@@ -303,7 +337,7 @@ void Init_mqueue()
|
|
303
337
|
rb_cQueueEmpty = rb_define_class_under(mqueue, "QueueEmpty", rb_eStandardError);
|
304
338
|
|
305
339
|
rb_define_alloc_func(mqueue, posix_mqueue_alloc);
|
306
|
-
rb_define_method(mqueue, "initialize", posix_mqueue_initialize, -
|
340
|
+
rb_define_method(mqueue, "initialize", posix_mqueue_initialize, -1);
|
307
341
|
rb_define_method(mqueue, "send", posix_mqueue_send, 1);
|
308
342
|
rb_define_method(mqueue, "receive", posix_mqueue_receive, 0);
|
309
343
|
rb_define_method(mqueue, "timedsend", posix_mqueue_timedsend, -2);
|
@@ -311,5 +345,6 @@ void Init_mqueue()
|
|
311
345
|
rb_define_method(mqueue, "msgsize", posix_mqueue_msgsize, 0);
|
312
346
|
rb_define_method(mqueue, "size", posix_mqueue_size, 0);
|
313
347
|
rb_define_method(mqueue, "unlink", posix_mqueue_unlink, 0);
|
348
|
+
rb_define_method(mqueue, "to_io", posix_mqueue_to_io, 0);
|
314
349
|
}
|
315
350
|
|
data/lib/posix/mqueue/version.rb
CHANGED
data/test/mqueue_test.rb
CHANGED
@@ -71,7 +71,7 @@ class MqueueTest < MiniTest::Unit::TestCase
|
|
71
71
|
|
72
72
|
# Set to the maximum for Linux
|
73
73
|
with_queue "/big-queue", msgsize: 2 ** 13 do |q|
|
74
|
-
assert_equal 2 ** 13, q.
|
74
|
+
assert_equal 2 ** 13, q.msgsize
|
75
75
|
|
76
76
|
q.send('c' * (2 ** 13))
|
77
77
|
end
|
@@ -97,6 +97,10 @@ class MqueueTest < MiniTest::Unit::TestCase
|
|
97
97
|
assert_equal 3, @queue.size
|
98
98
|
end
|
99
99
|
|
100
|
+
def test_to_io
|
101
|
+
assert_instance_of IO, @queue.to_io
|
102
|
+
end
|
103
|
+
|
100
104
|
private
|
101
105
|
def with_queue(name, options = {})
|
102
106
|
queue = POSIX::Mqueue.new(name, options)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: posix-mqueue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Eskildsen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|