Skip to content

Commit

Permalink
calculate bytes when write to socket
Browse files Browse the repository at this point in the history
  • Loading branch information
Fivell committed Sep 26, 2017
1 parent 3679470 commit 2127d14
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/net/tcp_client/tcp_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,17 @@ def socket_write(data, timeout)
socket.write(data)
else
deadline = Time.now.utc + timeout
length = data.bytesize
total_count = 0
non_blocking(socket, deadline) do
socket.write_nonblock(data)
begin
count = socket.write_nonblock(data)
rescue Errno::EWOULDBLOCK
retry
end
total_count += count
return total_count if total_count >= length
data = data.byteslice(count..-1)
end
end
rescue NonBlockingTimeout
Expand Down

0 comments on commit 2127d14

Please sign in to comment.