posix_mq 1.0.0 → 2.0.0

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,118 @@
1
1
  ChangeLog from http://bogomips.org/ruby_posix_mq.git
2
2
 
3
+ commit 86f36a2d88aca8fdef45fd2a757f98a593935ba9
4
+ Author: Eric Wong <normalperson@yhbt.net>
5
+ Date: Mon Aug 6 20:58:04 2012 +0000
6
+
7
+ posix_mq 2.0.0 - a minor API change + FreeBSD fixes
8
+
9
+ Blocking methods no longer raise Errno::EINTR (to match
10
+ Ruby IO semantics, making code easier to work with).
11
+
12
+ There are also many FreeBSD-related fixes thanks to
13
+ Hleb Valoshka <375gnu@gmail.com> and small code cleanups.
14
+
15
+ commit a7fc8eea6fbe774d289676ac197972d8fb6c41f4
16
+ Author: ew@fbsd90-32.(none) <ew@fbsd90-32.(none)>
17
+ Date: Wed Jul 11 02:54:33 2012 +0000
18
+
19
+ test: relax test timings for timed* tests
20
+
21
+ On my i386-freebsd9 VM, this takes just longer than the
22
+ maximum allowable time.
23
+
24
+ commit abbe5f16a9c3e17a9a6bab39bb105dc655e55eb6
25
+ Author: ew@fbsd90-32.(none) <ew@fbsd90-32.(none)>
26
+ Date: Wed Jul 11 02:25:44 2012 +0000
27
+
28
+ extconf: fix __mq_oshandle() detection on FreeBSD
29
+
30
+ We need to have -lrt in LDFLAGS before we can detect it.
31
+
32
+ commit 00b84b3d2d9bec7ed480a0715408148af0a0d057
33
+ Author: ew@fbsd90-32.(none) <ew@fbsd90-32.(none)>
34
+ Date: Wed Jul 11 02:02:43 2012 +0000
35
+
36
+ test: disable IO.select test if #to_io is missing
37
+
38
+ commit 78c63761660a96f96e8f465c4cecedd803df9afe
39
+ Author: ew@fbsd90-32.(none) <ew@fbsd90-32.(none)>
40
+ Date: Wed Jul 11 01:58:57 2012 +0000
41
+
42
+ ext: fix type inconsistencies for int vs mqd_t retvals
43
+
44
+ Somehow I mixed up return values for mq_* functions that
45
+ return "int". This was noticed on FreeBSD where mqd_t
46
+ is NOT an integer.
47
+
48
+ commit dc05c43b65460d72ae45164f61e327d715a6e954
49
+ Author: Eric Wong <normalperson@yhbt.net>
50
+ Date: Thu Jul 12 12:30:20 2012 -0700
51
+
52
+ notify: set lower bound for notify stack size
53
+
54
+ Some OSes have ridiculously low boundaries and we don't
55
+ want mysterious failures on them
56
+
57
+ commit 73dfbeb1d59fbc1e22651cb4da8ee85f0a6fd9ce
58
+ Author: Eric Wong <normalperson@yhbt.net>
59
+ Date: Tue Jul 3 17:57:44 2012 -0700
60
+
61
+ blocking functions do not raise Errno::EINTR
62
+
63
+ Blocking functions should not raise Errno::EINTR to match
64
+ existing semantics of Ruby IO methods (e.g. IO.select, IO#read,
65
+ IO#write). This makes user code easier to read/write.
66
+
67
+ Like th Ruby methods we emulate, we only reacquire the GVL on
68
+ EINTR to fire signal handlers, but otherwise emulate SA_RESTART
69
+ semantics.
70
+
71
+ This is a backwards-incompatible API change (but unlikely
72
+ to break existing code).
73
+
74
+ commit cf0665e57bf4857d4eb4c733527e77545190af59
75
+ Author: Hleb Valoshka <375gnu@gmail.com>
76
+ Date: Tue Jul 3 23:13:49 2012 +0300
77
+
78
+ Add libc names for Debian GNU/kFreeBSD and FreeBSD in tests.
79
+
80
+ Signed-off-by: Eric Wong <normalperson@yhbt.net>
81
+
82
+ commit 5e49637bdc37eb11b9d30863e8ba07a29e2948fe
83
+ Author: Hleb Valoshka <375gnu@gmail.com>
84
+ Date: Tue Jul 3 23:13:48 2012 +0300
85
+
86
+ Fix call to DL::Function.new in tests
87
+
88
+ The 3rd argument of DL::Function.new is ABI type, not a return type.
89
+
90
+ Signed-off-by: Eric Wong <normalperson@yhbt.net>
91
+
92
+ commit 3ae56d273aaa871a328ab5275f5700fa396dad03
93
+ Author: Eric Wong <normalperson@yhbt.net>
94
+ Date: Thu Jun 16 07:41:48 2011 +0000
95
+
96
+ fix compiler warnings, oops
97
+
98
+ CFLAGS=-Wall somehow got disabled in my Ruby installation...
99
+
100
+ commit b5bee9559dadcbe6a5669faac98d3201954c0606
101
+ Author: Eric Wong <normalperson@yhbt.net>
102
+ Date: Tue Jun 14 07:44:18 2011 +0000
103
+
104
+ num2timespec: remove needless double-assignment
105
+
106
+ Oops
107
+
108
+ commit 67d7da847965079367c325b876ed36e7bc5e25c1
109
+ Author: Eric Wong <normalperson@yhbt.net>
110
+ Date: Tue Jun 14 07:21:25 2011 +0000
111
+
112
+ no need to rb_intern("*")
113
+
114
+ '*' works just the same
115
+
3
116
  commit 90b66d0a4390e7794247d43b49160a50a9028caa
4
117
  Author: Eric Wong <normalperson@yhbt.net>
5
118
  Date: Tue Mar 1 09:07:05 2011 +0000
data/GIT-VERSION-FILE CHANGED
@@ -1 +1 @@
1
- GIT_VERSION = 1.0.0
1
+ GIT_VERSION = 2.0.0
data/GIT-VERSION-GEN CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/bin/sh
2
2
 
3
3
  GVF=GIT-VERSION-FILE
4
- DEF_VER=v1.0.0.GIT
4
+ DEF_VER=v2.0.0.GIT
5
5
 
6
6
  LF='
7
7
  '
data/LATEST CHANGED
@@ -1,17 +1,8 @@
1
- === posix_mq 1.0.0 - kinder, gentler message queues / 2011-03-01 09:17 UTC
1
+ === posix_mq 2.0.0 - a minor API change + FreeBSD fixes / 2012-08-06 21:02 UTC
2
2
 
3
- There is one backwards-incompatible API change:
3
+ Blocking methods no longer raise Errno::EINTR (to match
4
+ Ruby IO semantics, making code easier to work with).
4
5
 
5
- POSIX_MQ#send returns +true+ on success instead of +nil+
6
- for consistency with POSIX_MQ#trysend.
7
-
8
- This release adds the POSIX_MQ#trysend, POSIX_MQ#tryreceive and
9
- POSIX_MQ#tryshift interfaces to avoid exceptions on common
10
- EAGAIN errors for users of non-blocking queues.
11
-
12
- Bugfixes: non-blocking behavior changes to a shared descriptor
13
- in a different process are reflected immediately in the child
14
- (this won't fix race conditions in your code, however).
15
- Minor bugfixes for posix-mq-rb(1) and quieted warnings for
16
- 1.9.3dev.
6
+ There are also many FreeBSD-related fixes thanks to
7
+ Hleb Valoshka <375gnu@gmail.com> and small code cleanups.
17
8
 
data/NEWS CHANGED
@@ -1,3 +1,11 @@
1
+ === posix_mq 2.0.0 - a minor API change + FreeBSD fixes / 2012-08-06 21:02 UTC
2
+
3
+ Blocking methods no longer raise Errno::EINTR (to match
4
+ Ruby IO semantics, making code easier to work with).
5
+
6
+ There are also many FreeBSD-related fixes thanks to
7
+ Hleb Valoshka <375gnu@gmail.com> and small code cleanups.
8
+
1
9
  === posix_mq 1.0.0 - kinder, gentler message queues / 2011-03-01 09:17 UTC
2
10
 
3
11
  There is one backwards-incompatible API change:
@@ -141,8 +149,7 @@
141
149
  functionality. Under FreeBSD, using IO.select on POSIX_MQ
142
150
  objects is now possible as it has always been under Linux.
143
151
 
144
- === posix_mq 0.1.0 - initial release
145
- / 2010-01-02 11:01 UTC
152
+ === posix_mq 0.1.0 - initial release / 2010-01-02 11:01 UTC
146
153
 
147
154
  initial
148
155
 
@@ -3,7 +3,6 @@ require "mkmf"
3
3
  have_header("sys/select.h")
4
4
  have_header("signal.h")
5
5
  have_header("mqueue.h") or abort "mqueue.h header missing"
6
- have_func("__mq_oshandle")
7
6
  have_header("pthread.h")
8
7
  have_func("rb_str_set_len")
9
8
  have_func('rb_thread_blocking_region')
@@ -11,6 +10,7 @@ have_library("m")
11
10
  have_library("rt")
12
11
  have_library("pthread")
13
12
 
13
+ have_func("__mq_oshandle")
14
14
  have_func("mq_timedsend")
15
15
  have_func("mq_timedreceive")
16
16
  create_makefile("posix_mq_ext")
@@ -66,7 +66,7 @@ static int MQ_IO_CLOSE(struct posix_mq *mq)
66
66
  # define PMQ_TRY (1<<1)
67
67
 
68
68
  static VALUE cAttr;
69
- static ID id_new, id_kill, id_fileno, id_mul, id_divmod;
69
+ static ID id_new, id_kill, id_fileno, id_divmod;
70
70
  static ID id_flags, id_maxmsg, id_msgsize, id_curmsgs;
71
71
  static VALUE sym_r, sym_w, sym_rw;
72
72
  static const mqd_t MQD_INVALID = (mqd_t)-1;
@@ -185,7 +185,6 @@ static void num2timespec(struct timespec *ts, VALUE t)
185
185
  ts->tv_sec = (time_t)f;
186
186
  if (f != ts->tv_sec)
187
187
  rb_raise(rb_eRangeError, "%f out of range", val);
188
- ts->tv_sec = (time_t)f;
189
188
  }
190
189
  break;
191
190
  default: {
@@ -196,7 +195,7 @@ static void num2timespec(struct timespec *ts, VALUE t)
196
195
 
197
196
  ts->tv_sec = NUM2TIMET(rb_ary_entry(ary, 0));
198
197
  f = rb_ary_entry(ary, 1);
199
- f = rb_funcall(f, id_mul, 1, INT2FIX(1000000000));
198
+ f = rb_funcall(f, '*', 1, INT2FIX(1000000000));
200
199
  ts->tv_nsec = NUM2LONG(f);
201
200
  }
202
201
  }
