Class: CZMQ::FFI::Zpoller
- Inherits:
-
Object
- Object
- CZMQ::FFI::Zpoller
- Defined in:
- lib/czmq-ffi-gen/czmq/ffi/zpoller.rb
Overview
This class is 100% generated using zproject.
event-driven reactor
Defined Under Namespace
Classes: DestroyedError
Class Method Summary collapse
- .__new ⇒ Object
- .create_finalizer_for(ptr) ⇒ Proc
-
.new(reader, *args) ⇒ CZMQ::Zpoller
Create new poller, specifying zero or more readers.
-
.test(verbose) ⇒ void
Self test of this class.
Instance Method Summary collapse
-
#__ptr ⇒ ::FFI::Pointer
(also: #to_ptr)
Return internal pointer.
-
#__ptr_give_ref ⇒ ::FFI::MemoryPointer
Nullify internal pointer and return pointer pointer.
-
#__undef_finalizer ⇒ void
Undefines the finalizer for this object.
-
#add(reader) ⇒ Integer
Add a reader to be polled.
-
#destroy ⇒ void
Destroy a poller.
-
#expired ⇒ Boolean
Return true if the last zpoller_wait () call ended because the timeout expired, without any error.
-
#initialize(ptr, finalize = true) ⇒ Zpoller
constructor
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.
- #null? ⇒ Boolean
-
#remove(reader) ⇒ Integer
Remove a reader from the poller; returns 0 if OK, -1 on failure.
-
#set_nonstop(nonstop) ⇒ void
By default the poller stops if the process receives a SIGINT or SIGTERM signal.
-
#terminated ⇒ Boolean
Return true if the last zpoller_wait () call ended because the process was interrupted, or the parent context was destroyed.
-
#wait(timeout) ⇒ ::FFI::Pointer
Poll the registered readers for I/O, return first reader that has input.
Constructor Details
#initialize(ptr, finalize = true) ⇒ Zpoller
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.
24 25 26 27 28 29 30 31 32 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 24 def initialize(ptr, finalize = true) @ptr = ptr if @ptr.null? @ptr = nil # Remove null pointers so we don't have to test for them. elsif finalize @finalizer = self.class.create_finalizer_for @ptr ObjectSpace.define_finalizer self, @finalizer end end |
Class Method Details
.__new ⇒ Object
18 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 18 alias :__new :new |
.create_finalizer_for(ptr) ⇒ Proc
35 36 37 38 39 40 41 42 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 35 def self.create_finalizer_for(ptr) ptr_ptr = ::FFI::MemoryPointer.new :pointer Proc.new do ptr_ptr.write_pointer ptr ::CZMQ::FFI.zpoller_destroy ptr_ptr end end |
.new(reader, *args) ⇒ CZMQ::Zpoller
Create new poller, specifying zero or more readers. The list of readers ends in a NULL. Each reader can be a zsock_t instance, a zactor_t instance, a libzmq socket (void *), or a file handle.
83 84 85 86 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 83 def self.new(reader, *args) ptr = ::CZMQ::FFI.zpoller_new(reader, *args) __new ptr end |
Instance Method Details
#__ptr ⇒ ::FFI::Pointer Also known as: to_ptr
Return internal pointer
49 50 51 52 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 49 def __ptr raise DestroyedError unless @ptr @ptr end |
#__ptr_give_ref ⇒ ::FFI::MemoryPointer
This detaches the current instance from the native object and thus makes it unusable.
Nullify internal pointer and return pointer pointer.
60 61 62 63 64 65 66 67 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 60 def __ptr_give_ref raise DestroyedError unless @ptr ptr_ptr = ::FFI::MemoryPointer.new :pointer ptr_ptr.write_pointer @ptr __undef_finalizer if @finalizer @ptr = nil ptr_ptr end |
#__undef_finalizer ⇒ void
Only use this if you need to and can guarantee that the native object will be freed by other means.
This method returns an undefined value.
Undefines the finalizer for this object.
72 73 74 75 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 72 def __undef_finalizer ObjectSpace.undefine_finalizer self @finalizer = nil end |
#add(reader) ⇒ Integer
Add a reader to be polled. Returns 0 if OK, -1 on failure. The reader may be a libzmq void * socket, a zsock_t instance, a zactor_t instance or a file handle.
104 105 106 107 108 109 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 104 def add(reader) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zpoller_add(self_p, reader) result end |
#destroy ⇒ void
This method returns an undefined value.
Destroy a poller
91 92 93 94 95 96 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 91 def destroy() return unless @ptr self_p = __ptr_give_ref result = ::CZMQ::FFI.zpoller_destroy(self_p) result end |
#expired ⇒ Boolean
Return true if the last zpoller_wait () call ended because the timeout expired, without any error.
163 164 165 166 167 168 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 163 def expired() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zpoller_expired(self_p) result end |
#null? ⇒ Boolean
44 45 46 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 44 def null? !@ptr or @ptr.null? end |
#remove(reader) ⇒ Integer
Remove a reader from the poller; returns 0 if OK, -1 on failure. The reader must have been passed during construction, or in an zpoller_add () call.
116 117 118 119 120 121 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 116 def remove(reader) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zpoller_remove(self_p, reader) result end |
#set_nonstop(nonstop) ⇒ void
This method returns an undefined value.
By default the poller stops if the process receives a SIGINT or SIGTERM signal. This makes it impossible to shut-down message based architectures like zactors. This method lets you switch off break handling. The default nonstop setting is off (false).
130 131 132 133 134 135 136 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 130 def set_nonstop(nonstop) raise DestroyedError unless @ptr self_p = @ptr nonstop = !(0==nonstop||!nonstop) # boolean result = ::CZMQ::FFI.zpoller_set_nonstop(self_p, nonstop) result end |
#terminated ⇒ Boolean
Return true if the last zpoller_wait () call ended because the process was interrupted, or the parent context was destroyed.
174 175 176 177 178 179 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 174 def terminated() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zpoller_terminated(self_p) result end |
#wait(timeout) ⇒ ::FFI::Pointer
Poll the registered readers for I/O, return first reader that has input. The reader will be a libzmq void * socket, a zsock_t, a zactor_t instance or a file handle as specified in zpoller_new/zpoller_add. The timeout should be zero or greater, or -1 to wait indefinitely. Socket priority is defined by their order in the poll list. If you need a balanced poll, use the low level zmq_poll method directly. If the poll call was interrupted (SIGINT), or the ZMQ context was destroyed, or the timeout expired, returns NULL. You can test the actual exit condition by calling zpoller_expired () and zpoller_terminated (). The timeout is in msec.
151 152 153 154 155 156 157 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 151 def wait(timeout) raise DestroyedError unless @ptr self_p = @ptr timeout = Integer(timeout) result = ::CZMQ::FFI.zpoller_wait(self_p, timeout) result end |