mqtt 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This is a monkey patch to work around a missing method in OpenSSL. Older
4
+ # versions of OpenSSL were missing the `getbyte` method (regular sockets have
5
+ # a getbyte method but OpenSSL sockets didn't). We added `getbyte` to OpenSSL
6
+ # here: https://github.com/ruby/openssl/pull/438
7
+ #
8
+ # This patch is just to backport the `getbyte` method until folks are able to
9
+ # upgrade OpenSSL packages
10
+ unless OpenSSL::SSL::SSLSocket.method_defined?(:getbyte)
11
+ class OpenSSL::SSL::SSLSocket
12
+ def getbyte
13
+ byte = read(1)
14
+ byte && unpack_byte(byte)
15
+ end
16
+
17
+ private
18
+
19
+ if ''.respond_to?(:unpack1)
20
+ def unpack_byte(str)
21
+ str.unpack1('C')
22
+ end
23
+ else
24
+ def unpack_byte(str)
25
+ str.unpack('C').first
26
+ end
27
+ end
28
+ end
29
+ end