@@ -469,9 +468,9 @@ static VALUE init(int argc, VALUE *argv, VALUE self)
469
468
  */
470
469
  static VALUE s_unlink(VALUE self, VALUE name)
471
470
  {
472
- mqd_t rv = mq_unlink(StringValueCStr(name));
471
+ int rv = mq_unlink(StringValueCStr(name));
473
472
 
474
- if (rv == MQD_INVALID)
473
+ if (rv == -1)
475
474
  rb_sys_fail("mq_unlink");
476
475
 
477
476
  return INT2NUM(1);
@@ -490,12 +489,12 @@ static VALUE s_unlink(VALUE self, VALUE name)
490
489
  static VALUE _unlink(VALUE self)
491
490
  {
492
491
  struct posix_mq *mq = get(self, 0);
493
- mqd_t rv;
492
+ int rv;
494
493
 
495
494
  assert(TYPE(mq->name) == T_STRING && "mq->name is not a string");
496
495
 
497
496
  rv = mq_unlink(RSTRING_PTR(mq->name));
498
- if (rv == MQD_INVALID)
497
+ if (rv == -1)
499
498
  rb_sys_fail("mq_unlink");
500
499
 
501
500
  return self;
@@ -533,7 +532,7 @@ static VALUE _send(int sflags, int argc, VALUE *argv, VALUE self)
533
532
  struct posix_mq *mq = get(self, 1);
534
533
  struct rw_args x;
535
534
  VALUE buffer, prio, timeout;
536
- mqd_t rv;
535
+ int rv;
537
536
  struct timespec expire;
538
537
 
539
538
  rb_scan_args(argc, argv, "12", &buffer, &prio, &timeout);
@@ -543,8 +542,11 @@ static VALUE _send(int sflags, int argc, VALUE *argv, VALUE self)
543
542
  x.timeout = convert_timeout(&expire, timeout);
544
543
  x.msg_prio = NIL_P(prio) ? 0 : NUM2UINT(prio);
545
544
 
546
- rv = (mqd_t)rb_thread_blocking_region(xsend, &x, RUBY_UBF_IO, 0);
547
- if (rv == MQD_INVALID) {
545
+ retry:
546
+ rv = (int)rb_thread_blocking_region(xsend, &x, RUBY_UBF_IO, 0);
547
+ if (rv == -1) {
548
+ if (errno == EINTR)
549
+ goto retry;
548
550
  if (errno == EAGAIN && (sflags & PMQ_TRY))
549
551
  return Qfalse;
550
552
  rb_sys_fail("mq_send");
@@ -568,16 +570,20 @@ static VALUE send0(VALUE self, VALUE buffer)
568
570
  {
569
571
  struct posix_mq *mq = get(self, 1);
570
572
  struct rw_args x;
571
- mqd_t rv;
573
+ int rv;
572
574
 
573
575
  setup_send_buffer(&x, buffer);
574
576
  x.des = mq->des;
575
577
  x.timeout = NULL;
576
578
  x.msg_prio = 0;
577
579
 
578
- rv = (mqd_t)rb_thread_blocking_region(xsend, &x, RUBY_UBF_IO, 0);
579
- if (rv == MQD_INVALID)
580
+ retry:
581
+ rv = (int)rb_thread_blocking_region(xsend, &x, RUBY_UBF_IO, 0);
582
+ if (rv == -1) {
583
+ if (errno == EINTR)
584
+ goto retry;
580
585
  rb_sys_fail("mq_send");
586
+ }
581
587
 
582
588
  return self;
583
589
  }
@@ -679,8 +685,11 @@ static VALUE _receive(int rflags, int argc, VALUE *argv, VALUE self)
679
685
  x.msg_len = (size_t)mq->attr.mq_msgsize;
680
686
  x.des = mq->des;
681
687
 
688
+ retry:
682
689
  r = (ssize_t)rb_thread_blocking_region(xrecv, &x, RUBY_UBF_IO, 0);
683
690
  if (r < 0) {
691
+ if (errno == EINTR)
692
+ goto retry;
684
693
  if (errno == EAGAIN && (rflags & PMQ_TRY))
685
694
  return Qnil;
686
695
  rb_sys_fail("mq_receive");
@@ -704,7 +713,6 @@ static VALUE _receive(int rflags, int argc, VALUE *argv, VALUE self)
704
713
  static VALUE getattr(VALUE self)
705
714
  {
706
715
  struct posix_mq *mq = get(self, 1);
707
- VALUE astruct;
708
716
 
709
717
  if (mq_getattr(mq->des, &mq->attr) < 0)
710
718
  rb_sys_fail("mq_getattr");
@@ -830,18 +838,31 @@ static void thread_notify_fd(union sigval sv)
830
838
 
831
839
  static void my_mq_notify(mqd_t des, struct sigevent *not)
832
840
  {
833
- mqd_t rv = mq_notify(des, not);
841
+ int rv = mq_notify(des, not);
834
842
 
835
- if (rv == MQD_INVALID) {
843
+ if (rv == -1) {
836
844
  if (errno == ENOMEM) {
837
845
  rb_gc();
838
846
  rv = mq_notify(des, not);
839
847
  }
840
- if (rv == MQD_INVALID)
848
+ if (rv == -1)
841
849
  rb_sys_fail("mq_notify");
842
850
  }
843
851
  }
844
852
 
853
+ static void lower_stack_size(pthread_attr_t *attr)
854
+ {
855
+ /* some OSes have ridiculously small stack sizes */
856
+ #ifdef PTHREAD_STACK_MIN
857
+ size_t stack_size = PTHREAD_STACK_MIN;
858
+ size_t min_size = 4096;
859
+
860
+ if (stack_size < min_size)
861
+ stack_size = min_size;
862
+ pthread_attr_setstacksize(attr, stack_size);
863
+ #endif
864
+ }
865
+
845
866
  /* :nodoc: */
846
867
  static VALUE setnotify_exec(VALUE self, VALUE io, VALUE thr)
847
868
  {
@@ -856,10 +877,7 @@ static VALUE setnotify_exec(VALUE self, VALUE io, VALUE thr)
856
877
  errno = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
857
878
  if (errno) rb_sys_fail("pthread_attr_setdetachstate");
858
879
 
859
- #ifdef PTHREAD_STACK_MIN
860
- (void)pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN);
861
- #endif
862
-
880
+ lower_stack_size(&attr);
863
881
  not.sigev_notify = SIGEV_THREAD;
864
882
  not.sigev_notify_function = thread_notify_fd;
865
883
  not.sigev_notify_attributes = &attr;
@@ -1001,7 +1019,7 @@ static VALUE setnonblock(VALUE self, VALUE nb)
1001
1019
  */
1002
1020
  static VALUE trysend(int argc, VALUE *argv, VALUE self)
1003
1021
  {
1004
- _send(PMQ_TRY, argc, argv, self);
1022
+ return _send(PMQ_TRY, argc, argv, self);
1005
1023
  }
1006
1024
 
1007
1025
  /*
@@ -1086,7 +1104,6 @@ void Init_posix_mq_ext(void)
1086
1104
  id_new = rb_intern("new");
1087
1105
  id_kill = rb_intern("kill");
1088
1106
  id_fileno = rb_intern("fileno");
1089
- id_mul = rb_intern("*");
1090
1107
  id_divmod = rb_intern("divmod");
1091
1108
  id_flags = rb_intern("flags");
1092
1109
  id_maxmsg = rb_intern("maxmsg");
@@ -73,8 +73,8 @@ class Test_POSIX_MQ < Test::Unit::TestCase
73
73
  t0 = Time.now
74
74
  maybe_timeout { @mq.receive "", interval } or return
75
75
  elapsed = Time.now - t0
76
- assert elapsed > interval, elapsed.inspect
77
- assert elapsed < 0.02, elapsed.inspect
76
+ assert_operator elapsed, :>, interval, elapsed.inspect
77
+ assert_operator elapsed, :<, 0.04, elapsed.inspect
78
78
  end
79
79
 
80
80
  def test_timed_receive_divmod
@@ -87,8 +87,8 @@ class Test_POSIX_MQ < Test::Unit::TestCase
87
87
  t0 = Time.now
88
88
  maybe_timeout { @mq.receive "", interval } or return
89
89
  elapsed = Time.now - t0
90
- assert elapsed >= 0.01, elapsed.inspect
91
- assert elapsed <= 0.02, elapsed.inspect
90
+ assert_operator elapsed, :>=, 0.01, elapsed.inspect
91
+ assert_operator elapsed, :<=, 0.04, elapsed.inspect
92
92
  end
93
93
 
94
94
  def test_timed_receive_fixnum
@@ -104,13 +104,13 @@ class Test_POSIX_MQ < Test::Unit::TestCase
104
104
 
105
105
  def test_alarm_signal_safe
106
106
  libc = alarm = nil
107
- libcs = %w(libc.so.6 /usr/lib/libc.sl)
107
+ libcs = %w(libc.so.6 libc.so.0.1 libc.so.7 /usr/lib/libc.sl)
108
108
  libcs.each do |name|
109
109
  libc = DL::Handle.new(name) rescue next
110
110
  if defined?(DL::Function)
111
111
  alarm = libc["alarm"]
112
112
  alarm = DL::CFunc.new(alarm, DL::TYPE_INT, "alarm")
113
- alarm = DL::Function.new(alarm, [DL::TYPE_INT], DL::TYPE_INT)
113
+ alarm = DL::Function.new(alarm, [DL::TYPE_INT])
114
114
  else
115
115
  alarm = libc["alarm", "II"]
116
116
  end
@@ -118,16 +118,18 @@ class Test_POSIX_MQ < Test::Unit::TestCase
118
118
  end
119
119
  alarm or return warn "alarm() not found in #{libcs.inspect}"
120
120
  alarms = 0
121
- trap("ALRM") { alarms += 1 }
121
+ trap("ALRM") do
122
+ alarms += 1
123
+ Thread.new { @mq.send("HI") }
124
+ end
122
125
  interval = 1
123
126
  alarm.call interval
124
127
  @mq = POSIX_MQ.new(@path, :rw)
125
128
  assert ! @mq.nonblock?
126
129
  t0 = Time.now
127
- a = nil
128
- assert_raises(Errno::EINTR) { a = @mq.receive }
130
+ a = @mq.receive
129
131
  elapsed = Time.now - t0
130
- assert_nil a
132
+ assert_equal(["HI", 0], a)
131
133
  assert elapsed >= interval, elapsed.inspect
132
134
  assert elapsed < 1.10, elapsed.inspect
133
135
  assert_equal 1, alarms
@@ -255,7 +257,7 @@ class Test_POSIX_MQ < Test::Unit::TestCase
255
257
  assert_nil IO.select([rd], nil, nil, 0.1)
256
258
  ensure
257
259
  trap(:USR1, orig)
258
- end
260
+ end if POSIX_MQ.method_defined?(:to_io)
259
261
 
260
262
  def test_notify_none
261
263
  @mq = POSIX_MQ.new @path, IO::CREAT|IO::RDWR, 0666
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: posix_mq
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
- - 1
7
+ - 2
8
8
  - 0
9
9
  - 0
10
- version: 1.0.0
10
+ version: 2.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ruby POSIX MQ hackers
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-01 00:00:00 +00:00
19
- default_executable:
18
+ date: 2012-08-06 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: wrongdoc
@@ -78,7 +77,6 @@ files:
78
77
  - posix_mq.gemspec
79
78
  - setup.rb
80
79
  - test/test_posix_mq.rb
81
- has_rdoc: true
82
80
  homepage: http://bogomips.org/ruby_posix_mq/
83
81
  licenses: []
84
82
 
@@ -111,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
109
  requirements: []
112
110
 
113
111
  rubyforge_project: qrp
114
- rubygems_version: 1.5.2
112
+ rubygems_version: 1.8.24
115
113
  signing_key:
116
114
  specification_version: 3
117
115
  summary: POSIX Message Queues for Ruby