Class: Nonnative::BandwidthSocketPair

Inherits:
SocketPair
  • Object
show all
Defined in:
lib/nonnative/bandwidth_socket_pair.rb

Overview

Socket-pair variant used by the fault-injection proxy to simulate a bandwidth-limited link.

When active, each forwarded read is throttled so throughput does not exceed proxy.options[:rate] kilobytes per second (1 KB = 1024 bytes), by sleeping in proportion to the bytes read. Both directions are throttled, so a client under test sees a slow-but-alive dependency. When rate is absent or not positive the connection forwards at full speed.

This behavior is enabled by calling FaultInjectionProxy#bandwidth.

Constant Summary collapse

KILOBYTE =

One kilobyte in bytes; proxy.options[:rate] is expressed in KB/s.

1024

Instance Method Summary collapse

Methods inherited from SocketPair

#close, #connect, #initialize

Constructor Details

This class inherits a constructor from Nonnative::SocketPair

Instance Method Details

#read(socket) ⇒ String

Reads from the socket, then sleeps so the forwarded throughput stays within the configured rate.

Parameters:

  • socket (IO)

    the socket to read from

Returns:

  • (String)

    the bytes read from the socket



24
25
26
# File 'lib/nonnative/bandwidth_socket_pair.rb', line 24

def read(socket)
  super.tap { |data| throttle(data.bytesize) }
end