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
-
#ffi_delegate ⇒ CZMQ::FFI::*
readonly
The attached delegate.
Class Method Summary collapse
-
.raise_zmq_err(msg = CZMQ::FFI::Errors.strerror, errno: CZMQ::FFI::Errors.errno) ⇒ Object
Raises the appropriate exception for the reported ZMQ error.
Instance Method Summary collapse
-
#attach_ffi_delegate(ffi_delegate) ⇒ void
Attaches an FFI delegate to the current (probably new) CZTop object.
-
#from_ffi_delegate(ffi_delegate) ⇒ CZTop::*
Same as the counterpart in ClassMethods, but usable from within an instance.
-
#to_ptr ⇒ FFI::Pointer
FFI delegate’s pointer.
Instance Attribute Details
#ffi_delegate ⇒ CZMQ::FFI::* (readonly)
Returns 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.
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
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.
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.
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_ptr ⇒ FFI::Pointer
Returns FFI delegate’s pointer.
14 15 16 |
# File 'lib/cztop/has_ffi_delegate.rb', line 14 def to_ptr @ffi_delegate.to_ptr end |