File tree Expand file tree Collapse file tree 1 file changed +28
-3
lines changed Expand file tree Collapse file tree 1 file changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -80,9 +80,34 @@ def _read_from_socket(nbytes)
80
80
raise Errno ::ECONNRESET
81
81
end
82
82
83
- # UNIXSocket and TCPSocket don't support write timeouts
84
- def write ( *args )
85
- Timeout . timeout ( @write_timeout , TimeoutError ) { super }
83
+ def _write_to_socket ( data )
84
+ begin
85
+ write_nonblock ( data )
86
+
87
+ rescue *NBIO_EXCEPTIONS
88
+ if IO . select ( [ self ] , nil , nil , @write_timeout )
89
+ retry
90
+ else
91
+ raise Redis ::TimeoutError
92
+ end
93
+ end
94
+
95
+ rescue EOFError
96
+ raise Errno ::ECONNRESET
97
+ end
98
+
99
+ def write ( data )
100
+ return super ( data ) unless @write_timeout
101
+
102
+ length = data . bytesize
103
+ total_count = 0
104
+ loop do
105
+ count = _write_to_socket ( data )
106
+
107
+ total_count += count
108
+ return total_count if total_count >= length
109
+ data = data . byteslice ( count ..-1 )
110
+ end
86
111
end
87
112
end
88
113
You can’t perform that action at this time.
0 commit comments