@@ -7,6 +7,18 @@ class Socket
7
7
8
8
attr_accessor :data
9
9
10
+ # drawn from https://github.com/ruby-amqp/bunny/commit/75d9dd79551b31a5dd3d1254c537bad471f108cf
11
+ READ_RETRY_EXCEPTION_CLASSES = if defined? ( IO ::EAGAINWAITReadable ) # Ruby >= 2.1
12
+ [ Errno ::EAGAIN , Errno ::EWOULDBLOCK , IO ::WaitReadable , IO ::EAGAINWaitReadable , IO ::EWOULDBLOCKWaitReadable ]
13
+ else # Ruby <= 2.0
14
+ [ Errno ::EAGAIN , Errno ::EWOULDBLOCK , IO ::WaitReadable ]
15
+ end
16
+ WRITE_RETRY_EXCEPTION_CLASSES = if defined? ( IO ::EAGAINWaitWritable ) # Ruby >= 2.1
17
+ [ Errno ::EAGAIN , Errno ::EWOULDBLOCK , IO ::WaitWritable , IO ::EAGAINWaitWritable , IO ::EWOULDBLOCKWaitWritable ]
18
+ else # Ruby <= 2.0
19
+ [ Errno ::EAGAIN , Errno ::EWOULDBLOCK , IO ::WaitWritable ]
20
+ end
21
+
10
22
def params
11
23
Excon . display_warning ( 'Excon::Socket#params is deprecated use Excon::Socket#data instead.' )
12
24
@data
@@ -46,7 +58,7 @@ def readline
46
58
begin
47
59
buffer << @socket . read_nonblock ( 1 ) while buffer [ -1 ] != "\n "
48
60
buffer
49
- rescue Errno :: EAGAIN , Errno :: EWOULDBLOCK , IO :: WaitReadable
61
+ rescue * READ_RETRY_EXCEPTION_CLASSES
50
62
select_with_timeout ( @socket , :read ) && retry
51
63
rescue OpenSSL ::SSL ::SSLError => error
52
64
if error . message == 'read would block'
@@ -170,7 +182,7 @@ def read_nonblock(max_length)
170
182
else
171
183
raise ( error )
172
184
end
173
- rescue Errno :: EAGAIN , Errno :: EWOULDBLOCK , IO :: WaitReadable
185
+ rescue * READ_RETRY_EXCEPTION_CLASSES
174
186
if @read_buffer . empty?
175
187
# if we didn't read anything, try again...
176
188
select_with_timeout ( @socket , :read ) && retry
@@ -199,7 +211,7 @@ def read_block(max_length)
199
211
else
200
212
raise ( error )
201
213
end
202
- rescue Errno :: EAGAIN , Errno :: EWOULDBLOCK , IO :: WaitReadable
214
+ rescue * READ_RETRY_EXCEPTION_CLASSES
203
215
if @read_buffer . empty?
204
216
select_with_timeout ( @socket , :read ) && retry
205
217
end
@@ -225,7 +237,7 @@ def write_nonblock(data)
225
237
else
226
238
raise error
227
239
end
228
- rescue OpenSSL ::SSL ::SSLError , Errno :: EAGAIN , Errno :: EWOULDBLOCK , IO :: WaitWritable => error
240
+ rescue OpenSSL ::SSL ::SSLError , * WRITE_RETRY_EXCEPTION_CLASSES => error
229
241
if error . is_a? ( OpenSSL ::SSL ::SSLError ) && error . message != 'write would block'
230
242
raise error
231
243
else
@@ -246,7 +258,7 @@ def write_nonblock(data)
246
258
247
259
def write_block ( data )
248
260
@socket . write ( data )
249
- rescue OpenSSL ::SSL ::SSLError , Errno :: EAGAIN , Errno :: EWOULDBLOCK , IO :: WaitWritable => error
261
+ rescue OpenSSL ::SSL ::SSLError , * WRITE_RETRY_EXCEPTION_CLASSES => error
250
262
if error . is_a? ( OpenSSL ::SSL ::SSLError ) && error . message != 'write would block'
251
263
raise error
252
264
else
0 commit comments