Class: Nonnative::TimeoutSocketPair

Inherits:
SocketPair show all
Defined in:
lib/nonnative/timeout_socket_pair.rb

Overview

Socket-pair variant used by the fault-injection proxy to simulate read timeouts.

When active, the proxy accepts the client connection and keeps it open without forwarding bytes. Clients with read deadlines should observe their own timeout behavior.

This behavior is enabled by calling FaultInjectionProxy#timeout.

Instance Method Summary collapse

Methods inherited from SocketPair

#close, #initialize

Constructor Details

This class inherits a constructor from Nonnative::SocketPair

Instance Method Details

#connect(local_socket) ⇒ void

This method returns an undefined value.

Keeps the accepted socket silent until reset or stop closes active proxy connections.

Parameters:

  • local_socket (TCPSocket)

    the accepted client socket



19
20
21
22
23
24
25
26
27
28
# File 'lib/nonnative/timeout_socket_pair.rb', line 19

def connect(local_socket)
  @local_socket = local_socket

  Nonnative.logger.info "stalling socket '#{local_socket.inspect}' for 'timeout' pair"

  # Do not call super: the base implementation opens the upstream socket and forwards traffic.
  sleep 0.1 until local_socket.closed?
ensure
  close
end