posix_mq 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +18 -1
- data/GIT-VERSION-FILE +1 -1
- data/GIT-VERSION-GEN +1 -1
- data/NEWS +5 -0
- data/ext/posix_mq/posix_mq.c +43 -35
- data/lib/posix_mq.rb +5 -6
- data/test/test_posix_mq.rb +15 -18
- metadata +2 -2
data/ChangeLog
CHANGED
@@ -1,5 +1,22 @@
|
|
1
|
-
ChangeLog from git://git.bogomips.org/ruby_posix_mq.git (v0.4.0..v0.5.
|
1
|
+
ChangeLog from git://git.bogomips.org/ruby_posix_mq.git (v0.4.0..v0.5.1)
|
2
2
|
|
3
|
+
commit 3ca83d322486bb3da20d974af7faa74f9df891d8
|
4
|
+
Author: Eric Wong <normalperson@yhbt.net>
|
5
|
+
Date: Sun May 9 01:05:56 2010 -0700
|
6
|
+
|
7
|
+
posix_mq 0.5.1
|
8
|
+
|
9
|
+
Fix POSIX_MQ#notify(&block) usage, this regression was
|
10
|
+
introduced in 0.4.0 and our tests for it were broken, as well.
|
11
|
+
|
12
|
+
commit a997f4822a99590c7a5175be4a694b4482a4b997
|
13
|
+
Author: Eric Wong <normalperson@yhbt.net>
|
14
|
+
Date: Sun May 9 00:05:03 2010 -0700
|
15
|
+
|
16
|
+
fix POSIX_MQ#notify(&block) aka SIGEV_THREAD
|
17
|
+
|
18
|
+
tests for them were stupidly broken and never executed :x
|
19
|
+
|
3
20
|
commit f3605c820fd73713e34950170bf759e1af204038
|
4
21
|
Author: Eric Wong <normalperson@yhbt.net>
|
5
22
|
Date: Tue May 4 19:48:18 2010 -0700
|
data/GIT-VERSION-FILE
CHANGED
@@ -1 +1 @@
|
|
1
|
-
GIT_VERSION = 0.5.
|
1
|
+
GIT_VERSION = 0.5.1
|
data/GIT-VERSION-GEN
CHANGED
data/NEWS
CHANGED
data/ext/posix_mq/posix_mq.c
CHANGED
@@ -724,6 +724,10 @@ static int lookup_sig(VALUE sig)
|
|
724
724
|
return NUM2INT(sig);
|
725
725
|
}
|
726
726
|
|
727
|
+
/*
|
728
|
+
* TODO: Under Linux, we could just use netlink directly
|
729
|
+
* the same way glibc does...
|
730
|
+
*/
|
727
731
|
/* we spawn a thread just to write ONE byte into an fd (usually a pipe) */
|
728
732
|
static void thread_notify_fd(union sigval sv)
|
729
733
|
{
|
@@ -732,30 +736,49 @@ static void thread_notify_fd(union sigval sv)
|
|
732
736
|
while ((write(fd, "", 1) < 0) && (errno == EINTR || errno == EAGAIN));
|
733
737
|
}
|
734
738
|
|
735
|
-
/*
|
736
|
-
|
737
|
-
* the same way glibc does...
|
738
|
-
*/
|
739
|
-
static void setup_notify_io(struct sigevent *not, VALUE io)
|
739
|
+
/* :nodoc: */
|
740
|
+
static VALUE setnotify_exec(VALUE self, VALUE io, VALUE thr)
|
740
741
|
{
|
741
742
|
int fd = NUM2INT(rb_funcall(io, id_fileno, 0, 0));
|
743
|
+
struct posix_mq *mq = get(self, 1);
|
744
|
+
struct sigevent not;
|
742
745
|
pthread_attr_t attr;
|
743
|
-
int e;
|
744
746
|
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
747
|
+
errno = pthread_attr_init(&attr);
|
748
|
+
if (errno) rb_sys_fail("pthread_attr_init");
|
749
|
+
|
750
|
+
errno = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
751
|
+
if (errno) rb_sys_fail("pthread_attr_setdetachstate");
|
752
|
+
|
749
753
|
#ifdef PTHREAD_STACK_MIN
|
750
754
|
(void)pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN);
|
751
755
|
#endif
|
752
|
-
|
753
|
-
not
|
754
|
-
not
|
755
|
-
not
|
756
|
-
|
757
|
-
|
758
|
-
|
756
|
+
|
757
|
+
not.sigev_notify = SIGEV_THREAD;
|
758
|
+
not.sigev_notify_function = thread_notify_fd;
|
759
|
+
not.sigev_notify_attributes = &attr;
|
760
|
+
not.sigev_value.sival_int = fd;
|
761
|
+
|
762
|
+
if (!NIL_P(mq->thread))
|
763
|
+
rb_funcall(mq->thread, id_kill, 0, 0);
|
764
|
+
mq->thread = thr;
|
765
|
+
|
766
|
+
if (mq_notify(mq->des, ¬) < 0)
|
767
|
+
rb_sys_fail("mq_notify");
|
768
|
+
|
769
|
+
return thr;
|
770
|
+
}
|
771
|
+
|
772
|
+
/* :nodoc: */
|
773
|
+
static VALUE notify_cleanup(VALUE self)
|
774
|
+
{
|
775
|
+
struct posix_mq *mq = get(self, 1);
|
776
|
+
|
777
|
+
if (!NIL_P(mq->thread)) {
|
778
|
+
rb_funcall(mq->thread, id_kill, 0, 0);
|
779
|
+
mq->thread = Qnil;
|
780
|
+
}
|
781
|
+
return Qnil;
|
759
782
|
}
|
760
783
|
|
761
784
|
/*
|
@@ -789,10 +812,7 @@ static VALUE setnotify(VALUE self, VALUE arg)
|
|
789
812
|
struct sigevent * notification = ¬
|
790
813
|
VALUE rv = arg;
|
791
814
|
|
792
|
-
|
793
|
-
rb_funcall(mq->thread, id_kill, 0, 0);
|
794
|
-
mq->thread = Qnil;
|
795
|
-
}
|
815
|
+
notify_cleanup(self);
|
796
816
|
not.sigev_notify = SIGEV_SIGNAL;
|
797
817
|
|
798
818
|
switch (TYPE(arg)) {
|
@@ -810,11 +830,7 @@ static VALUE setnotify(VALUE self, VALUE arg)
|
|
810
830
|
not.sigev_signo = lookup_sig(arg);
|
811
831
|
rv = INT2NUM(not.sigev_signo);
|
812
832
|
break;
|
813
|
-
case T_FILE:
|
814
|
-
setup_notify_io(¬, arg);
|
815
|
-
break;
|
816
833
|
default:
|
817
|
-
/* maybe support Proc+thread via sigev_notify_function.. */
|
818
834
|
rb_raise(rb_eArgError, "must be a signal or nil");
|
819
835
|
}
|
820
836
|
|
@@ -866,15 +882,6 @@ static VALUE setnonblock(VALUE self, VALUE nb)
|
|
866
882
|
return nb;
|
867
883
|
}
|
868
884
|
|
869
|
-
/* :nodoc: */
|
870
|
-
static VALUE setnotifythread(VALUE self, VALUE thread)
|
871
|
-
{
|
872
|
-
struct posix_mq *mq = get(self, 1);
|
873
|
-
|
874
|
-
mq->thread = thread;
|
875
|
-
return thread;
|
876
|
-
}
|
877
|
-
|
878
885
|
void Init_posix_mq_ext(void)
|
879
886
|
{
|
880
887
|
cPOSIX_MQ = rb_define_class("POSIX_MQ", rb_cObject);
|
@@ -914,7 +921,8 @@ void Init_posix_mq_ext(void)
|
|
914
921
|
rb_define_method(cPOSIX_MQ, "name", name, 0);
|
915
922
|
rb_define_method(cPOSIX_MQ, "notify=", setnotify, 1);
|
916
923
|
rb_define_method(cPOSIX_MQ, "nonblock=", setnonblock, 1);
|
917
|
-
rb_define_method(cPOSIX_MQ, "
|
924
|
+
rb_define_method(cPOSIX_MQ, "notify_exec", setnotify_exec, 2);
|
925
|
+
rb_define_method(cPOSIX_MQ, "notify_cleanup", notify_cleanup, 0);
|
918
926
|
rb_define_method(cPOSIX_MQ, "nonblock?", getnonblock, 0);
|
919
927
|
#ifdef MQD_TO_FD
|
920
928
|
rb_define_method(cPOSIX_MQ, "to_io", to_io, 0);
|
data/lib/posix_mq.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# -*- encoding: binary -*-
|
2
2
|
class POSIX_MQ
|
3
3
|
|
4
|
-
# version of POSIX_MQ, currently 0.5.
|
5
|
-
VERSION = '0.5.
|
4
|
+
# version of POSIX_MQ, currently 0.5.1
|
5
|
+
VERSION = '0.5.1'
|
6
6
|
|
7
7
|
# An analogous Struct to "struct mq_attr" in C.
|
8
8
|
# This may be used in arguments for POSIX_MQ.new and
|
@@ -47,7 +47,7 @@ class POSIX_MQ
|
|
47
47
|
block.arity == 1 or
|
48
48
|
raise ArgumentError, "arity of notify block must be 1"
|
49
49
|
r, w = IO.pipe
|
50
|
-
self.
|
50
|
+
self.notify_exec(w, Thread.new(r, w, self) do |r, w, mq|
|
51
51
|
begin
|
52
52
|
begin
|
53
53
|
r.read(1) or raise Errno::EINTR
|
@@ -56,12 +56,11 @@ class POSIX_MQ
|
|
56
56
|
end
|
57
57
|
block.call(mq)
|
58
58
|
ensure
|
59
|
-
mq.
|
59
|
+
mq.notify_cleanup
|
60
60
|
r.close rescue nil
|
61
61
|
w.close rescue nil
|
62
62
|
end
|
63
|
-
end
|
64
|
-
self.notify = w
|
63
|
+
end)
|
65
64
|
nil
|
66
65
|
end if RUBY_PLATFORM =~ /linux/
|
67
66
|
|
data/test/test_posix_mq.rb
CHANGED
@@ -3,16 +3,16 @@ require 'test/unit'
|
|
3
3
|
require 'posix_mq'
|
4
4
|
require 'thread'
|
5
5
|
require 'fcntl'
|
6
|
+
require 'set'
|
6
7
|
$stderr.sync = $stdout.sync = true
|
7
8
|
|
8
9
|
class Test_POSIX_MQ < Test::Unit::TestCase
|
10
|
+
METHODS = Set.new(POSIX_MQ.instance_methods.map { |x| x.to_sym })
|
9
11
|
|
10
|
-
|
12
|
+
METHODS.include?(:to_io) or
|
11
13
|
warn "POSIX_MQ#to_io not supported on this platform: #{RUBY_PLATFORM}"
|
12
|
-
|
13
|
-
|
14
|
-
true
|
15
|
-
end
|
14
|
+
METHODS.include?(:notify) or
|
15
|
+
warn "POSIX_MQ#notify not supported on this platform: #{RUBY_PLATFORM}"
|
16
16
|
|
17
17
|
def setup
|
18
18
|
@mq = nil
|
@@ -155,7 +155,7 @@ class Test_POSIX_MQ < Test::Unit::TestCase
|
|
155
155
|
@mq = POSIX_MQ.new @path, IO::CREAT|IO::RDWR, 0666
|
156
156
|
assert @mq.to_io.kind_of?(IO)
|
157
157
|
assert_nothing_raised { IO.select([@mq], nil, nil, 0) }
|
158
|
-
end if
|
158
|
+
end if METHODS.include?(:to_io)
|
159
159
|
|
160
160
|
def test_notify
|
161
161
|
rd, wr = IO.pipe
|
@@ -224,7 +224,7 @@ class Test_POSIX_MQ < Test::Unit::TestCase
|
|
224
224
|
def test_new_sym_w
|
225
225
|
@mq = POSIX_MQ.new @path, :w
|
226
226
|
assert_equal IO::WRONLY, @mq.to_io.fcntl(Fcntl::F_GETFL)
|
227
|
-
end if
|
227
|
+
end if METHODS.include?(:to_io)
|
228
228
|
|
229
229
|
def test_new_sym_r
|
230
230
|
@mq = POSIX_MQ.new @path, :w
|
@@ -232,7 +232,7 @@ class Test_POSIX_MQ < Test::Unit::TestCase
|
|
232
232
|
assert_nothing_raised { mq = POSIX_MQ.new @path, :r }
|
233
233
|
assert_equal IO::RDONLY, mq.to_io.fcntl(Fcntl::F_GETFL)
|
234
234
|
assert_nil mq.close
|
235
|
-
end if
|
235
|
+
end if METHODS.include?(:to_io)
|
236
236
|
|
237
237
|
def test_new_path_only
|
238
238
|
@mq = POSIX_MQ.new @path, :w
|
@@ -240,12 +240,12 @@ class Test_POSIX_MQ < Test::Unit::TestCase
|
|
240
240
|
assert_nothing_raised { mq = POSIX_MQ.new @path }
|
241
241
|
assert_equal IO::RDONLY, mq.to_io.fcntl(Fcntl::F_GETFL)
|
242
242
|
assert_nil mq.close
|
243
|
-
end if
|
243
|
+
end if METHODS.include?(:to_io)
|
244
244
|
|
245
245
|
def test_new_sym_wr
|
246
246
|
@mq = POSIX_MQ.new @path, :rw
|
247
247
|
assert_equal IO::RDWR, @mq.to_io.fcntl(Fcntl::F_GETFL)
|
248
|
-
end if
|
248
|
+
end if METHODS.include?(:to_io)
|
249
249
|
|
250
250
|
def test_new_attr
|
251
251
|
mq_attr = POSIX_MQ::Attr.new(IO::NONBLOCK, 1, 1, 0)
|
@@ -274,24 +274,21 @@ class Test_POSIX_MQ < Test::Unit::TestCase
|
|
274
274
|
q = Queue.new
|
275
275
|
@mq = POSIX_MQ.new(@path, :rw)
|
276
276
|
assert_nothing_raised { @mq.notify { |mq| q << mq } }
|
277
|
-
@mq << "hi"
|
278
|
-
assert_equal
|
277
|
+
assert_nothing_raised { Process.waitpid2(fork { @mq << "hi" }) }
|
278
|
+
assert_equal @mq.object_id, q.pop.object_id
|
279
279
|
assert_equal "hi", @mq.receive.first
|
280
280
|
assert_nothing_raised { @mq.notify { |mq| q << "hi" } }
|
281
|
-
@mq << "bye"
|
281
|
+
assert_nothing_raised { Process.waitpid2(fork { @mq << "bye" }) }
|
282
282
|
assert_equal "hi", q.pop
|
283
|
-
end if
|
283
|
+
end if METHODS.include?(:notify)
|
284
284
|
|
285
285
|
def test_notify_thread
|
286
286
|
q = Queue.new
|
287
287
|
@mq = POSIX_MQ.new(@path, :rw)
|
288
|
-
@mq.notify_thread = thr = Thread.new { sleep }
|
289
|
-
assert thr.alive?
|
290
288
|
@mq.notify { |mq| q << Thread.current }
|
291
289
|
@mq << "."
|
292
290
|
x = q.pop
|
293
291
|
assert x.instance_of?(Thread)
|
294
292
|
assert Thread.current != x
|
295
|
-
|
296
|
-
end if POSIX_MQ.respond_to?(:notify)
|
293
|
+
end if METHODS.include?(:notify)
|
297
294
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: posix_mq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ruby POSIX MQ hackers
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-05-
|
12
|
+
date: 2010-05-09 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|