@@ -27,8 +27,12 @@ module SocketMixin
27
27
CRLF = "\r \n " . freeze
28
28
29
29
# Exceptions raised during non-blocking I/O ops that require retrying the op
30
- NBIO_EXCEPTIONS = [ Errno ::EWOULDBLOCK , Errno ::EAGAIN ]
31
- NBIO_EXCEPTIONS << IO ::WaitReadable if RUBY_VERSION >= "1.9.3"
30
+ NBIO_READ_EXCEPTIONS = [ Errno ::EWOULDBLOCK , Errno ::EAGAIN ]
31
+ NBIO_WRITE_EXCEPTIONS = [ Errno ::EWOULDBLOCK , Errno ::EAGAIN ]
32
+ if RUBY_VERSION >= "1.9.3"
33
+ NBIO_READ_EXCEPTIONS << IO ::WaitReadable
34
+ NBIO_WRITE_EXCEPTIONS << IO ::WaitWritable
35
+ end
32
36
33
37
def initialize ( *args )
34
38
super ( *args )
@@ -78,12 +82,18 @@ def _read_from_socket(nbytes)
78
82
begin
79
83
read_nonblock ( nbytes )
80
84
81
- rescue *NBIO_EXCEPTIONS
85
+ rescue *NBIO_READ_EXCEPTIONS
82
86
if IO . select ( [ self ] , nil , nil , @timeout )
83
87
retry
84
88
else
85
89
raise Redis ::TimeoutError
86
90
end
91
+ rescue *NBIO_WRITE_EXCEPTIONS
92
+ if IO . select ( nil , [ self ] , nil , @timeout )
93
+ retry
94
+ else
95
+ raise Redis ::TimeoutError
96
+ end
87
97
end
88
98
89
99
rescue EOFError
@@ -94,7 +104,13 @@ def _write_to_socket(data)
94
104
begin
95
105
write_nonblock ( data )
96
106
97
- rescue *NBIO_EXCEPTIONS
107
+ rescue *NBIO_READ_EXCEPTIONS
108
+ if IO . select ( [ self ] , nil , nil , @write_timeout )
109
+ retry
110
+ else
111
+ raise Redis ::TimeoutError
112
+ end
113
+ rescue *NBIO_WRITE_EXCEPTIONS
98
114
if IO . select ( nil , [ self ] , nil , @write_timeout )
99
115
retry
100
116
else
0 commit comments