Module: CZTop::HasFFIDelegate

Included in:
Actor, CertStore, Certificate, Config, Frame, Message, Poller::ZPoller, Socket, Z85
Defined in:
lib/cztop/has_ffi_delegate.rb

Overview

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.

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ffi_delegateCZMQ::FFI::* (readonly)

Returns the attached delegate.

Returns:

  • (CZMQ::FFI::*)

    the attached delegate



11
12
13
# File 'lib/cztop/has_ffi_delegate.rb', line 11

def ffi_delegate
  @ffi_delegate
end

Class Method Details

.raise_zmq_err(msg = CZMQ::FFI::Errors.strerror, errno: CZMQ::FFI::Errors.errno) ⇒ Object

Raises the appropriate exception for the reported ZMQ error.

Parameters:

  • msg (String) (defaults to: CZMQ::FFI::Errors.strerror)

    error message

Raises:

  • (ArgumentError)

    if EINVAL was reported

  • (Interrupt)

    if EINTR was reported

  • (SocketError)

    if EHOSTUNREACH was reported

  • (SystemCallError)

    any other reported error (appropriate SystemCallError subclass, if errno is known)



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 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

Instance Method Details

#attach_ffi_delegate(ffi_delegate) ⇒ 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.

This method returns an undefined value.

Attaches an FFI delegate to the current (probably new) CZTop object.

Parameters:

  • ffi_delegate

    an instance of the corresponding class in the CZMQ::FFI namespace

Raises:

  • (SystemCallError, ArgumentError, ...)

    if the FFI delegate’s internal pointer is NULL

See Also:



29
30
31
32
# 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

#from_ffi_delegate(ffi_delegate) ⇒ CZTop::*

Same as the counterpart in ClassMethods, but usable from within an instance.

Returns:

See Also:

  • FFIDelegate::ClassMethods#from_ffi_delegate


39
40
41
# File 'lib/cztop/has_ffi_delegate.rb', line 39

def from_ffi_delegate(ffi_delegate)
  self.class.from_ffi_delegate(ffi_delegate)
end

#to_ptrFFI::Pointer

Returns FFI delegate’s pointer.

Returns:

  • (FFI::Pointer)

    FFI delegate’s pointer



14
15
16
# File 'lib/cztop/has_ffi_delegate.rb', line 14

def to_ptr
  @ffi_delegate.to_ptr
end