em-rtmp 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -148,21 +148,16 @@ module EventMachine
148
148
  loop do
149
149
  break if bytes_waiting < 1
150
150
 
151
- begin
152
- case state
153
- when :handshake
154
- if @handshake.buffer_changed == :handshake_complete
155
- @handshake = nil
156
- change_state :handshake_complete
157
- end
158
- break
159
- when :handshake_complete, :ready
160
- @response_router.buffer_changed
161
- next
151
+ case state
152
+ when :handshake
153
+ if @handshake.buffer_changed == :handshake_complete
154
+ @handshake = nil
155
+ change_state :handshake_complete
162
156
  end
163
- rescue NoMethodError, TypeError, RuntimeError => e
164
- Logger.error "failure: #{e}"
165
- retry
157
+ break
158
+ when :handshake_complete, :ready
159
+ @response_router.buffer_changed
160
+ next
166
161
  end
167
162
  end
168
163
 
@@ -6,7 +6,7 @@ module EventMachine
6
6
  #
7
7
  # Returns the result of the read
8
8
  def read_uint8
9
- read(1).unpack('C')[0]
9
+ read_safe(1).unpack('C')[0]
10
10
  end
11
11
 
12
12
  # Write an unsigned 8-bit integer
@@ -22,7 +22,7 @@ module EventMachine
22
22
  #
23
23
  # Returns the result of the read
24
24
  def read_uint16_be
25
- read(2).unpack('n')[0]
25
+ read_safe(2).unpack('n')[0]
26
26
  end
27
27
 
28
28
  # Write an unsigned 16-bit integer
@@ -38,7 +38,7 @@ module EventMachine
38
38
  #
39
39
  # Returns the result of the read
40
40
  def read_uint24_be
41
- ("\x00" + read(3)).unpack('N')[0]
41
+ ("\x00" + read_safe(3)).unpack('N')[0]
42
42
  end
43
43
 
44
44
  # Write an unsigned 24-bit integer
@@ -54,14 +54,14 @@ module EventMachine
54
54
  #
55
55
  # Returns the result of the read
56
56
  def read_uint32_be
57
- read(4).unpack('N')[0]
57
+ read_safe(4).unpack('N')[0]
58
58
  end
59
59
 
60
60
  # Read a unsigned 32-bit integer (little endian)
61
61
  #
62
62
  # Returns the result of the read
63
63
  def read_uint32_le
64
- read(4).unpack('V')[0]
64
+ read_safe(4).unpack('V')[0]
65
65
  end
66
66
 
67
67
  # Write an unsigned 32-bit integer (big endian)
@@ -86,7 +86,7 @@ module EventMachine
86
86
  #
87
87
  # Returns the result of the read
88
88
  def read_double_be
89
- read(8).unpack('G')[0]
89
+ read_safe(8).unpack('G')[0]
90
90
  end
91
91
 
92
92
  # Write a double (big endian)
@@ -172,6 +172,18 @@ module EventMachine
172
172
  }
173
173
  end
174
174
 
175
+ def read_safe(length)
176
+ raise ArgumentError, "cannot read nothing: #{length}" unless length && length >= 1
177
+
178
+ loop do
179
+ if value = read(length)
180
+ return value
181
+ else
182
+ Logger.error "unable to read from socket"
183
+ end
184
+ end
185
+ end
186
+
175
187
  private
176
188
 
177
189
  # Obtain the shift and bitmasks for a set of widths
@@ -1,5 +1,5 @@
1
1
  module EventMachine
2
2
  module RTMP
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-rtmp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: