Class: Nonnative::SlicerSocketPair
- Inherits:
-
SocketPair
- Object
- SocketPair
- Nonnative::SlicerSocketPair
- Defined in:
- lib/nonnative/slicer_socket_pair.rb
Overview
Socket-pair variant used by the fault-injection proxy to fragment upstream responses.
When active, client requests pass through unchanged, while each response written back to the
client is split into proxy.options[:slice_size]-byte writes, optionally separated by
proxy.options[:slice_delay] seconds, so a client that assumes one recv yields a whole protocol
frame is forced to perform multiple reads and reassemble the message. A missing or non-positive
slice_size leaves the connection in pass-through mode.
This behavior is enabled by calling FaultInjectionProxy#slicer.
Instance Method Summary collapse
-
#connect(local_socket) ⇒ void
Tracks the client socket so we can fragment only the response path.
-
#write(socket, data) ⇒ Integer
Writes response data to the client in configured slices, leaving requests unchanged.
Methods inherited from SocketPair
Constructor Details
This class inherits a constructor from Nonnative::SocketPair
Instance Method Details
#connect(local_socket) ⇒ void
This method returns an undefined value.
Tracks the client socket so we can fragment only the response path.
22 23 24 25 26 27 28 |
# File 'lib/nonnative/slicer_socket_pair.rb', line 22 def connect(local_socket) @local_socket = local_socket super ensure @local_socket = nil end |
#write(socket, data) ⇒ Integer
Writes response data to the client in configured slices, leaving requests unchanged.
35 36 37 38 39 40 41 42 |
# File 'lib/nonnative/slicer_socket_pair.rb', line 35 def write(socket, data) return super unless socket.equal?(@local_socket) size = proxy.[:slice_size] return super if size.nil? || size <= 0 sliced_write(socket, data, size) end |