Class: ConcurrentSHM::Channel::SingleBuffered::Fixed
- Inherits:
-
ConcurrentSHM::Channel::SingleBuffered
- Object
- ConcurrentSHM::Channel
- ConcurrentSHM::Channel::SingleBuffered
- ConcurrentSHM::Channel::SingleBuffered::Fixed
- Defined in:
- lib/concurrent-shm/channel.rb
Overview
A single-buffered channel with fixed-width packets.
Class Method Summary collapse
-
.new(shm, width:, offset: 0, autosize: true) ⇒ Object
Allocates a single-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 a single-unbuffered, fixed-width channel with the specified width.
174 175 176 177 178 179 180 181 182 |
# File 'lib/concurrent-shm/channel.rb', line 174 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 the buffer is empty.
194 195 196 197 198 |
# File 'lib/concurrent-shm/channel.rb', line 194 def recv do_recv do @data.read end end |
#send(data) ⇒ nil
Send a fixed-width packet over the channel. Blocks if the buffer is full.
185 186 187 188 189 190 191 |
# File 'lib/concurrent-shm/channel.rb', line 185 def send(data) raise RangeError, "Data is wider than channel" if data.size > @data.size do_send do @data.write(data) end end |