about summary refs log tree commit homepage
path: root/ext/posix_mq/posix_mq.c
DateCommit message (Collapse)
2018-01-30drop extra args to rb_funcall
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
2017-03-20freeze internal objects
We do not want ObjectSpace walkers to be able to mess with our internals.
2017-03-18TypedData C-API conversion pu
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
2017-03-18set correct condition for setting id_autoclose
This bug was noticed under FreeBSD :x
2016-02-02support idempotent POSIX_MQ#close
IO#close under Ruby 2.3 is idempotent, we shall follow suit with POSIX_MQ#close
2015-01-16POSIX_MQ#autoclose= propagates to IO
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.
2015-01-11favor comparisons against zero instead of -1
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.
2015-01-09pack rw_args struct
This saves one word of stack space, potentially improving performance a miniscule amount.
2015-01-09support autoclose= and autoclose?
These are analogous to the identically-named IO methods and useful when we're inheriting descriptors (or writing tests for inheriting descriptors).
2015-01-09for_fd: delay assigning to mq->des until after mq_getattr
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).
2015-01-04Ability to adopt file descriptors
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>
2014-02-15avoid deprecated rb_thread_blocking_region in Ruby 2.0/2.1
This will be removed in Ruby 2.2, so avoid the deprecation warning.
2014-02-09prepare for rb_thread_blocking_region removal
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
2012-07-12ext: fix type inconsistencies for int vs mqd_t retvals
Somehow I mixed up return values for mq_* functions that return "int". This was noticed on FreeBSD where mqd_t is NOT an integer.
2012-07-12notify: set lower bound for notify stack size
Some OSes have ridiculously low boundaries and we don't want mysterious failures on them
2012-07-05blocking functions do not raise Errno::EINTR
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).
2011-06-16fix compiler warnings, oops
CFLAGS=-Wall somehow got disabled in my Ruby installation...
2011-06-14num2timespec: remove needless double-assignment
Oops
2011-06-14no need to rb_intern("*")
'*' works just the same
2011-03-01make methods that should be private, private
So private we won't mention them in the commit message!
2011-03-01remove unused tryinit function
Something I considered but decided wasn't worth doing.
2011-03-01POSIX_MQ#send returns +true+ on success
This is to be consistent with POSIX_MQ#trysend
2011-03-01finalize try* interfaces
Consider them good enough for a 1.0.0 release
2011-02-27doc: note that the try* interfaces are not final
But they'll be pushed to the site for greater visibility.
2011-02-27add trysend, tryreceive, and tryshift interfaces
These are kinder and less exceptional than their non-trying counterparts as generating exceptions is expensive for common EAGAIN errors.
2011-02-27eliminate needless global (cPOSIX_MQ)
It can be local variable
2011-02-27run GC on ENOSPC when calling mq_open()
It could work...
2011-02-27Symbols are VALUEs, not IDs
Oops :x
2011-02-27Do not trust locally cached mq_flags
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.
2011-02-23doc: note that timeout is not always supported
Maybe people will just upgrade to newer systems eventually.
2011-02-23fix MQ_IO_NIL_P and MQ_IO_CLOSE macros
These cannot be cast to void since its value is meaningful.
2011-02-22attempt to support systems w/o mq_timedsend/mq_timedreceive
Some ancient systems don't support mq_timedsend and mq_timedreceive but somehow manage to support other POSIX mq_* functions.
2011-02-22use StringValueCStr for paths
RSTRING_PTR may contain '\0' bytes which makes it unsuitable for mq_unlink() and mq_open()
2011-02-22fix broken rb_str_set_len() #define for Ruby 1.8.6
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
2011-02-22fix for systems that can't convert mqd_t to FD
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>
2010-12-24add Rubinius support
Cleaner code, too, no more direct RSTRUCT usage.
2010-12-24refactor type checks and remove unnecessary guards
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.
2010-12-24remove rb_time_interval() and gettimeofday() dependency
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.
2010-08-19avoid double close() and EBADF
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.
2010-08-02open/notify: invoke GC if needed
On ENOMEM, EMFILE, and ENFILE errors, it is customary to invoke the Ruby GC and free up resources and retry the system call.
2010-05-09fix POSIX_MQ#notify(&block) aka SIGEV_THREAD
tests for them were stupidly broken and never executed :x
2010-04-22GC safety fixes
Avoid the RSTRING_PTR(rb_inspect(val)) construct, as it may not preserve the value of rb_inspect() on the stack.
2010-04-21cleaner lookup "Signal" of constant
Instead of blindly defining a module, this is more flexible in case Signal in Ruby itself becomes something other than a module.
2010-03-13ensure POSIX_MQ#name is clobber-proof
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).
2010-03-13remove non-portable #warning CPP directive
There's a good chance they're not using GCC if they're on some weird platform that we'd emit a warning for.
2010-03-02add TODO item for using netlink under Linux
2010-02-20POSIX_MQ#to_io works under FreeBSD, too
2010-02-20avoid shadow warnings
2010-02-20POSIX_MQ#<< does not release GVL when non-blocking
Missed this with the other change
2010-02-20do not release GVL when unlinking/opening
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.