Skip to content

Commit

Permalink
Turns out Ruby 1.8.7 does not have String#byteslice, use String#unpac…
Browse files Browse the repository at this point in the history
…k cleverly.
  • Loading branch information
sodabrew committed Jul 16, 2014
1 parent b9e97da commit 50c5e41
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions code/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,19 @@ def send_recv(msg, data="")

private

# Borrowed from UnixRack
# Borrowed from UnixRack and updated by Backports
def do_write(client, buff)
nwritten = 0

out_buff = buff

while true
nw = client.syswrite(out_buff)
nwritten = nwritten + nw
break if nw == out_buff.bytesize
out_buff = out_buff.byteslice(nw..-1)
lwritten = client.syswrite(buff)
nwritten = lwritten

# Only dup the original buff if we didn't get it all in the first try
while nwritten < buff.bytesize
remaining = buff.bytesize - nwritten
rbuff = (rbuff || buff.dup).unpack("@#{lwritten}a#{remaining}").first
lwritten = client.syswrite(rbuff)
nwritten += lwritten
end

nwritten
end

Expand Down

0 comments on commit 50c5e41

Please sign in to comment.