Class: ConcurrentSHM::Channel::Unbuffered::Fixed
- Inherits:
-
ConcurrentSHM::Channel::Unbuffered
- Object
- ConcurrentSHM::Channel
- ConcurrentSHM::Channel::Unbuffered
- ConcurrentSHM::Channel::Unbuffered::Fixed
- Defined in:
- lib/concurrent-shm/channel.rb
Overview
An unbuffered channel with fixed-width packets.
Class Method Summary collapse
-
.new(shm, width:, offset: 0, autosize: true) ⇒ Object
Allocates an unbuffered, fixed-width channel with the specified width.
Instance Method Summary collapse
-
#recv ⇒ String
Receive a fixed-width packet over the channel.
-
#send(data) ⇒ nil
Send a fixed-width packet over the channel.
Methods inherited from ConcurrentSHM::Channel
Class Method Details
.new(shm, width:, offset: 0, autosize: true) ⇒ Object
Allocates an unbuffered, fixed-width channel with the specified width.
44 45 46 47 48 49 50 51 52 |
# File 'lib/concurrent-shm/channel.rb', line 44 def self.new(shm, width:, offset: 0, autosize: true) raise RangeError, "Width must be > 0" unless width > 0 alloc(shm, 2 + width, offset: offset, autosize: autosize) do |body| @state = body[0].as_intptr @closed = body[1].as_intptr @data = body[2..] end end |
Instance Method Details
#recv ⇒ String
Receive a fixed-width packet over the channel. Blocks if there are no senders.
69 70 71 72 73 |
# File 'lib/concurrent-shm/channel.rb', line 69 def recv do_recv do @data.read end end |
#send(data) ⇒ nil
Send a fixed-width packet over the channel. Blocks if there are no receivers.
59 60 61 62 63 64 65 |
# File 'lib/concurrent-shm/channel.rb', line 59 def send(data) raise RangeError, "Data is wider than channel" if data.size > @data.size do_send do @data.write(data) end end |