Class: TIPCPortId

Inherits:
Object
  • Object
show all
Defined in:
lib/tipcsocket.rb

Overview

Represents a TIPC port identifier.

From the TIPC Programmer’s Guide:

Each port in a TIPC network has a unique "port identifier" or "port ID", 
which is typically denoted as <Z.C.N:ref>.  The port ID is assigned 
automatically by TIPC when the port is created, and consists of the 32-bit 
network address of the port's node and a 32-bit reference value.  The 
reference value is guaranteed to be unique on a per-node basis and will not 
be reused for a long time once the port ceases to exist.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ref, node, scope = TIPCSocket::Constants::TIPC_NODE_SCOPE) ⇒ TIPCPortId

Create a new TIPCPortId instance.

Parameters

* ref   - 32 bit reference value
* node  - 32 bit network address of the port's node
* scope - the scope (zone, cluster, or node) to use when packing this port
          id as a TIPC address (optional)


31
32
33
34
35
36
37
# File 'lib/tipcsocket.rb', line 31

def initialize(ref, node, scope = TIPCSocket::Constants::TIPC_NODE_SCOPE)
  @family   = Socket::Constants::AF_TIPC
  @addrtype = TIPCSocket::Constants::TIPC_ADDR_ID
  @ref      = ref
  @node     = node
  @scope    = scope
end

Instance Attribute Details

#addrtypeObject (readonly)

Returns the value of attribute addrtype.



21
22
23
# File 'lib/tipcsocket.rb', line 21

def addrtype
  @addrtype
end

#familyObject (readonly)

Returns the value of attribute family.



21
22
23
# File 'lib/tipcsocket.rb', line 21

def family
  @family
end

#nodeObject

Returns the value of attribute node.



22
23
24
# File 'lib/tipcsocket.rb', line 22

def node
  @node
end

#refObject

Returns the value of attribute ref.



22
23
24
# File 'lib/tipcsocket.rb', line 22

def ref
  @ref
end

#scopeObject

Returns the value of attribute scope.



22
23
24
# File 'lib/tipcsocket.rb', line 22

def scope
  @scope
end

Class Method Details

.unpack(bytes) ⇒ Object

Create a new TIPCPortId instance from an 8 byte binary string containing a TIPC port indentifier.

Parameters

* bytes - 8 byte string containing TIPC port identifier


87
88
89
90
# File 'lib/tipcsocket.rb', line 87

def self.unpack(bytes)
  data = bytes.unpack("L2")
  self.new(data[0], data[1])
end

.unpack_addr(bytes) ⇒ Object

Create a new TIPCPortId instance from a 16 byte binary string containing a TIPC address.

Parameters

* bytes - 16 byte string containing TIPC address


77
78
79
80
# File 'lib/tipcsocket.rb', line 77

def self.unpack_addr(bytes)
  data = bytes.unpack("SCcL3")
  self.new(data[3], data[4], data[2])
end

Instance Method Details

#packObject

Pack an instance of a TIPCPortId.

Produces an 8 byte string with the following format:

* ref  - uint32 (4 bytes)
* node - uint32 (4 bytes)


65
66
67
68
69
70
# File 'lib/tipcsocket.rb', line 65

def pack
  [
    self.ref,
    self.node,
  ].pack("L2")
end

#pack_addrObject

Pack an instance of a TIPCPortId as a 16 byte TIPC network address suitable for passing to one of the standard Socket methods (connect, send, etc.).

Produces a 16 byte binary string with the following format:

* family   - unsigned short (2 bytes)
* addrtype - unsigned char  (1 byte)
* scope    - signed char    (1 byte)
* ref      - uint32         (4 bytes)
* node     - uint32         (4 bytes)
* padding  - uint32         (4 bytes)


49
50
51
52
53
54
55
56
57
58
# File 'lib/tipcsocket.rb', line 49

def pack_addr
  [
    self.family,
    self.addrtype,
    self.scope,
    self.ref,
    self.node,
    0
  ].pack("SCcL3")
end