Class: TCR::RecordableTCPSocket

Inherits:
Object
  • Object
show all
Includes:
Net::BER::BERParser, Net::LDAP::Connection::GetbyteForSSLSocket
Defined in:
lib/tcr/recordable_tcp_socket.rb,
lib/tcr/net/ldap.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address, port, cassette) ⇒ RecordableTCPSocket

Returns a new instance of RecordableTCPSocket.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/tcr/recordable_tcp_socket.rb', line 9

def initialize(address, port, cassette)
  raise TCR::NoCassetteError unless TCR.cassette

  @read_lock = []
  @recording = cassette.next_session
  @live = cassette.recording?
  @config_block_for_reads = TCR.configuration.block_for_reads

  if live
    begin
      @socket = TCPSocket.real_open(address, port)
    rescue StandardError => e
      recording << ['error', Marshal.dump(e)]
      raise
    end
  else
    @closed = false
    check_recording_for_errors
  end
end

Instance Attribute Details

#liveObject (readonly)

Returns the value of attribute live.



7
8
9
# File 'lib/tcr/recordable_tcp_socket.rb', line 7

def live
  @live
end

#recordingObject (readonly)

Returns the value of attribute recording.



7
8
9
# File 'lib/tcr/recordable_tcp_socket.rb', line 7

def recording
  @recording
end

#socketObject (readonly)

Returns the value of attribute socket.



7
8
9
# File 'lib/tcr/recordable_tcp_socket.rb', line 7

def socket
  @socket
end

Instance Method Details

#cipherObject



65
66
67
# File 'lib/tcr/recordable_tcp_socket.rb', line 65

def cipher
  {}
end

#closeObject



81
82
83
84
85
86
87
# File 'lib/tcr/recordable_tcp_socket.rb', line 81

def close
  if live
    @socket.close
  else
    @closed = true
  end
end

#closed?Boolean

Returns:

  • (Boolean)


73
74
75
76
77
78
79
# File 'lib/tcr/recordable_tcp_socket.rb', line 73

def closed?
  if live
    @socket.closed?
  else
    @closed
  end
end

#getc(*args) ⇒ Object



37
38
39
# File 'lib/tcr/recordable_tcp_socket.rb', line 37

def getc(*args)
  _read(:getc, *args)
end

#gets(*args) ⇒ Object



41
42
43
# File 'lib/tcr/recordable_tcp_socket.rb', line 41

def gets(*args)
  _read(:gets, *args)
end

#hostname=(*args) ⇒ Object

no-op for Ruby 3.1 compatibility



31
# File 'lib/tcr/recordable_tcp_socket.rb', line 31

def hostname=(*args); end


49
50
51
# File 'lib/tcr/recordable_tcp_socket.rb', line 49

def print(str)
  _write(:print, str)
end

#read(bytes) ⇒ Object



33
34
35
# File 'lib/tcr/recordable_tcp_socket.rb', line 33

def read(bytes)
  _read(:read, bytes)
end

#read_nonblock(*args, **_rest) ⇒ Object



45
46
47
# File 'lib/tcr/recordable_tcp_socket.rb', line 45

def read_nonblock(*args, **_rest)
  _read(:read_nonblock, *args, blocking: false)
end

#setsockopt(*args) ⇒ Object



89
# File 'lib/tcr/recordable_tcp_socket.rb', line 89

def setsockopt(*args); end

#ssl_versionObject



63
# File 'lib/tcr/recordable_tcp_socket.rb', line 63

def ssl_version; end

#to_ioObject



69
70
71
# File 'lib/tcr/recordable_tcp_socket.rb', line 69

def to_io
  @socket.to_io if live
end

#write(str) ⇒ Object



53
54
55
56
# File 'lib/tcr/recordable_tcp_socket.rb', line 53

def write(str)
  _write(:write, str)
  str.length
end

#write_nonblock(str, *_rest) ⇒ Object



58
59
60
61
# File 'lib/tcr/recordable_tcp_socket.rb', line 58

def write_nonblock(str, *_rest)
  _write(:write_nonblock, str)
  str.length
end