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 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 35 def self.create_finalizer_for(ptr) Proc.new do ptr_ptr = ::FFI::MemoryPointer.new :pointer 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.
82 83 84 85 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 82 def self.new(reader, *args) ptr = ::CZMQ::FFI.zpoller_new(reader, *args) __new ptr end |
.test(verbose) ⇒ void
This method returns an undefined value.
Self test of this class.
182 183 184 185 186 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 182 def self.test(verbose) verbose = !(0==verbose||!verbose) # boolean result = ::CZMQ::FFI.zpoller_test(verbose) result end |
Instance Method Details
#__ptr ⇒ ::FFI::Pointer Also known as: to_ptr
Return internal pointer
48 49 50 51 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 48 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.
59 60 61 62 63 64 65 66 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 59 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.
71 72 73 74 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 71 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, or a zactor_t instance.
102 103 104 105 106 107 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 102 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
90 91 92 93 94 95 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 90 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.
160 161 162 163 164 165 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 160 def expired() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zpoller_expired(self_p) result end |
#null? ⇒ Boolean
43 44 45 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 43 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.
114 115 116 117 118 119 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 114 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).
128 129 130 131 132 133 134 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 128 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.
171 172 173 174 175 176 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 171 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, or a zsock_t or zactor_t instance 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.
148 149 150 151 152 153 154 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 148 def wait(timeout) raise DestroyedError unless @ptr self_p = @ptr timeout = Integer(timeout) result = ::CZMQ::FFI.zpoller_wait(self_p, timeout) result end |