Class: CZMQ::FFI::Zpoller

Inherits:
Object
  • Object
show all
Defined in:
lib/czmq-ffi-gen/czmq/ffi/zpoller.rb

Overview

Note:

This class is 100% generated using zproject.

event-driven reactor

Defined Under Namespace

Classes: DestroyedError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr, finalize = true) ⇒ Zpoller

Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.

Parameters:

  • ptr (::FFI::Pointer)
  • finalize (Boolean) (defaults to: true)


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

.__newObject



18
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 18

alias :__new :new

.create_finalizer_for(ptr) ⇒ Proc

Parameters:

  • ptr (::FFI::Pointer)

Returns:

  • (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.

Parameters:

  • reader (::FFI::Pointer, #to_ptr)
  • args (Array<Object>)

Returns:

  • (CZMQ::Zpoller)


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

.test(verbose) ⇒ void

This method returns an undefined value.

Self test of this class.

Parameters:

  • verbose (Boolean)


185
186
187
188
189
# File 'lib/czmq-ffi-gen/czmq/ffi/zpoller.rb', line 185

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

Returns:

  • (::FFI::Pointer)

Raises:



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

Note:

This detaches the current instance from the native object and thus makes it unusable.

Nullify internal pointer and return pointer pointer.

Returns:

  • (::FFI::MemoryPointer)

    the pointer pointing to a pointer pointing to the native object

Raises:



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_finalizervoid

Note:

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.

Parameters:

  • reader (::FFI::Pointer, #to_ptr)

Returns:

  • (Integer)

Raises:



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

#destroyvoid

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

#expiredBoolean

Return true if the last zpoller_wait () call ended because the timeout expired, without any error.

Returns:

  • (Boolean)

Raises:



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

Returns:

  • (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.

Parameters:

  • reader (::FFI::Pointer, #to_ptr)

Returns:

  • (Integer)

Raises:



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).

Parameters:

  • nonstop (Boolean)

Raises:



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

#terminatedBoolean

Return true if the last zpoller_wait () call ended because the process was interrupted, or the parent context was destroyed.

Returns:

  • (Boolean)

Raises:



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.

Parameters:

  • timeout (Integer, #to_int, #to_i)

Returns:

  • (::FFI::Pointer)

Raises:



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