posix_mq 0.5.0 → 0.5.1

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.
data/ChangeLog CHANGED
@@ -1,5 +1,22 @@
1
- ChangeLog from git://git.bogomips.org/ruby_posix_mq.git (v0.4.0..v0.5.0)
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.0
1
+ GIT_VERSION = 0.5.1
data/GIT-VERSION-GEN CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/bin/sh
2
2
 
3
3
  GVF=GIT-VERSION-FILE
4
- DEF_VER=v0.5.0.GIT
4
+ DEF_VER=v0.5.1.GIT
5
5
 
6
6
  LF='
7
7
  '
data/NEWS CHANGED
@@ -1,3 +1,8 @@
1
+ === 0.5.1 / 2010-05-09 08:10 UTC
2
+
3
+ Fix POSIX_MQ#notify(&block) usage, this regression was
4
+ introduced in 0.4.0 and our tests for it were broken, as well.
5
+
1
6
  === 0.5.0 / 2010-05-05 02:54 UTC
2
7
 
3
8
  Uncommonly raised exceptions due to programmer error are now
@@ -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
- * TODO: Under Linux, we could just use netlink directly
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
- if ((e = pthread_attr_init(&attr)))
746
- goto err;
747
- if ((e = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED)))
748
- goto err;
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
- not->sigev_notify = SIGEV_THREAD;
753
- not->sigev_notify_function = thread_notify_fd;
754
- not->sigev_notify_attributes = &attr;
755
- not->sigev_value.sival_int = fd;
756
- return;
757
- err:
758
- rb_raise(rb_eRuntimeError, "pthread failure: %s\n", strerror(e));
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, &not) < 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 = &not;
790
813
  VALUE rv = arg;
791
814
 
792
- if (!NIL_P(mq->thread)) {
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(&not, 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, "notify_thread=", setnotifythread, 1);
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.0
5
- VERSION = '0.5.0'
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.notify_thread = Thread.new(r, w, self) do |r, w, mq|
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.notify_thread = nil
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
 
@@ -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
- HAVE_TO_IO = if POSIX_MQ.instance_methods.grep(/\Ato_io\z/).empty?
12
+ METHODS.include?(:to_io) or
11
13
  warn "POSIX_MQ#to_io not supported on this platform: #{RUBY_PLATFORM}"
12
- false
13
- else
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 HAVE_TO_IO
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 HAVE_TO_IO
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 HAVE_TO_IO
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 HAVE_TO_IO
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 HAVE_TO_IO
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 POSIX_MQ, q.pop.class
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 POSIX_MQ.respond_to?(:notify)
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
- assert ! thr.alive?
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.0
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-05 00:00:00 +00:00
12
+ date: 2010-05-09 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies: []
15
15