module CZTop::HasFFIDelegate
This module is used to attach the low-level objects of classes within the CZMQ::FFI namespace (coming from the czmq-ffi-gen gem) as delegates.
Attributes
@return [CZMQ::FFI::*] the attached delegate
Public Instance Methods
Attaches an FFI delegate to the current (probably new) {CZTop} object. @param ffi_delegate
an instance of the corresponding class in the
CZMQ::FFI namespace
@raise [SystemCallError, ArgumentError, …] if the FFI delegate’s
internal pointer is NULL
@return [void] @note This only raises the correct exception when the creation of the new
CZMQ object was the most recent thing done with the CZMQ library and thus CZMQ::FFI::Errors.errno is still reports the correct error number.
@see raise_zmq_err
# File lib/cztop/has_ffi_delegate.rb, line 29 def attach_ffi_delegate(ffi_delegate) raise_zmq_err(CZMQ::FFI::Errors.strerror) if ffi_delegate.null? @ffi_delegate = ffi_delegate end
Same as the counterpart in {ClassMethods}, but usable from within an instance. @see CZTop::FFIDelegate::ClassMethods#from_ffi_delegate @return [CZTop::*] the new object
# File lib/cztop/has_ffi_delegate.rb, line 39 def from_ffi_delegate(ffi_delegate) self.class.from_ffi_delegate(ffi_delegate) end
Raises the appropriate exception for the reported ZMQ error.
@param msg [String] error message @raise [ArgumentError] if EINVAL was reported @raise [Interrupt] if EINTR was reported @raise [SocketError] if EHOSTUNREACH was reported @raise [SystemCallError] any other reported error (appropriate
SystemCallError subclass, if errno is known)
# File lib/cztop/has_ffi_delegate.rb, line 53 def raise_zmq_err(msg = CZMQ::FFI::Errors.strerror, errno: CZMQ::FFI::Errors.errno) case errno when Errno::EINVAL::Errno fail ArgumentError, msg, caller when Errno::EINTR::Errno fail Interrupt, msg, caller when Errno::EHOSTUNREACH::Errno fail SocketError, msg, caller else # If the errno is known, the corresponding Errno::* exception is # automatically constructed. Otherwise, it'll be a plain SystemCallError. # In any case, #errno will return the corresponding errno. fail SystemCallError.new(msg, errno), msg, caller end end
@return [FFI::Pointer] FFI delegate’s pointer
# File lib/cztop/has_ffi_delegate.rb, line 14 def to_ptr @ffi_delegate.to_ptr end