/usr/lib/ruby/vendor_ruby/ffi-rzmq-core/structures.rb is in ruby-ffi-rzmq-core 1.0.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | module LibZMQ
# Used for casting pointers back to the msg_t struct
#
class Message < FFI::Struct
layout :content, :pointer,
:flags, :uint8,
:vsm_size, :uint8,
:vsm_data, [:uint8, 30]
end
# Create the basic mapping for the poll_item_t structure so we can
# access those fields via Ruby.
#
module PollItemLayout
def self.included(base)
fd_type = if FFI::Platform::IS_WINDOWS && FFI::Platform::ADDRESS_SIZE == 64
# On Windows, zmq.h defines fd as a SOCKET, which is 64 bits on x64.
:uint64
else
:int
end
base.class_eval do
layout :socket, :pointer,
:fd, fd_type,
:events, :short,
:revents, :short
end
end
end
# PollItem class includes the PollItemLayout module so that we can use the
# basic FFI accessors to get at the structure's fields. We also want to provide
# some higher-level Ruby accessors for convenience.
#
class PollItem < FFI::Struct
include PollItemLayout
def socket
self[:socket]
end
def fd
self[:fd]
end
def readable?
(self[:revents] & ZMQ::POLLIN) > 0
end
def writable?
(self[:revents] & ZMQ::POLLOUT) > 0
end
def inspect
"socket [#{socket}], fd [#{fd}], events [#{self[:events]}], revents [#{self[:revents]}]"
end
end
# /* Socket event data */
# typedef struct {
# uint16_t event; // id of the event as bitfield
# int32_t value ; // value is either error code, fd or reconnect interval
# } zmq_event_t;
module EventDataLayout
def self.included(base)
base.class_eval do
layout :event, :uint16,
:value, :int32
end
end
end # module EventDataLayout
# Provide a few convenience methods for accessing the event structure.
#
class EventData < FFI::Struct
include EventDataLayout
def event
self[:event]
end
def value
self[:value]
end
def inspect
"event [#{event}], value [#{value}]"
end
end # class EventData
end
|