net-telnet-rfc2217 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f0b5b2b5e014b1fc9906ae0be1e7d33fb5d3971cce0b4eda74332e6a1ee24a9e
4
- data.tar.gz: b56a17ffee69e60c4c8f805fd5fb16a0195a95719ed3b93a4fc5417c1dbb0e2f
3
+ metadata.gz: 8c22526ce99613e2c561a64f7b7c9063591eaac34fce16602374afbc7461287c
4
+ data.tar.gz: 18d1b8c6679c93ec46d69ad0a6f6e0942b868f3bb2b82022d6d50f88a01b411d
5
5
  SHA512:
6
- metadata.gz: 1b4b82e214841d59828c733e9c15a65d2e623ee807f42df97353054564cb6bd7991f6900182ecd35cedebf83876c9388ecdce8574639a86b0e4d237e3e8f0a96
7
- data.tar.gz: 35da8ce422ca87cfc75ad2c4461582d9ec54f8335f74bb381fe178d12890bae4f5034e7338488187c07cdfb6a900e2eb89f95909c7cdd536a33581062b0c5861
6
+ metadata.gz: a92d336bd6cc302a1f1b2d3aba4ab57d45115556e954da8937afbdef7a4f7a1056ebdb5911fa6f3685b01e2123734c66166fef9c510c9055e6959f855b117108
7
+ data.tar.gz: cceb6cf145dcbffa1fb0132f7bc7d2f9c73b9b80c2bc993d2865e339e0e5a52aca0330f0b0eeb799c39b1984a41697bc56cdbee0c99b65f70fe82129fb9e3944
@@ -73,7 +73,12 @@ module Net
73
73
  telnet.write(IAC + WILL + COM_PORT_OPTION)
74
74
  sock.flush
75
75
  @buffer = ''
76
- readpartial(0)
76
+ start = Time.now.to_f
77
+ loop do
78
+ raise "could not negotiate serial port in time" if Time.now.to_f - start > 5
79
+ break if @negotiated
80
+ readpartial(0)
81
+ end
77
82
  end
78
83
 
79
84
  def get_modem_params
@@ -121,8 +126,9 @@ module Net
121
126
 
122
127
  def readpartial(length, outbuf = '')
123
128
  loop do
124
- # 0 is special and means 'read at least one control sequence'
125
- break if length != 0 || @buffer.length != 0
129
+ # 0 is special and means "just see if there's data to read"
130
+ break if length != 0 && @buffer.length != 0
131
+ raise "could not negotiate serial port in first 1MB of data" if @buffer.length >= 1024 * 1024
126
132
 
127
133
  data = sock.sysread([length - @buffer.length, 64 * 1024].max)
128
134
 
@@ -131,12 +137,11 @@ module Net
131
137
  data.concat(sock.sysread(16))
132
138
  end
133
139
 
134
- saw_control = false
135
140
  data = @telnet.preprocess(data) do |control|
136
- saw_control = true
137
141
  if DO[0] == control[0] && COM_PORT_OPTION == control[1]
138
142
  # start negotiation
139
143
  write_modem_params
144
+ @negotiated = true
140
145
  true
141
146
  elsif DONT[0] == control[0] && COM_PORT_OPTION == control[1]
142
147
  raise "Serial port control not supported"
@@ -148,7 +153,8 @@ module Net
148
153
  end
149
154
  end
150
155
  @buffer.concat(data)
151
- break if length == 0 && saw_control
156
+
157
+ break if length == 0
152
158
  end
153
159
 
154
160
  length = [length, @buffer.length].min
@@ -1,7 +1,7 @@
1
1
  module Net
2
2
  class Telnet
3
3
  class RFC2217
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-telnet-rfc2217
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer