Class: TIPCSocket
- Inherits:
-
Socket
- Object
- Socket
- TIPCSocket
- Defined in:
- lib/tipcsocket.rb
Overview
Provides access to a TIPC socket. Subclass of the standard ruby Socket class.
Defined Under Namespace
Modules: Constants
Class Method Summary collapse
-
.unpack_sockaddr(bytes) ⇒ Object
Create a new TIPCSocket instance from a 16 byte binary string containing a TIPC address.
Instance Method Summary collapse
- #bind(tipc_addr) ⇒ Object
- #connect(tipc_addr) ⇒ Object
-
#initialize(type, protocol = 0) ⇒ TIPCSocket
constructor
Create a new instance of a TIPCSocket.
- #send(msg, flags, tipc_addr = nil) ⇒ Object
Constructor Details
#initialize(type, protocol = 0) ⇒ TIPCSocket
Create a new instance of a TIPCSocket.
Parameters
- type: must be one of the following
* :stream - for reliable connection-oriented byte streams
* :seqpacket - for reliable connection-oriented
* :rdm - for reliable connectionless
* :dgram - for unreliable connectionless
- protocol: passed directly to Socket.new (optional)
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 |
# File 'lib/tipcsocket.rb', line 478 def initialize(type, protocol = 0) case type.to_s.downcase when 'stream' type = Socket::Constants::SOCK_STREAM when 'seqpacket' type = Socket::Constants::SOCK_SEQPACKET when 'rdm' type = Socket::Constants::SOCK_RDM when 'dgram' type = Socket::Constants::SOCK_DGRAM else raise TypeError, "invalid TIPC socket type (#{type})" end super(Socket::Constants::AF_TIPC, type, protocol) end |
Class Method Details
.unpack_sockaddr(bytes) ⇒ Object
Create a new TIPCSocket instance from a 16 byte binary string containing a TIPC address. Returns one of the following depending on the addrtype field: TIPCNameSeq, TIPCName, TIPCPortId.
Parameters
* bytes - 16 byte string containing TIPC address
454 455 456 457 458 459 460 461 462 463 464 465 466 467 |
# File 'lib/tipcsocket.rb', line 454 def self.unpack_sockaddr(bytes) family, addrtype = bytes.unpack("SC") case when addrtype == Constants::TIPC_ADDR_NAMESEQ TIPCNameSeq.unpack_addr(bytes) when addrtype == Constants::TIPC_ADDR_NAME TIPCName.unpack_addr(bytes) when addrtype == Constants::TIPC_ADDR_ID TIPCPortId.unpack_addr(bytes) else raise ArgumentError, "invalid address type (#{addrtype})" end end |
Instance Method Details
#bind(tipc_addr) ⇒ Object
504 505 506 507 |
# File 'lib/tipcsocket.rb', line 504 def bind(tipc_addr) tipc_addr = tipc_addr.is_a?(String) ? tipc_addr : tipc_addr.pack_addr super(tipc_addr) end |
#connect(tipc_addr) ⇒ Object
509 510 511 512 |
# File 'lib/tipcsocket.rb', line 509 def connect(tipc_addr) tipc_addr = tipc_addr.is_a?(String) ? tipc_addr : tipc_addr.pack_addr super(tipc_addr) end |
#send(msg, flags, tipc_addr = nil) ⇒ Object
495 496 497 498 499 500 501 502 |
# File 'lib/tipcsocket.rb', line 495 def send(msg, flags, tipc_addr = nil) if tipc_addr tipc_addr = tipc_addr.is_a?(String) ? tipc_addr : tipc_addr.pack_addr super(msg, flags, tipc_addr) else super(msg, flags) end end |