Class: Net::TNS::Packet
- Inherits:
-
BinData::Record
- Object
- BinData::Record
- Net::TNS::Packet
show all
- Defined in:
- lib/net/tns/packet.rb
Direct Known Subclasses
AbortPacket, AcceptPacket, AckPacket, AttentionPacket, ConnectPacket, ControlPacket, DataPacket, MarkerPacket, NullPacket, RedirectPacket, RefusePacket, ResendPacket
Constant Summary
collapse
- SESSION_DATA_UNIT_SIZE =
8192
- MAX_PAYLOAD_SIZE =
SESSION_DATA_UNIT_SIZE - Header::LENGTH
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.from_socket(socket) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/net/tns/packet.rb', line 36
def self.from_socket( socket )
Net::TNS.logger.debug("Attempting to read header")
require "timeout"
begin
= Timeout::timeout(5) do
socket.read(Header::LENGTH)
end
rescue Timeout::Error
raise Exceptions::ReceiveTimeoutExceeded
end
if .nil? || .length != Header::LENGTH
= .length unless .nil?
raise Exceptions::ProtocolException.new("Failed to read complete header. Read #{.to_i} bytes.")
end
= Header.new()
.read( )
Net::TNS.logger.debug("Read header. Reported packet length is #{.packet_length} bytes")
if .packet_length > SESSION_DATA_UNIT_SIZE
raise Exceptions::ProtocolException.new("Packet length in header (#{.packet_length}) is longer than SDU size.")
end
payload_raw = socket.read( .packet_length - Header::LENGTH )
packet_raw = + payload_raw
unless payload_class = @@tns_packet_classes[ .packet_type ]
raise Net::TNS::Exceptions::TNSException.new( "Unknown TNS packet type: #{.packet_type}" )
end
unless packet_raw.length == .packet_length
raise Net::TNS::Exceptions::ProtocolException.new("Failed to read entire packet (read #{packet_raw.length} of #{.packet_length} bytes).")
end
new_packet = payload_class.read( packet_raw )
return new_packet
end
|
.register_tns_type(tns_type) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/net/tns/packet.rb', line 23
def self.register_tns_type(tns_type)
@@tns_packet_classes ||= {}
@@tns_packet_types ||= {}
if @@tns_packet_classes.has_key?(tns_type)
existing_class = @@tns_packet_classes[tns_type]
raise ArgumentError.new("Duplicate TNS Types Defined: #{existing_class} and #{self} both have a type of #{tns_type}")
end
@@tns_packet_classes[tns_type] = self
@@tns_packet_types[self] = tns_type
return nil
end
|
Instance Method Details
#to_binary_s ⇒ Object
80
81
82
83
|
# File 'lib/net/tns/packet.rb', line 80
def to_binary_s()
()
return super
end
|
75
76
77
78
|
# File 'lib/net/tns/packet.rb', line 75
def ()
self..packet_type = @@tns_packet_types[self.class]
self..packet_length = self.num_bytes
end
|