Date | Commit message (Collapse) |
|
Having extra args was harmless in Ruby 2.4, but Ruby 2.5 with
newer versions of clang are not happy about it. Eventually this
may be fixed in Ruby 2.5.1: https://bugs.ruby-lang.org/issues/14425
|
|
We do not want ObjectSpace walkers to be able to mess with
our internals.
|
|
This provides some extra type safety if combined with other
C extensions, as well as allowing us to account for memory usage of
the HTTP parser in ObjectSpace.
This requires Ruby 1.9.3+ and has remained a stable API since
then. This will become officially supported when Ruby 2.3.0 is
released later this month.
This API has only been documented in doc/extension.rdoc (formerly
README.EXT) in the Ruby source tree since April 2015, r50318
|
|
This bug was noticed under FreeBSD :x
|
|
IO#close under Ruby 2.3 is idempotent, we shall follow suit
with POSIX_MQ#close
|
|
If a corresponding IO object exists or is created later, propagate
autoclose to the corresponding IO object to avoid simplify autoclose
handling for the user. This hopefully avoids nasty surprises in case
users disable autoclose but want to keep the IO object around.
|
|
This should allow faster instructions to be used in some cases.
Technically this may be less pedantically correct, but there is
enough existing code out there which does the same thing to
discourage kernel/libc developers from overloading negative
return values.
...And glibc even favors comparison against zero, too.
|
|
This saves one word of stack space, potentially improving
performance a miniscule amount.
|
|
These are analogous to the identically-named IO methods and useful
when we're inheriting descriptors (or writing tests for inheriting
descriptors).
|
|
We do not want to assign to mq->des before verifying we
have a valid message queue, otherwise the GC may misclose
an invalid MQ descriptor (which may be a valid FD).
|
|
This patch adds support for adopting an existing file descriptor, together
with testcases. The need for this comes up when we use systemd with the
ListenMessageQueue directive. For socket activation, systemd opens the POSIX
message queue and expects user code to begin using the file descriptor
without opening it in-process.
To support the systemd model in the `posix_mq` gem, this patch suggests
imitating the behavior on the Socket class, which uses `#for_fd` to create a
socket class from a descriptor.
One confounding factor exists. POSIX queues have a name but it is difficult
to get access to this name in a safe manner from the file descriptor. One
option would be to `readlink(2)` on `/proc/self/fd/N` to get the name[1], but
note that if the descriptor is unlinked we wouldn't get anything usable.
Rather than risk incorrect behavior and extra complexity, I've decided to
just raise an `ArgumentError` if `#name` is called on adopted descriptors.
Typically one wouldn't need the actual name in a systemd socket-activated
situation, anyway.
[1]: http://stackoverflow.com/questions/1188757/getting-filename-from-file-descriptor-in-c
[ew: simplified type checks to be consistent with IO.for_fd,
fixed test case]
Signed-off-by: Eric Wong <normalperson@yhbt.net>
|
|
This will be removed in Ruby 2.2, so avoid the deprecation warning.
|
|
It'll be OK to use rb_thread_call_without_gvl when
rb_thread_blocking_region is not detectable at all.
We still use rb_thread_blocking_region for Ruby 2.0-2.1 because
rb_thread_call_without_gvl was detectable in 1.9.3, but not
usable as an internal symbol.
ref: https://bugs.ruby-lang.org/issues/9502
|
|
Somehow I mixed up return values for mq_* functions that
return "int". This was noticed on FreeBSD where mqd_t
is NOT an integer.
|
|
Some OSes have ridiculously low boundaries and we don't
want mysterious failures on them
|
|
Blocking functions should not raise Errno::EINTR to match
existing semantics of Ruby IO methods (e.g. IO.select, IO#read,
IO#write). This makes user code easier to read/write.
Like th Ruby methods we emulate, we only reacquire the GVL on
EINTR to fire signal handlers, but otherwise emulate SA_RESTART
semantics.
This is a backwards-incompatible API change (but unlikely
to break existing code).
|
|
CFLAGS=-Wall somehow got disabled in my Ruby installation...
|
|
Oops
|
|
'*' works just the same
|
|
So private we won't mention them in the commit message!
|
|
Something I considered but decided wasn't worth doing.
|
|
This is to be consistent with POSIX_MQ#trysend
|
|
Consider them good enough for a 1.0.0 release
|
|
But they'll be pushed to the site for greater
visibility.
|
|
These are kinder and less exceptional than their
non-trying counterparts as generating exceptions
is expensive for common EAGAIN errors.
|
|
It can be local variable
|
|
It could work...
|
|
Oops :x
|
|
These flags can be changed in the parent or child
process, so we will always have to run mq_getattr()
to check it. This removes the GVL-keeping non-blocking
optimizations but we'll gain some soon.
|
|
Maybe people will just upgrade to newer systems eventually.
|
|
These cannot be cast to void since its value is
meaningful.
|
|
Some ancient systems don't support mq_timedsend and
mq_timedreceive but somehow manage to support other POSIX
mq_* functions.
|
|
RSTRING_PTR may contain '\0' bytes which makes it unsuitable
for mq_unlink() and mq_open()
|
|
This was too aggressively deleted during cleanups for Rubinius
support in commit 5339d9d693c794c0f20270d5726cb360e31dff30
Noticed-by: Tadeusz Bochan <tad.bochan@bnpparibas.com>
ref: 2a92695fc1958e0370782284c6196625@ruby-forum.com
|
|
Apparently there are OSes that don't have methods to convert
mqd_t to FD.
Noticed-by: Tadeusz Bochan <tad.bochan@bnpparibas.com>
ref: <2a92695fc1958e0370782284c6196625@ruby-forum.com>
|
|
Cleaner code, too, no more direct RSTRUCT usage.
|
|
StringValuePtr should already be a sufficient guard.
There are more tests while we're at it, too, and we'll
now raise TypeError instead of ArgumentError when a
POSIX_MQ::Attr is not passed properly.
|
|
This function isn't exported in the standard Ruby headers,
it returns an aggregate value and isn't available in Rubinius,
either, so nuke it.
While we're at it, use clock_gettime() instead of gettimeofday()
to avoid unnecessary timeval usage since mq_send/mq_receive
rely on higher-precision timespecs instead.
|
|
It can be dangerous to hit (and ignore) EBADF errors in
multi-threaded applications. Users of POSIX_MQ#to_io have two
Ruby objects pointing to the same file descriptor, making
things tricky when it comes time to reap resources.
We'll always prefer to close the Ruby IO object if it exists
(because we have less control over its GC behavior) and
ignore the raw descriptor.
|
|
On ENOMEM, EMFILE, and ENFILE errors, it is customary to
invoke the Ruby GC and free up resources and retry the
system call.
|
|
tests for them were stupidly broken and never executed :x
|
|
Avoid the RSTRING_PTR(rb_inspect(val)) construct, as it may not
preserve the value of rb_inspect() on the stack.
|
|
Instead of blindly defining a module, this is more flexible in
case Signal in Ruby itself becomes something other than a
module.
|
|
We don't want folks to accidentally clobber the value for
others, so allocate a new string object for it (don't worry,
rb_str_dup() is cheap in 1.9).
|
|
There's a good chance they're not using GCC if they're on some
weird platform that we'd emit a warning for.
|
|
|
|
|
|
|
|
Missed this with the other change
|
|
Since the message queue is not actually on a (slow) block
device, it's unlikely to block in a way where other tasks may be
scheduled by the kernel. So avoid complicating things and
unnecessary task switching and assume mq_open/mq_unlink can
be executed as fast as the CPU/memory subsystems allows.
|