Module: CZTop::HasFFIDelegate
- Included in:
- Socket
- 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 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 = nil, errno: nil) ⇒ 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.
13 14 15 |
# File 'lib/cztop/has_ffi_delegate.rb', line 13 def ffi_delegate @ffi_delegate end |
Class Method Details
.raise_zmq_err(msg = nil, errno: nil) ⇒ Object
Raises the appropriate exception for the reported ZMQ error.
Captures zmq_errno once to avoid a race where a subsequent ZMQ call
overwrites it before we read it.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/cztop/has_ffi_delegate.rb', line 61 def raise_zmq_err(msg = nil, errno: nil) errno ||= CZMQ::FFI::Errors.errno msg ||= CZMQ::FFI::Errors.strerror(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 still reports the correct error number.
This method returns an undefined value.
Attaches an FFI delegate to the current (probably new) CZTop object.
32 33 34 35 |
# File 'lib/cztop/has_ffi_delegate.rb', line 32 def attach_ffi_delegate(ffi_delegate) raise_zmq_err 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.
42 43 44 |
# File 'lib/cztop/has_ffi_delegate.rb', line 42 def from_ffi_delegate(ffi_delegate) self.class.from_ffi_delegate(ffi_delegate) end |
#to_ptr ⇒ FFI::Pointer
Returns FFI delegate's pointer.
17 18 19 |
# File 'lib/cztop/has_ffi_delegate.rb', line 17 def to_ptr @ffi_delegate.to_ptr end |