em-rtmp 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/em-rtmp/connection.rb +9 -14
- data/lib/em-rtmp/io_helpers.rb +18 -6
- data/lib/em-rtmp/version.rb +1 -1
- metadata +1 -1
data/lib/em-rtmp/connection.rb
CHANGED
@@ -148,21 +148,16 @@ module EventMachine
|
|
148
148
|
loop do
|
149
149
|
break if bytes_waiting < 1
|
150
150
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
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
|
-
|
164
|
-
|
165
|
-
|
157
|
+
break
|
158
|
+
when :handshake_complete, :ready
|
159
|
+
@response_router.buffer_changed
|
160
|
+
next
|
166
161
|
end
|
167
162
|
end
|
168
163
|
|
data/lib/em-rtmp/io_helpers.rb
CHANGED
@@ -6,7 +6,7 @@ module EventMachine
|
|
6
6
|
#
|
7
7
|
# Returns the result of the read
|
8
8
|
def read_uint8
|
9
|
-
|
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
|
-
|
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" +
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
data/lib/em-rtmp/version.rb
CHANGED